Example #1
0
func (c *Topic) EditPost(id int64, topic models.Topic) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.Edit(id))
	}

	topic_ := models.FindTopicById(id)

	if topic_.Id == 0 {
		return c.NotFound("帖子不存在")
	}

	topic_.Title = topic.Title
	topic_.CategoryId = topic.CategoryId
	topic_.Content = topic.Content

	if topic_.Save() {
		c.Flash.Success("编辑帖子成功")
	} else {
		c.Flash.Error("编辑帖子失败")
	}

	return c.Redirect(routes.Topic.Edit(id))
}
Example #2
0
func (c *Topic) NewPost(topic models.Topic) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.New())
	}

	topic.UserId = c.RenderArgs["user"].(*models.User).Id
	if topic.Save() {
		c.Flash.Success("发表新帖成功")
	} else {
		c.Flash.Error("发表新帖失败")
	}

	return c.Redirect(routes.Topic.New())
}