public virtual async Task <ActionResult> Create(PatientCreateViewModel viewModel) { // Check if (viewModel == null) { return(View(MVC.Error.Views.BadRequest)); } // Validation if (ModelState.IsValid == false) { return(View(MVC.Patient.Views.Create)); } var validattor = await _patientValidator.CreateValidationAsync(viewModel.NationalCode); if (validattor != null) { ModelState.AddModelError("1", "کدملی تکراری است"); return(View(MVC.Patient.Views.Create)); } // Result await _patientService.CreateByViewModelAsync(viewModel); this.AddToastMessage("افزودن بیمار با موفقیت انجام شد", "", ToastType.Success); return(RedirectToAction(MVC.Document.Create(viewModel.NationalCode))); }
// GET: Patients/Create public ActionResult Create() { PatientCreateViewModel viewModel = new PatientCreateViewModel(); viewModel.PersonalDoctorID = new SelectList(db.Doctors, "ID", "FullName"); viewModel.HeightMetricUnit = "cm"; viewModel.WeightMetricunit = "kg"; return(View(viewModel)); }
public async Task <ActionResult> Create(PatientCreateViewModel patient) { if (ModelState.IsValid) { db.Patients.Add(patient.MapToPatient()); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(patient)); }
/// <summary> /// /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public async Task CreateByViewModelAsync(PatientCreateViewModel viewModel) { // Check if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } // Process var patient = _mapper.Map <Patient>(viewModel); _patients.Add(patient); await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId()); }
public Patient ToPatientDataModel(PatientCreateViewModel viewModel) { var result = new Patient { ID = viewModel.ID, FirstName = viewModel.FirstName, LastName = viewModel.LastName, Address = viewModel.Address, PhoneNumber = viewModel.PhoneNumber, Email = viewModel.Email, DateOfBirth = viewModel.DateOfBirth, Height = viewModel.Height, Weight = viewModel.Weight, BloodType = viewModel.BloodType, PatientSocialSecurityNumber = viewModel.PatientSocSecurityNum }; return(result); }
public ActionResult Create(PatientCreateViewModel viewModel) { PatientTranslator patientDataTranslator = new PatientTranslator(); Patient patient = patientDataTranslator.ToPatientDataModel(viewModel); viewModel.PersonalDoctorID = new SelectList(db.Doctors, "ID", "FullName", patient.PersonalDoctorID); if (ModelState.IsValid) { patient.PersonalDoctorID = viewModel.SelectedDoctorID; db.Patients.Add(patient); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(viewModel)); }
public ActionResult Create(PatientCreateViewModel patientData) { if (ModelState.IsValid) { var dbPatient = db.Pacjenci.FirstOrDefault(p => p.PESEL == patientData.PESEL.Trim()); if (dbPatient != null) { patientData.AlreadyExists = true; patientData.ActualPatient = dbPatient; return(View(patientData)); } var newPatient = new Patient() { LastName = patientData.LastName, Name = patientData.Name, PESEL = patientData.PESEL }; db.Pacjenci.Add(newPatient); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(patientData)); }