Example #1
0
//删除文章
func (c *ArticleController) DoDel() {
	CheckAdminLogin(&c.Controller, 1)
	id, _ := strconv.ParseInt(c.GetString("id"), 10, 64)
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	if id <= 0 {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)
	}
	entity := models.GetArticle(id)
	if entity == nil {
		tip.Message = "系统找不到本记录!"
		EchoTip(&c.Controller, tip)
	} else {
		if err := models.DelArticle(entity); err != nil {
			tip.Message = "删除出错:" + err.Error()
			EchoTip(&c.Controller, tip)
		} else {
			tip.Status = models.TipSuccess
			tip.Message = "删除成功!"
			tip.ReturnUrl = "/admin/article"
			EchoTip(&c.Controller, tip)
		}
	}
}
Example #2
0
//编辑文章页面
func (c *ArticleController) Edit() {
	CheckAdminLogin(&c.Controller, 0)

	myid := c.Ctx.Input.Param(":id")
	id, err := strconv.ParseInt(myid, 10, 64)
	if err != nil {
		EchoErrorPage(&c.Controller, "错误参数传递!", "/admin/category")
	}
	entity := models.GetArticle(id)
	if entity == nil {
		EchoErrorPage(&c.Controller, "系统找不到本记录!", "/admin/category")
	}
	//获取所有栏目
	Categories := models.GetCategoryTree(0, -1, true, 0)
	c.Data["Title"] = "修改文章"
	c.Data["Action"] = "edit"
	c.Data["Entity"] = entity
	c.Data["Categories"] = Categories
	c.TplNames = "admin/article_add.tpl"
}
Example #3
0
//执行修改文章
func (c *ArticleController) DoEdit() {
	CheckAdminLogin(&c.Controller, 1)
	tip := &models.TipJSON{}
	tip.Status = models.TipError

	id, err := c.GetInt64("Id")
	if err != nil {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)
	}
	entity := models.GetArticle(id)
	if entity == nil {
		tip.Message = "系统找不到本记录!"
		EchoTip(&c.Controller, tip)
	}

	entity.Title = c.GetString("Title")
	if entity.Title == "" {
		tip.Message = "标题不能为空!"
		EchoTip(&c.Controller, tip)
	}
	kid, _ := strconv.ParseInt(c.GetString("Kid"), 10, 64)
	if kid == 0 {
		tip.Message = "请选择一个栏目!"
		EchoTip(&c.Controller, tip)
	}
	entity.Origin = c.GetString("Origin")
	entity.OriginUrl = c.GetString("OriginUrl")
	if c.GetString("IsNew") == "1" {
		entity.IsNew = 1
	} else {
		entity.IsNew = 0
	}
	if c.GetString("IsRecommend") == "1" {
		entity.IsRecommend = 1
	} else {
		entity.IsRecommend = 0
	}
	if c.GetString("IsHide") == "1" {
		entity.IsHide = 1
	} else {
		entity.IsHide = 0
	}
	views, _ := strconv.ParseInt(c.GetString("Views"), 10, 64)
	addtime, _ := time.Parse("2006-01-02 15:04:05", c.GetString("Created"))
	entity.Created = addtime
	entity.Views = views
	entity.Rank, _ = strconv.ParseInt(c.GetString("Rank"), 10, 64)
	entity.LinkUrl = c.GetString("LinkUrl")
	entity.Keyword = c.GetString("Keyword")
	entity.Description = c.GetString("Description")
	entity.Pic = c.GetString("Pic")
	entity.Content = c.GetString("Content")

	if id, err := models.EditArticle(entity); id > 0 && err == nil {
		//修改成功
		tip.Status = models.TipSuccess
		tip.Id = id
		tip.ReturnUrl = "/admin/article"
		tip.Message = "文章修改成功"
	} else {
		tip.Id = id
		tip.Message = "文章修改失败:" + err.Error()
	}
	EchoTip(&c.Controller, tip)

}