Example #1
0
func (c OptionController) CreatePost(obj models.Option) revel.Result {
	revel.TRACE.Printf("POST >> option.create create ... (%v)", obj)

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

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

	c.Flash.Success("option (%d) create succeed.", obj.ID)
	return c.Redirect(routes.OptionController.Index())
}
Example #2
0
func (c OptionController) Remove(id int64) revel.Result {
	revel.TRACE.Printf("GET >> option.remove ... (%d)", id)

	c.Begin()
	var obj models.Option
	obj.ID = id

	count, err := c.Txn.Delete(&obj)
	if err != nil {
		c.Rollback()
		c.Flash.Error(err.Error())
		return c.Redirect(routes.OptionController.Index())
	}
	c.Commit()

	if count == 0 {
		c.Flash.Error("option (%d) not exist.", id)
	} else {
		c.Flash.Success("option (%d) remove succeed.", id)
	}

	return c.Redirect(routes.OptionController.Index())
}