Exemple #1
0
// POST admin edit company
func AdminCompanyEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	r.ParseForm()
	company := service.FindOneCompany(r.FormValue("id"))
	util.FormToStruct(&company, r.Form, "")
	if !service.CanUpdateCompany(company.Id, company.Name) {
		c.SetFlash("alertError", "Error company name already in use")
		http.Redirect(w, r, "/admin/company/"+r.FormValue("id"), 303)
		return
	}
	service.SaveCompany(company)
	c.SetFlash("alertSuccess", "Successfully saved company")
	http.Redirect(w, r, "/admin/company/"+r.FormValue("id"), 303)
	return
}
Exemple #2
0
// POST admin add company
func AdminCompanyAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	r.ParseForm()
	var company service.Company
	util.FormToStruct(&company, r.Form, "")
	if !service.CanUpdateCompany("", company.Name) {
		c.SetFlash("alertError", "Error company name already in use")
		http.Redirect(w, r, "/admin/company", 303)
		return
	}
	company.Id = util.UUID4()
	service.SaveCompany(company)
	c.SetFlash("alertSuccess", "Successfully saved company")
	http.Redirect(w, r, "/admin/company", 303)
	return
}