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()) }
func (c UserPostController) Remove(id int64) revel.Result { revel.TRACE.Printf("GET >> user.post.remove ... (%d)", id) c.Begin() var obj models.UserPost obj.ID = id count, err := c.Txn.Delete(&obj) if err != nil { c.Rollback() c.Flash.Error(err.Error()) return c.Redirect(routes.UserPostController.Index()) } c.Commit() if count == 0 { c.Flash.Error("user.post (%d) not exist.", id) } else { c.Flash.Success("user.post (%d) remove succeed.", id) } return c.Redirect(routes.UserPostController.Index()) }