func UpdateAlertNotification(c *middleware.Context, cmd models.UpdateAlertNotificationCommand) Response { cmd.OrgId = c.OrgId if err := bus.Dispatch(&cmd); err != nil { return ApiError(500, "Failed to update alert notification", err) } return Json(200, cmd.Result) }
func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error { return inTransaction(func(sess *xorm.Session) (err error) { current := m.AlertNotification{} if _, err = sess.Id(cmd.Id).Get(¤t); err != nil { return err } // check if name exists sameNameQuery := &m.GetAlertNotificationsQuery{OrgId: cmd.OrgId, Name: cmd.Name} if err := getAlertNotificationInternal(sameNameQuery, sess); err != nil { return err } if sameNameQuery.Result != nil && sameNameQuery.Result.Id != current.Id { return fmt.Errorf("Alert notification name %s already exists", cmd.Name) } current.Updated = time.Now() current.Settings = cmd.Settings current.Name = cmd.Name current.Type = cmd.Type current.IsDefault = cmd.IsDefault sess.UseBool("is_default") if affected, err := sess.Id(cmd.Id).Update(current); err != nil { return err } else if affected == 0 { return fmt.Errorf("Could not find alert notification") } cmd.Result = ¤t return nil }) }