public DoctorViewModel(Doctor doctor) { IBL bl = new BLImplement(); DoctorId = doctor.DoctorId; Id = doctor.Id; Name = doctor.Name; SpecialName = bl.getAllSpecialties().Where(s => s.Id == doctor.Special).FirstOrDefault().SpecialtyName; LicenseExpirationDate = doctor.LicenseExpirationDate; specials = bl.getAllSpecialties().Select(x => x.SpecialtyName).ToList(); }
public ActionResult Edit([Bind(Include = "Id,DoctorId,Name,Special,LicenseExpirationDate")] DoctorViewModel dvm) { if (ModelState.IsValid) { try { IBL bl = new BLImplement(); var doctor = new Doctor() { DoctorId = dvm.DoctorId, Name = dvm.Name, LicenseExpirationDate = Convert.ToDateTime(dvm.LicenseExpirationDate), Special = bl.getAllSpecialties().Where(s => s.SpecialtyName == dvm.SpecialName).FirstOrDefault().Id }; bl.updateDoctor(doctor); ViewBag.Message = String.Format("The doctor {0} is successfully updated", doctor.Name); } catch (Exception ex) { ViewBag.Message = String.Format(ex.Message); return(RedirectToAction("Index")); } //db.Entry(doctorViewModel).State = EntityState.Modified; return(RedirectToAction("Index")); } return(View(dvm)); }
public DoctorViewModel() { IBL bl = new BLImplement(); Name = null; LicenseExpirationDate = DateTime.MinValue; specials = bl.getAllSpecialties().Select(x => x.SpecialtyName).ToList(); }
public ActionResult Create([Bind(Include = "DoctorId,Name,Special,LicenseExpirationDate")] DoctorViewModel dvm) { if (ModelState.IsValid) { IBL bl = new BLImplement(); try { if (!bl.getAllSpecialties().ToList().Exists(a => a.SpecialtyName == dvm.SpecialName)) { bl.addSpecialty(new Specialty { SpecialtyName = dvm.SpecialName }); } } catch (Exception ex) { ViewBag.Message = String.Format(ex.Message); return(RedirectToAction("Create")); } if (!bl.getAllSpecialties().ToList().Exists(a => a.SpecialtyName == dvm.SpecialName)) { bl.addSpecialty(new Specialty { SpecialtyName = dvm.SpecialName }); } Doctor doctor = new Doctor() { Name = dvm.Name, LicenseExpirationDate = Convert.ToDateTime(dvm.LicenseExpirationDate), Special = bl.getAllSpecialties().Where(s => s.SpecialtyName == dvm.SpecialName).FirstOrDefault().Id }; try { bl.addDoctor(doctor); ViewBag.Message = String.Format("The doctor {0} is successfully added", doctor.Name); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = String.Format(ex.Message); return(RedirectToAction("Index")); } } return(View(dvm)); }