Beispiel #1
0
        public async Task <ActionResult> Create(DoctorViewModel doctorViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindByEmail(doctorViewModel.Email);
                if (user == null)
                {
                    Doctor doctor = DoctorViewModel.ToDoctor(doctorViewModel);

                    user = await AddUser(doctorViewModel);

                    ImageWorker imagePathGetter = new ImageWorker();
                    doctor.ImageUrl = imagePathGetter.GetImageStringPath(doctorViewModel.DoctorImage);

                    if (doctorViewModel.DoctorImage != null)
                    {
                        doctorViewModel.DoctorImage.SaveAs(Path.Combine(
                                                               Server.MapPath("~/AppFile/DoctorPictures"), doctor.ImageUrl));
                    }

                    db.Doctors.Add(doctor);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(doctorViewModel));
        }
Beispiel #2
0
        public async Task <ActionResult> Create(PatientViewModel patientViewModel)
        {
            if (ModelState.IsValid)
            {
                var checkingUser = UserManager.FindByEmail(patientViewModel.Email);

                if (checkingUser == null)
                {
                    Patient patient = PatientViewModel.ToPatient(patientViewModel);
                    patient.Doctors.AddRange(db.Doctors.ToList().Where
                                                 (doctor => patientViewModel.DoctorsIds.Contains(doctor.Id)));

                    await CreateUser(patientViewModel);

                    ImageWorker imagePathGetter = new ImageWorker();
                    patient.ImageUrl = imagePathGetter.GetImageStringPath(patientViewModel.UserImage);
                    SaveImage(patientViewModel, patient);

                    db.Patients.Add(patient);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            patientViewModel.Doctors           = db.Doctors.ToList();
            patientViewModel.AttendingDoctorId = 1;
            return(View(patientViewModel));
        }
Beispiel #3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Name, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Patient patient = new Patient()
                    {
                        Name       = model.Name,
                        Email      = user.Email,
                        Status     = Status.Arrived,
                        DayOfBirth = model.DayOfBirth,
                        TaxCode    = model.TaxCode,
                    };
                    ImageWorker imagePathGetter = new ImageWorker();
                    patient.ImageUrl = imagePathGetter.GetImageStringPath(model.UserImage);
                    SaveImage(model, patient);
                    db.Patients.Add(patient);
                    db.SaveChanges();

                    await UserManager.AddToRoleAsync(user.Id, "Patient");

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Details", "Patients", new { id = patient.Id }));
                }
                AddErrors(result);
            }
            return(View(model));
        }
Beispiel #4
0
 private void ChangeImage(EditPatientViewModel editPatientViewModel, Patient currentPatient)
 {
     if (editPatientViewModel.ChangedImage != null)
     {
         ImageWorker imagePathGetter = new ImageWorker();
         currentPatient.ImageUrl = imagePathGetter.GetImageStringPath(editPatientViewModel.ChangedImage);
         editPatientViewModel.ChangedImage.SaveAs(Path.Combine(
                                                      Server.MapPath("~/AppFile/PatientPictures"), currentPatient.ImageUrl));
     }
 }