public async Task<IActionResult> Create( Patient patient ) { if( ModelState.IsValid ) { await _pat.CreateAsync( patient ); return RedirectToAction( "Index" ); } return View( patient ); } // Create
public async Task <Patient> Handle(CreatePatientCommand request, CancellationToken cancellationToken) { var patient = new Patient(request.Id, request.Name, request.BirthDate, request.Cpf, request.IdDoctor); if (patient == null) { throw new ApplicationException($"Erro ao criar paciente."); } patient.IdDoctor = request.IdDoctor; return(await _patientRepository.CreateAsync(patient)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Register(RegisterViewModel model) { var doctor = await _doctorRepository.ReadAsync(model.DoctorUserName); Patient patient = await model.GetNewPatient(_doctorRepository); patient.Doctor = doctor; //patient.DoctorUserName = doctor.UserName; //var result = await _userManager.CreateAsync(patient, model.Password); var newPat = await _patientRepository.CreateAsync(patient); if (newPat != null) { _logger.LogInformation("User created a new account with password."); patient.CreatedAt = DateTime.Now; patient.UpdatedAt = patient.CreatedAt; //patient.DrUserName = model.DoctorUserName; //patient.DoctorId = doctor?.Id; await _patientRepository.UpdateAsync(model.Email, patient); var code = await _userManager.GenerateEmailConfirmationTokenAsync(patient); var callbackUrl = Url.EmailConfirmationLink(patient.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); //await _signInManager.SignInAsync( patient, isPersistent: false ); _logger.LogInformation("User created a new account with password."); return(await Login(model.Email, model.Password)); // new JsonResult( new { } ); // } // Else, if registering didn't succeed... patient = await _patientRepository.ReadAsync(model.Email); if (patient != null && !String.IsNullOrEmpty(patient.RemoteLoginToken.ToString())) { return(new JsonResult(new { success = true, errorCode = ErrorCode.USER_ALREADY_LOGGED_IN, patient.RemoteLoginToken, patient.RemoteLoginExpiration, doctorUserName = patient?.Doctor?.UserName, patient.Email, patient.UserName, doctorId = patient?.Doctor?.Id })); } return(await Login(model.Email, model.Password)); //new JsonResult( new { success = false, errorCode = ErrorCode.USER_ALREADY_REGISTERED } ); }
public async Task<IActionResult> Create( Patient patient ) { if ( ModelState.IsValid ) { await _pat.CreateAsync( patient ); if ( User.IsInRole( Roles.DEVELOPER ) ) return RedirectToAction( nameof( PatientList ) ); else if( User.IsInRole( Roles.PATIENT ) ) return RedirectToAction( nameof( Index ) ); else if ( User.IsInRole( Roles.DOCTOR ) ) return RedirectToAction( nameof( Index ), Roles.DOCTOR ); } return View( patient ); } // Create
public async Task <Patient> CreatePatient(Patient patient) { //foreach (var patientAilment in patient.PatientAilments) //{ // patientAilment.Ailment = await _ailmentRepository.ReadById(patientAilment.AilmentId); // patientAilment.Patient = patient; // patientAilment.PatientId = patient.PatientId; //} //foreach (var patientMedication in patient.PatientMedications) //{ // patientMedication.Medication = await _medicationRepository.ReadById(patientMedication.MedicationId); // patientMedication.Patient = patient; // patientMedication.PatientId = patient.PatientId; //} await _patientRepository.CreateAsync(patient); return(patient); }
public async Task <PatientDto> CreateAsync(PatientDto entityDto) { return(await _patientRepository.CreateAsync(entityDto)); }
public async Task <IActionResult> Register(RegisterViewModel registerVM, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { _logger.LogInformation("********Role: " + registerVM.Role + "*************"); //IdentityResult result = null; //var user = registerVM.Role == Roles.DOCTOR ? (ApplicationUser) doctor : (ApplicationUser) patient; switch (registerVM.Role) { case Roles.DOCTOR: Doctor doctor = registerVM.GetNewDoctor(); doctor = await _doctorRepository.CreateAsync(doctor); await _userManager.AddToRoleAsync(doctor, Roles.DOCTOR.ToUpper()); //await _users.AssignRole(doctor.UserName, Roles.DOCTOR.ToUpper()); await SetupUser(doctor, registerVM); break; case Roles.PATIENT: Patient patient = await registerVM.GetNewPatient(_doctorRepository); patient = await _patientRepository.CreateAsync(patient); await _userManager.AddToRoleAsync(patient, Roles.PATIENT); await SetupUser(patient, registerVM); break; case Roles.DEVELOPER: Developer dev = registerVM.GetNewDeveloper(); //var result = await _userManager.CreateAsync(dev, registerVM.Password); dev = await _developerRepository.CreateAsync(dev); await _userManager.AddToRoleAsync(dev, Roles.DEVELOPER); await SetupUser(dev, registerVM); break; default: break; } //var user = new ApplicationUser { UserName = registerVM.Email, Email = registerVM.Email }; //if ( result != null && result.Succeeded ) //{ return(RedirectToLocal(returnUrl)); //} // if //AddErrors( result ); } // if // If we got this far, something failed, redisplay form return(View(registerVM)); } // Register