func (this *NewsController) Insert(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin News Insert") if r.Method != "POST" { this.Err400(w, r, "Error", "Error Method to Insert news") return } this.Init(w, r) if this.Privilege != config.PrivilegeAD { this.Err400(w, r, "Warning", "Error Privilege to Insert news") return } one := model.News{} one.Title = r.FormValue("title") one.Content = template.HTML(r.FormValue("content")) newsModel := model.NewsModel{} err := newsModel.Insert(one) if err != nil { http.Error(w, err.Error(), 500) return } http.Redirect(w, r, "/admin/news?list", http.StatusFound) }
//@URL: /admin/news/(\d+)/ @method: POST func (nc *AdminNews) Update(Nid string) { restweb.Logger.Debug("Admin News Update") if nc.Privilege != config.PrivilegeAD { nc.Err400("Warning", "Error Privilege to Update news") return } nid, err := strconv.Atoi(Nid) if err != nil { nc.Error("args error", 400) return } one := model.News{} newsModel := model.NewsModel{} one.Title = nc.Input.Get("title") one.Content = template.HTML(nc.Input.Get("content")) err = newsModel.Update(nid, one) if err != nil { nc.Error(err.Error(), 500) return } else { nc.Redirect("/admin/news", http.StatusFound) } }
func (this *NewsController) Update(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin News Update") if r.Method != "POST" { this.Err400(w, r, "Error", "Error Method to Update news") return } this.Init(w, r) if this.Privilege != config.PrivilegeAD { this.Err400(w, r, "Warning", "Error Privilege to Update news") return } args := this.ParseURL(r.URL.String()) nid, err := strconv.Atoi(args["nid"]) if err != nil { http.Error(w, "args error", 400) return } one := model.News{} newsModel := model.NewsModel{} one.Title = r.FormValue("title") one.Content = template.HTML(r.FormValue("content")) err = newsModel.Update(nid, one) if err != nil { http.Error(w, err.Error(), 500) return } else { http.Redirect(w, r, "/admin/news?detail/nid?"+strconv.Itoa(nid), http.StatusFound) } }
//@URL: /admin/news/ @method:POST func (nc *AdminNews) Insert() { restweb.Logger.Debug("Admin News Insert") if nc.Privilege != config.PrivilegeAD { nc.Err400("Warning", "Error Privilege to Insert news") return } one := model.News{} one.Title = nc.R.FormValue("title") one.Content = template.HTML(nc.Input.Get("content")) newsModel := model.NewsModel{} err := newsModel.Insert(one) if err != nil { nc.Error(err.Error(), 500) return } nc.Redirect("/admin/news", http.StatusFound) }