本文整理汇总了Golang中admin/app/models.Announce.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang Announce.Save方法的具体用法?Golang Announce.Save怎么用?Golang Announce.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类admin/app/models.Announce
的用法示例。
在下文中一共展示了Announce.Save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Add
//添加公告
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() {
//******************************************
//管理员日志
if UserID, ok := c.Session["UserID"]; ok {
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/")
}
}
}