public ActionResult Login(UserVM user)
        {
            if (ModelState.IsValid)
            {
                try {
                    var userDTO = userService.GetUser(user.Login);
                    user = MapperUtilVM.MapToUserVM(userDTO);

                    if (user != null)
                    {
                        Session["Login"] = user.Login;
                        Session["Id"]    = user.UserId;
                        Session["Role"]  = userService.GetUserRole(userDTO).Name;
                        if (user.RoleId == 1 && Session["DoctorId"] != null)
                        {
                            Session["DoctorId"] = doctorService.GetDoctors().FirstOrDefault(id => id.UserId == user.UserId).DoctorId;
                        }
                        FormsAuthentication.SetAuthCookie(user.Login, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Пользователь с таким логином не существует.");
                    }
                } catch (ValidationException ex) {
                    Debug.WriteLine("Возникла ошибка (Пользователь с введенным логином не найден): " + ex.Message);
                }
                return(View(user));
            }
            else
            {
                ModelState.AddModelError("", "Введенный логин или пароль не верны.");
                return(View(user));
            }
        }
Exemplo n.º 2
0
        public PartialViewResult CreateAppointment()
        {
            List <DoctorVM>  doctorVMs        = MapperUtilVM.MapToDoctorVMList(doctorService.GetDoctors());
            List <PatientVM> patientVMs       = MapperUtilVM.MapToPatientVMList(patientService.GetPatients());
            SelectList       doctorNamesList  = new SelectList(doctorVMs, "DoctorId", "FullName");
            SelectList       patientNamesList = new SelectList(patientVMs, "PatientId", "FullName");

            ViewBag.doctorNamesList  = doctorNamesList;
            ViewBag.patientNamesList = patientNamesList;
            return(PartialView("_CreateAppointment", new Models.AppointmentVM()));
        }
Exemplo n.º 3
0
        private List <AppointmentVM> GetAppointments()
        {
            List <AppointmentVM> appointments = MapperUtilVM.MapToAppointmentVMList(appointmentService.GetAppointments());

            foreach (AppointmentVM appointment in appointments)
            {
                appointment.DoctorName  = appointmentService.GetDoctorName(appointment.DoctorId);
                appointment.PatientName = appointmentService.GetPatientName(appointment.PatientId);
            }
            return(appointments);
        }
Exemplo n.º 4
0
        public PartialViewResult EditAppointment(long appointmentId)
        {
            List <DoctorVM>  doctorVMs        = MapperUtilVM.MapToDoctorVMList(doctorService.GetDoctors());
            List <PatientVM> patientVMs       = MapperUtilVM.MapToPatientVMList(patientService.GetPatients());
            SelectList       doctorNamesList  = new SelectList(doctorVMs, "DoctorId", "FullName");
            SelectList       patientNamesList = new SelectList(patientVMs, "PatientId", "FullName");

            ViewBag.doctorNamesList  = doctorNamesList;
            ViewBag.patientNamesList = patientNamesList;

            AppointmentVM appointment = MapperUtilVM.MapToAppointmentVM(appointmentService.GetAppointment(appointmentId));

            return(PartialView("_EditAppointment", appointment));
        }
Exemplo n.º 5
0
        public ActionResult DeleteDoctor(int id)
        {
            DoctorDTO doctor = doctorService.GetDoctors().FirstOrDefault(doctorId => doctorId.DoctorId == id);

            if (doctor != null)
            {
                return(View(MapperUtilVM.MapToDoctorVM(doctor)));
            }
            else
            {
                ViewBag.Title   = "Ошибка удаления врача.";
                ViewBag.Message = "Не удалось найти врача для удаления с идентификационным номером = " + id;
                return(View("Error"));
            }
        }
Exemplo n.º 6
0
        public string CreatePatient([Bind(Exclude = "PatientId")] PatientVM patient)
        {
            string msg;

            try
            {
                if (ModelState.IsValid)
                {
                    patientService.AddPatient(MapperUtilVM.MapToPatientDTO(patient));
                    msg = "Пациент добавлен успешно";
                }
                else
                {
                    msg = "Пациент не был добавлен. Ошибка валидации модели";
                }
            }
            catch (Exception ex)
            {
                msg = "Возникла ошибка: " + ex.Message;
            }
            return(msg);
        }
Exemplo n.º 7
0
        public string EditPatient(PatientVM patient)
        {
            string msg;

            try
            {
                if (ModelState.IsValid)
                {
                    patientService.EditPatient(MapperUtilVM.MapToPatientDTO(patient));
                    msg = "Запись пациента успешно редактирована";
                }
                else
                {
                    msg = "Запись пациента не была редактирована. Ошибка валидации модели";
                }
            }
            catch (Exception ex)
            {
                msg = "Возникла ошибка: " + ex.Message;
            }
            return(msg);
        }
        public ActionResult RegisterDoctor(RegisterDoctorVM model)
        {
            if (ModelState.IsValid)
            {
                UserDTO user = userService.GetUsers().FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);

                if (user == null)
                {
                    model.RoleId = 1;
                    userService.AddUser(MapperUtilVM.MapToUserDTO(model));

                    // проверяем если пользователь удачно добавлен в бд
                    var newUser = userService.GetUsers().FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);
                    if (newUser != null)
                    {
                        try {
                            model.UserId = newUser.UserId;
                            doctorService.AddDoctor(MapperUtilVM.MapToDoctorDTO(model));
                            Session["Login"]    = newUser.Login;
                            Session["Id"]       = newUser.UserId;
                            Session["Role"]     = "Doctor";
                            Session["DoctorId"] = doctorService.GetDoctors().FirstOrDefault(id => id.UserId == newUser.UserId).DoctorId;
                            FormsAuthentication.SetAuthCookie(model.Login, true);
                            return(RedirectToAction("ListDoctors", "Home"));
                        } catch (Exception ex) {
                            ModelState.AddModelError("", "Ошибка регистрации врача: " + ex.Message);
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }
            return(View(model));
        }
Exemplo n.º 9
0
 public ActionResult EditDoctor(int id)
 {
     return(View(MapperUtilVM.MapToDoctorVM(doctorService.GetDoctors().FirstOrDefault(doctorID => doctorID.DoctorId == id))));
 }
Exemplo n.º 10
0
 private List <DoctorVM> GetDoctors()
 {
     return(MapperUtilVM.MapToDoctorVMList(doctorService.GetDoctors()));
 }
Exemplo n.º 11
0
 public JsonResult CreateAppRecord(AppointmentRecordVM appointmentRecordVM)
 {
     appointmentService.AddAppointmentRecord(MapperUtilVM.MapToAppointmentRecordDTO(appointmentRecordVM));
     return(Json(appointmentRecordVM, JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 12
0
 private List <AppointmentRecordVM> GetAppointmentRecords()
 {
     return(MapperUtilVM.MapToAppointmentRecordVMList(appointmentService.GetAppointmentRecords()));
 }
Exemplo n.º 13
0
 public PartialViewResult AJAXGetAppointmentRecords(long appointmentId)
 {
     return(PartialView("_ListAppointmentRecords", MapperUtilVM.MapToAppointmentRecordVMList(appointmentService.GetAppointmentRecordsByAppointment(appointmentId))));
 }
Exemplo n.º 14
0
        public PartialViewResult EditAppointmentRecord(long appointmentRecordId)
        {
            AppointmentRecordVM appointment = MapperUtilVM.MapToAppointmentRecordVM(appointmentService.GetAppointmentRecord(appointmentRecordId));

            return(PartialView("_EditAppointmentRecord", appointment));
        }
Exemplo n.º 15
0
 public JsonResult EditAppointment(AppointmentVM appointmentVM)
 {
     appointmentService.EditAppointment(MapperUtilVM.MapToAppointmentDTO(appointmentVM));
     return(Json(appointmentVM, JsonRequestBehavior.AllowGet));
 }