Exemple #1
0
        public Doctor ToDoctor(DoctorEditModel viewModel)
        {
            Doctor doctor;

            if (viewModel.Id == null)
            {
                doctor = new Doctor();
            }
            else
            {
                doctor = db.Doctors.Get((int)viewModel.Id);
                doctor.Specializations.Clear();
                doctor.Patients.Clear();
            }
            doctor.Name = viewModel.Name;
            if (viewModel.SpecIds != null)
            {
                doctor.Specializations.AddRange(SpecializationsForDoctor(viewModel));
            }
            if (viewModel.PatientIds != null)
            {
                doctor.Patients.AddRange(PatientsForDoctor(viewModel));
            }
            doctor.AccountId = viewModel.AccountId;
            return(doctor);
        }
        private DoctorModel MapPatientModel(DoctorEditModel editModel)
        {
            var config      = new MapperConfiguration(cfg => cfg.CreateMap <DoctorEditModel, DoctorModel>());
            var mapper      = new Mapper(config);
            var doctorModel = mapper.Map <DoctorModel>(editModel);

            if (editModel.PhotoFile != null)
            {
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(editModel.PhotoFile.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)editModel.PhotoFile.Length);
                }
                doctorModel.Photo = $"data:image/jpeg;base64, {Convert.ToBase64String(imageData)}";
            }
            return(doctorModel);
        }
Exemple #3
0
        public DoctorEditModel FromDoctor(Doctor doctor)
        {
            DoctorEditModel viewModel = new DoctorEditModel();

            if (doctor.Id != null)
            {
                viewModel.Id = doctor.Id;
            }
            viewModel.Name = doctor.Name;

            viewModel.Specializations = SpecToMultiselect(doctor
                                                          .Specializations.Select(s => s.Id));

            viewModel.Patients = PatientsToMultiselect(doctor.Patients.Select(p => p.Id));

            viewModel.AccountId = doctor.AccountId;
            return(viewModel);
        }
Exemple #4
0
 public ActionResult Edit([Bind(Include = "Id,AccountId,Email,Name,SpecIds,PatientIds")]
                          DoctorEditModel viewModel)
 {
     if (ModelState.IsValid)
     {
         Doctor doctor = updater.ToDoctor(viewModel);
         db.Doctors.Update(doctor);
         var user = UserManager.FindById(viewModel.AccountId);
         user.Email    = viewModel.Email;
         user.UserName = viewModel.Email;
         if (UserManager.Update(user).Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         return(new HttpStatusCodeResult(500));
     }
     return(View(viewModel));
 }
        public IActionResult Edit(DoctorEditModel editModel)
        {
            if (ModelState.IsValid)
            {
                var doctorModel = MapPatientModel(editModel);
                doctorService.UpdateDoctor(doctorModel);
                if (User.Identity.Name == "Admin")
                {
                    return(Redirect($"/doctor/{doctorModel.Id}"));
                }
                return(RedirectToAction("Home"));
            }
            editModel.Specializations = doctorService.GetSpecializations()
                                        .Select(x => new SelectListItem()
            {
                Text     = x.Key,
                Value    = x.Value.ToString(),
                Selected = x.Value.ToString() == editModel.SpecializationId.ToString()
            });

            return(View(editModel));
        }
        public IActionResult Edit(Guid id)
        {
            var doctor          = doctorService.GetDoctor(id);
            var doctorEditModel = new DoctorEditModel()
            {
                Id               = doctor.Id,
                FullName         = doctor.FullName,
                HireDate         = doctor.HireDate,
                Email            = doctor.Email,
                Education        = doctor.Education,
                Photo            = doctor.Photo,
                SpecializationId = doctor.SpecializationId,
                Specializations  = doctorService.GetSpecializations()
                                   .Select(x => new SelectListItem()
                {
                    Text     = x.Key,
                    Value    = x.Value.ToString(),
                    Selected = x.Value.ToString() == doctor.SpecializationId.ToString()
                }),
                PlaceDefault = doctor.PlaceDefault
            };

            return(View(doctorEditModel));
        }
Exemple #7
0
 private IEnumerable <Patient> PatientsForDoctor(DoctorEditModel viewModel)
 {
     return(db.Patients.GetAll().Where(p =>
                                       viewModel.PatientIds.Contains((int)p.Id)));
 }
Exemple #8
0
 private IEnumerable <Specialization> SpecializationsForDoctor(DoctorEditModel viewModel)
 {
     return(db.Specializations.GetAll().Where(s =>
                                              viewModel.SpecIds.Contains((int)s.Id)));
 }