Ejemplo n.º 1
0
func (c UserPostController) CreatePost(obj models.UserPost) revel.Result {
	revel.TRACE.Printf("POST >> user.post.create create ... (%v)", obj)

	obj.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(UserPostController.Create)
	}

	c.Begin()
	if err := c.Txn.Insert(&obj); err != nil {
		c.Rollback()
		c.Flash.Error(err.Error())
		return c.Redirect(routes.UserPostController.Index())
	}
	c.Commit()

	c.Flash.Success("user.post (%d) create succeed.", obj.ID)
	return c.Redirect(routes.UserPostController.Index())
}