public ActionResult DoctorForm(string UserId) { var doctor = new DoctorFormViewModels(); if (UserId != null) { var model = _context.DoctorsRepository.GetBy(x => x.UserId == UserId); doctor = Mapper.Map <Doctors, DoctorFormViewModels>(model); var img = _context.ImagesRepository.GetBy(x => x.DoctorId == model.Id); doctor.ImagePath = img.FilePath + @"\" + img.FileName; doctor.SelectedSpecialization = model.SpecializationId; } doctor.Specialization = _context.SpecializationRepository.GetAll(); return(View("DoctorForm", doctor)); }
public ActionResult DoctorForm(DoctorFormViewModels model) { ModelState.Remove("ErrorKey"); if (ModelState.IsValid) { if (model.Id == null) { var entity = Mapper.Map <DoctorFormViewModels, Doctors>(model); entity.SpecializationId = model.SelectedSpecialization; entity.UserId = User.Identity.GetUserId(); _doctorBll.SaveOrUpdate(entity); _doctorBll.InitializeDoctorSchedule(entity.Id); var img = _doctorBll.SaveImage(model.Image, entity); return(RedirectToAction("Profile", "DoctorProfile", new { UserId = entity.UserId })); } else { var entity = _context.DoctorsRepository.Get(model.Id); entity = Mapper.Map <DoctorFormViewModels, Doctors>(model); entity.SpecializationId = model.SelectedSpecialization; _doctorBll.SaveOrUpdate(entity); var img = _context.ImagesRepository.GetAllBy(x => x.DoctorId == model.Id); if (model.Image != null) { _context.ImagesRepository.RemoveRange(img); _doctorBll.SaveImage(model.Image, entity); } return(RedirectToAction("Profile", "DoctorProfile", new { UserId = entity.UserId })); } } var image = _context.ImagesRepository.GetBy(x => x.DoctorId == model.Id); model.ImagePath = image.FilePath + @"\" + image.FileName; model.Specialization = _context.SpecializationRepository.GetAll(); return(View(model)); }