Ejemplo n.º 1
0
func (c Topic) EditPost(id int64, topic models.Topic, category int64) revel.Result {
	user := c.user()
	if has, _ := engine.Where("id = ? AND user_id = ?", id, user.Id).Get(&models.Topic{}); !has {
		return c.Forbidden("抱歉,您没有权限")
	}

	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.Edit(id))
	}

	topic.Category = models.Category{Id: category}

	aff, _ := engine.Id(id).Cols("title", "category_id", "content").Update(&topic)
	if aff > 0 {
		c.Flash.Success("编辑帖子成功")
		cache.Flush()
	} else {
		c.Flash.Error("编辑帖子失败")
	}

	return c.Redirect(routes.Topic.Show(id))
}
Ejemplo n.º 2
0
func (c Topic) EditPost(id int64, topic models.Topic, category int64) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.Edit(id))
	}

	topic.Category = models.Category{Id: category}

	aff, _ := c.Engine.Id(id).Cols("title", "category_id", "content").Update(&topic)
	if aff > 0 {
		c.Flash.Success("编辑帖子成功")
		cache.Flush()
	} else {
		c.Flash.Error("编辑帖子失败")
	}

	return c.Redirect(routes.Topic.Show(id))
}
Ejemplo n.º 3
0
func (c Topic) NewPost(topic models.Topic, category int64) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.New())
	}

	topic.User = models.User{Id: c.user().Id}
	topic.Category = models.Category{Id: category}

	aff, _ := c.Engine.Insert(&topic)
	if aff > 0 {
		c.Flash.Success("发表新帖成功")
		cache.Flush()
	} else {
		c.Flash.Error("发表新帖失败")
	}

	return c.Redirect(routes.Topic.Index(1))
}