Esempio n. 1
0
func (a *AccountService) Update(account *models.Account) error {
	revel.INFO.Println("updating account", account.ToString())
	count, err := persistence.Dbm.Update(account)
	checkErr(err, "account not updated "+account.ToString())
	if count == 1 {
		return nil
	}
	return err
}
Esempio n. 2
0
func (a *AccountService) Save(account *models.Account) *models.Account {
	revel.INFO.Println("saving account", account.ToString())
	tx, err := persistence.Dbm.Begin()
	checkErr(err, "unable to start transaction")
	tx.Insert(account)
	defaultGroup := &models.AccountGroup{Name: "Default", AccountId: account.Id, Default: true}
	tx.Insert(defaultGroup)
	tx.Commit()
	return account
}
Esempio n. 3
0
func (a *AccountController) Add() revel.Result {
	var account models.Account
	err := json.NewDecoder(a.Request.Body).Decode(&account)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	account.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	return a.RenderJson(a.AccountService.Save(&account))
}
Esempio n. 4
0
func (a *AccountController) Update(id int64) revel.Result {
	var account models.Account
	err := json.NewDecoder(a.Request.Body).Decode(&account)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	revel.INFO.Println(&account)
	if account.Id != id {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(&models.Error{Error: "Entity ID and URL ID don't match"})
	}
	account.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	err = a.AccountService.Update(&account)
	if err != nil {
		a.Response.Status = http.StatusConflict
		return a.RenderJson(err)
	}
	return a.RenderJson(&account)
}