func (a *AccountGroupService) Update(accountGroup *models.AccountGroup) error {
	revel.INFO.Println("updating account group", accountGroup.ToString())
	count, err := persistence.Dbm.Update(accountGroup)
	checkErr(err, "account not updated "+accountGroup.ToString())
	if count == 1 {
		return nil
	}
	return err
}
func (a *AccountGroupService) Save(accountGroup *models.AccountGroup) *models.AccountGroup {
	revel.INFO.Println("saving account group", accountGroup.ToString())
	// there can only be one default group per account
	_, err := a.FindDefault(accountGroup.AccountId)
	if err != nil {
		accountGroup.Default = false
	} else {
		accountGroup.Default = true
	}
	persistence.Dbm.Insert(accountGroup)
	return accountGroup
}
func (a *AccountGroupController) Add(accountId int64) revel.Result {
	var accountGroup models.AccountGroup
	err := json.NewDecoder(a.Request.Body).Decode(&accountGroup)
	if err != nil {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(err)
	}
	if accountGroup.AccountId != accountId {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(&models.Error{Error: "Entity ID and URL ID don't match"})
	}
	accountGroup.Validate(a.Validation)
	if a.Validation.HasErrors() {
		a.Response.Status = http.StatusNotAcceptable
		return a.RenderJson(a.Validation.Errors)
	}
	return a.RenderJson(a.AccountGroupService.Save(&accountGroup))
}