Exemple #1
0
//添加公告
func (c Announce) Add(announce *models.Announce) revel.Result {

	if c.Request.Method == "GET" {
		title := "添加公告--GoCMS管理系统"

		c.Render(title)
		return c.RenderTemplate("Module/Announce/Add.html")
	} else {
		var title string = c.Params.Get("title")
		if len(title) > 0 {
			announce.Title = title
		} else {
			c.Flash.Error("请输入公告标题!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var starttime string = c.Params.Get("starttime")
		if len(starttime) > 0 {
			announce.Starttime = starttime
		} else {
			c.Flash.Error("请输入起始日期!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var endtime string = c.Params.Get("endtime")
		if len(endtime) > 0 {
			announce.Endtime = endtime
		} else {
			c.Flash.Error("请输入截止日期!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			announce.Content = content
		} else {
			c.Flash.Error("请输入公告内容!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			announce.Status = Status
		} else {
			c.Flash.Error("请选择是否启用!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}

		if announce.Save() {

			//******************************************
			//管理员日志
			UserID := utils.GetSession("UserID", c.Session)

			if len(UserID) > 0 {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin := new(models.Admin)
				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "添加公告:" + title
				logs.Save(admin_info, c.Controller, desc)
			}
			//*****************************************

			c.Flash.Success("添加公告成功!")
			c.Flash.Out["url"] = "/Announce/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加公告失败!")
			c.Flash.Out["url"] = "/Announce/Add/"
			return c.Redirect("/Message/")
		}
	}
}