Example #1
0
// POST add employee
func AdminEmployeeAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	if !service.CanUpdate("", r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/employee/new", 303)
		return
	}
	r.ParseForm()
	employee, user := service.NewEmployee(r.Form)
	service.SaveUser(user)
	service.SaveEmployee(employee)
	c.SetFlash("alertSuccess", "Successfully added employee")
	http.Redirect(w, r, "/admin/employee", 303)
	return
}
Example #2
0
// POST edit employee
func AdminEmployeeEdit(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "developer") {
		return
	}
	if !service.CanUpdate(r.FormValue("userId"), r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/employee/"+r.FormValue("id"), 303)
		return
	}
	r.ParseForm()
	employee := service.FindOneEmployee(r.FormValue("id"))
	util.FormToStruct(&employee, r.Form, "")
	user := service.FindOneUser(employee.UserId)
	util.FormToStruct(&user, r.Form, "")
	user.Id = employee.UserId
	service.SaveEmployee(employee)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully saved employee")
	http.Redirect(w, r, "/admin/employee", 303)
	return
}