Exemple #1
0
func (c AppControllerWithValidation) PostUpdateApp(appId int, app models.App) revel.Result {
	if appId != app.Id {
		c.Flash.Error("Parameter is invalid.")
		c.Redirect(routes.AppControllerWithValidation.GetUpdateApp(app.Id))
	}

	c.Validation.Required(app.Title).Message("Title is required.")
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.AppControllerWithValidation.GetUpdateApp(app.Id))
	}

	err := Transact(func(txn gorp.SqlExecutor) error {
		return app.Update(txn)
	})
	if err != nil {
		panic(err)
	}

	if err := c.GoogleService.UpdateFileTitle(c.App.FileId, app.Title); err != nil {
		panic(err)
	}

	c.Flash.Success("Updated!")
	return c.Redirect(routes.AppControllerWithValidation.GetApp(app.Id))
}