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)); } }
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())); }
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); }
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)); }
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")); } }
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); }
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)); }
public ActionResult EditDoctor(int id) { return(View(MapperUtilVM.MapToDoctorVM(doctorService.GetDoctors().FirstOrDefault(doctorID => doctorID.DoctorId == id)))); }
private List <DoctorVM> GetDoctors() { return(MapperUtilVM.MapToDoctorVMList(doctorService.GetDoctors())); }
public JsonResult CreateAppRecord(AppointmentRecordVM appointmentRecordVM) { appointmentService.AddAppointmentRecord(MapperUtilVM.MapToAppointmentRecordDTO(appointmentRecordVM)); return(Json(appointmentRecordVM, JsonRequestBehavior.AllowGet)); }
private List <AppointmentRecordVM> GetAppointmentRecords() { return(MapperUtilVM.MapToAppointmentRecordVMList(appointmentService.GetAppointmentRecords())); }
public PartialViewResult AJAXGetAppointmentRecords(long appointmentId) { return(PartialView("_ListAppointmentRecords", MapperUtilVM.MapToAppointmentRecordVMList(appointmentService.GetAppointmentRecordsByAppointment(appointmentId)))); }
public PartialViewResult EditAppointmentRecord(long appointmentRecordId) { AppointmentRecordVM appointment = MapperUtilVM.MapToAppointmentRecordVM(appointmentService.GetAppointmentRecord(appointmentRecordId)); return(PartialView("_EditAppointmentRecord", appointment)); }
public JsonResult EditAppointment(AppointmentVM appointmentVM) { appointmentService.EditAppointment(MapperUtilVM.MapToAppointmentDTO(appointmentVM)); return(Json(appointmentVM, JsonRequestBehavior.AllowGet)); }