Exemplo n.º 1
0
func (c Admin) NewCategoryPost(category models.Category) revel.Result {
	category.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Admin.NewCategory())
	}

	aff, _ := engine.Insert(&category)
	if aff > 0 {
		c.Flash.Success("添加分类成功")
		cache.Delete("categories")
	} else {
		c.Flash.Error("添加分类失败")
		return c.Redirect(routes.Admin.NewCategory())
	}

	return c.Redirect(routes.Admin.ListCategory())
}
Exemplo n.º 2
0
func (c Admin) EditCategoryPost(id int64, category models.Category) revel.Result {
	category.Id = id
	category.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Admin.EditCategory(id))
	}

	aff, _ := engine.Id(id).Update(&category)
	if aff > 0 {
		c.Flash.Success("编辑分类成功")
		cache.Flush()
	} else {
		c.Flash.Error("编辑分类失败")
		return c.Redirect(routes.Admin.EditCategory(id))
	}

	return c.Redirect(routes.Admin.ListCategory())
}