示例#1
0
func Save(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	ctx := appengine.NewContext(req)

	t := testimonials.Testimonial{
		Job: testimonials.Job{
			Title:       req.FormValue("title"),
			Description: req.FormValue("desc"),
		},
		Mention: testimonials.Mention{
			Name: req.FormValue("name"),
			Copy: req.FormValue("copy"),
		},
	}

	intID, err := strconv.Atoi(params["id"])
	if err == nil {
		t.ID = int64(intID)
	}

	err = t.Save(ctx)
	if err != nil {
		http.Redirect(rw, req, "/admin/testimonials/"+params["id"]+"?error="+err.Error(), http.StatusFound)
		return
	}

	http.Redirect(rw, req, "/admin/testimonials/"+strconv.Itoa(int(t.ID))+"?success=Testimonial saved", http.StatusFound)
	return
}