public ActionResult Edit(int? id) { var user = DisplayCurUser(); if (!user.UserCanEdit()) return RedirectToAction("AccessDenied", "Error"); if (id.HasValue) { var dep = new Department(id.Value); return View(dep); } else { return View("New"); } }
public ActionResult Edit(Department dep) { var user = DisplayCurUser(); if (!user.UserCanEdit()) return RedirectToAction("AccessDenied", "Error"); try { ResponseMessage responseMessage; bool complete = dep.Save(out responseMessage); if (!complete) throw new Exception(responseMessage.ErrorMessage); return RedirectToAction("Edit", "Department", new { id = responseMessage.Id }); } catch (Exception ex) { ViewData["ServerError"] = ex.Message; return RedirectToAction("Edit", "Department", new { id = dep.Id }); } }
public JsonResult GetDepartmentChief(int idDepartment) { string result = "--отсутствует--"; var dep = new Department(idDepartment); if (dep.Chief != null && dep.Chief.Id > 0) { result = dep.Chief.DisplayName; } return Json(new { name = result }); }
public ActionResult New(Department dep) { var user = DisplayCurUser(); if (!user.UserCanEdit()) return RedirectToAction("AccessDenied", "Error"); //Save department try { ResponseMessage responseMessage; //dep.Creator = new Employee(){AdSid = GetCurUser().Sid}; bool complete = dep.Save(out responseMessage); if (!complete) throw new Exception(responseMessage.ErrorMessage); return RedirectToAction("Edit", "Department", new { id = responseMessage.Id }); } catch (Exception ex) { ViewData["ServerError"] = ex.Message; return View("New", dep); } }
private void FillSelf(Department dep) { Id = dep.Id; Name = dep.Name; ParentDepartment = dep.ParentDepartment; Chief = dep.Chief; EmployeeCount = dep.EmployeeCount; Creator = dep.Creator; }