Пример #1
0
func (c *appContext) cpPostUpdateHandler(w http.ResponseWriter, r *http.Request) {

	if r.Method != "POST" {
		http.NotFound(w, r)
		return
	}

	var p models.Post

	p.PostId, _ = strconv.Atoi(r.FormValue("ID"))
	p.Title = r.FormValue("title")
	p.Name = r.FormValue("name")
	p.Content = r.FormValue("content")
	p.Status, _ = strconv.Atoi(r.FormValue("status"))

	fmt.Println(p)

	err := models.UpdatePost(c.db, p)
	if err != nil {
		fmt.Println(err)
	}

	http.Redirect(w, r, fmt.Sprintf("http://www.mtstats.com/cp/post/%s/", r.FormValue("ID")), 301)

}
Пример #2
0
func (c *appContext) cpPostAddHandler(w http.ResponseWriter, r *http.Request) {

	if r.Method != "POST" {
		http.NotFound(w, r)
		return
	}

	var p models.Post

	p.Title = r.FormValue("title")
	p.Name = r.FormValue("name")
	p.Content = r.FormValue("content")
	p.Status, _ = strconv.Atoi(r.FormValue("status"))
	p.Author.AuthorId, _ = strconv.Atoi(r.FormValue("author_ID"))
	p.CommentStatus = 1
	p.CommentCount = 0

	id, err := models.AddPost(c.db, p)
	if err != nil {
		fmt.Println(err)
	}

	http.Redirect(w, r, fmt.Sprintf("http://www.mtstats.com/cp/post/%s/", strconv.FormatInt(id, 10)), 301)

}