/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>ActionResult.</returns> public ActionResult Edit(int id) { if (Session["CurrentEmployee"] == null) { return RedirectToAction("Index", "Employee"); } var employee = (Employee)Session["CurrentEmployee"]; var model = new MedicSpecialtyViewModel(); model.CurrentEmployee= employee; model.Specialties = new SpecialtyAppService().GetAllSpecialty(); if (id != -1) { var svc = new MedicSpecialtyAppService(); var o = svc.GetMedicSpecialty(id); model.MedicSpecialtyId = o.MedicSpecialtyId; model.SpecialtyId = o.SpecialtyId; model.EmployeeId = o.EmployeeId; } else { model.Action = "-1"; model.MedicSpecialtyId = -1; model.SpecialtyId = -1; model.EmployeeId =employee.EmployeeId; model.IsActive = true; } return View(model); }
public ActionResult Edit(MedicSpecialtyViewModel model) { if (Session["CurrentEmployee"] == null) { return RedirectToAction("Index", "Employee"); } var employee = (Employee)Session["CurrentEmployee"]; model.CurrentEmployee = employee; model.Specialties = new SpecialtyAppService().GetAllSpecialty(); try { var svc = new MedicSpecialtyAppService(); var o = new MedicSpecialty { MedicSpecialtyId= model.MedicSpecialtyId, EmployeeId = employee.EmployeeId, SpecialtyId = model.SpecialtyId, }; if (model.Action == "-1") { var exist = svc.GetMedicSpecialty(model.MedicSpecialtyId)!=null; if (!exist) { svc.AddMedicSpecialty(o); ViewBag.Feed = 0; } else { model.Action = "-1"; ViewBag.Feed = 3; return View(model); } } else { o.MedicSpecialtyId= model.MedicSpecialtyId; if (model.IsDeleteAction == 0) { svc.SaveMedicSpecialty(o); } else { svc.RemoveMedicSpecialty(model.MedicSpecialtyId); } ViewBag.Feed = 0; } } catch (Exception) { ViewBag.Feed = 1; } return View(model); }