Exemplo n.º 1
0
func UpdateContactType(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var ct contact.ContactType

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

	//json?

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

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

	if req.FormValue("show") != "" {
		if show, err := strconv.ParseBool(req.FormValue("show")); err == nil {
			ct.ShowOnWebsite = show
		}
	}
	if req.FormValue("brandId") != "" {
		if brandId, err := strconv.Atoi(req.FormValue("brandId")); err == nil {
			ct.BrandID = brandId
		}
	}

	if err = ct.Update(); err != nil {
		apierror.GenerateError("Trouble updating contact type", err, rw, req)
	}

	return encoding.Must(enc.Encode(ct))
}
Exemplo n.º 2
0
func GetContactType(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder) string {
	var err error
	var ctype contact.ContactType

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