Ejemplo n.º 1
0
func UpdateSalesRep(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var rep salesrep.SalesRep

	if rep.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting sales rep ID", err, rw, req)
	}

	if err = rep.Get(); err != nil {
		apierror.GenerateError("Trouble getting sales rep", err, rw, req)
	}

	if req.FormValue("name") != "" {
		rep.Name = req.FormValue("name")
	}

	if req.FormValue("code") != "" {
		rep.Code = req.FormValue("code")
	}

	if err := rep.Update(); err != nil {
		apierror.GenerateError("Trouble updating sales rep", err, rw, req)
	}

	return encoding.Must(enc.Encode(rep))
}
Ejemplo n.º 2
0
func GetSalesRep(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var rep salesrep.SalesRep

	if rep.ID, err = strconv.Atoi(params["id"]); err != nil {
		apierror.GenerateError("Trouble getting sales rep ID", err, rw, req)
	}
	if err := rep.Get(); err != nil {
		apierror.GenerateError("Trouble getting sales rep", err, rw, req)
	}
	return encoding.Must(enc.Encode(rep))
}