public async Task <ActionResult> RegisterDoctor(RegisterDoctorViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (model.Sexe.Equals("M")) { model.Sexe = "homme"; } else { model.Sexe = "femme"; } user user = new user { firstName = model.FirstName, lastName = model.LastName, password = model.Password, phoneNumber = model.Phone, sexe = model.Sexe, address = model.Street, email = model.Email, licenseNumber = model.Code, user_type = "doctor", role = "doctor" }; ServiceUser serviceUser = new ServiceUser(); if (await serviceUser.RegisterUser(user)) { return(RedirectToAction("Login")); } return(View(model)); }
public ActionResult DoctorReport(/*string specialization = null*/) { List <RegisterDoctorViewModel> DoctorVMList = new List <RegisterDoctorViewModel>(); //var query = db.Doctors.AsEnumerable(); List <Doctor> DoctorsInDb = db.Doctors.ToList(); foreach (Doctor item in DoctorsInDb) { RegisterDoctorViewModel DoctorVM = new RegisterDoctorViewModel(); DoctorVM.FirstName = item.FirstName; DoctorVM.Surname = item.Surname; DoctorVM.BirthDate = item.BirthDate; DoctorVM.Gender = item.Gender; DoctorVM.ContactNumber = item.ContactNumber; DoctorVM.NIC = item.NIC; DoctorVM.Specialization = item.Specialization; DoctorVM.Qualification = item.Qualification; DoctorVM.ChannelFee = item.ChannelFee; DoctorVM.ChannelStartTime = item.ChannelStartTime; DoctorVM.ChannelEndTime = item.ChannelEndTime; DoctorVM.AverageChannelDuration = item.AverageChannelDuration; DoctorVM.NumOfPatientsPerDay = item.NumOfPatientsPerDay; DoctorVM.Room = item.Room; DoctorVMList.Add(DoctorVM); } return(View(DoctorVMList)); }
public async Task <IActionResult> RegisterDoctor(RegisterDoctorViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = new ApplicationUser { UserName = model.Name, IsActive = true }; var createUserResult = await _userManager.CreateAsync(user, model.Password); if (createUserResult.Succeeded) { await _userManager.AddToRoleAsync(user, "Doctor"); await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.GivenName, model.Name)); var signInResult = await _signInManager.PasswordSignInAsync(user, model.Password, false, false); if (signInResult.Succeeded) { await _specializationsRepository.AddSpecialization( new Specialization { Name = model.Specialization }); var docsSpec = await _specializationsRepository.GetSpecializationByUserName(model.Specialization); var doctor = new Doctor { Name = model.Name, FirstName = model.FirstName, LastName = model.LastName, Phone = model.Phone, Specialization = docsSpec, ApplicationUserID = user.Id }; await _doctorsRepository.AddDoctor(doctor); return(View("RegisterSuccessful")); } } foreach (var identityError in createUserResult.Errors) { ModelState.AddModelError("", identityError.Description); } return(View(model)); }
public static Doctor ToDoctor(RegisterDoctorViewModel viewModel, ApplicationUser applicationUser) { return(new Doctor { Id = applicationUser.Id, FirstName = viewModel.FirstName, LastName = viewModel.LastName, Speciality = viewModel.Speciality, Ward = viewModel.Ward, HospitalId = viewModel.HospitalId }); }
public async Task <IActionResult> Register([FromBody] RegisterDoctorViewModel theDoctor) { if (ModelState.IsValid) { var password = theDoctor.Password; var newDoctor = Mapper.Map <Doctor>(theDoctor); var result = await _userManager.CreateAsync(newDoctor, password); return(RedirectToAction("Index", "App")); } return(BadRequest("Failed to register")); }
public async Task <IActionResult> DoctorRegister(RegisterDoctorViewModel model) { if (ModelState.IsValid) { var roleName = "Doctor"; if (model.ImageName == null) { model.ImageName = "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR_q1QWy4q604M8nPCoHqq1rR8OCoQ3wx5iRScLfgjO7F1-gwdH"; } DoctorProfile doctor = new DoctorProfile() { Login = model.Login, FirstName = model.FirstName, LastName = model.LastName, Experience = model.Experience, SpecializationId = Convert.ToInt32(model.SicknessId), HospitalId = 1, Image = model.ImageName }; var dbUser = new DbUser() { Email = model.Email, UserName = model.Email, DoctorProfiles = doctor }; var result = await _userManager.CreateAsync(dbUser, model.Password); result = _userManager.AddToRoleAsync(dbUser, roleName).Result; if (result.Succeeded) { // установка куки await _signInManager.SignInAsync(dbUser, false); return(RedirectToAction("Login", "Home")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> RegisterDoctor([FromBody] RegisterDoctorViewModel doctorModel) { //ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = doctorModel.Email, Email = doctorModel.Email }; var result = await _userManager.CreateAsync(user, doctorModel.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var createdDoctor = await _userManager.FindByEmailAsync(doctorModel.Email); await _userManager.AddToRoleAsync(createdDoctor, "HospitalDoctor"); var doctorDb = Mappers.MapperRegisterDoctor.ToDoctor(doctorModel, createdDoctor); try { _doctorsService.AddDoctor(doctorDb); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); //await _emailSender.SendEmailConfirmationAsync(doctorModel.Email, callbackUrl); //await _signInManager.SignInAsync(user, isPersistent: false); _logger.LogInformation("User created a new account with password."); //return RedirectToLocal(returnUrl); return(Ok(doctorModel)); }catch (Exception ex) { return(BadRequest(ex.Message)); } } AddErrors(result); } // If we got this far, something failed, redisplay form return(BadRequest("Something failed in register doctor")); }
public ActionResult Register(RegisterDoctorViewModel doctorViewModel, HttpPostedFileBase photo) { // Check Username Doctor doctor = new Doctor(); if (doctorViewModel.Username != null) { var count = db.Doctors.Count(e => e.Username.Equals(doctorViewModel.Username)); if (count == 1) { ModelState.AddModelError("Username", "Tên đăng nhập đã tồn tại"); } } if (doctorViewModel.Email != null) { var count = db.Doctors.Count(e => e.Email.Equals(doctorViewModel.Email)); if (count == 1) { ModelState.AddModelError("Email", "Email đã tồn tại"); } } if (ModelState.IsValid) { doctor.Firstname = doctorViewModel.Firstname; doctor.Lastname = doctorViewModel.Lastname; doctor.Email = doctorViewModel.Email; doctor.Username = doctorViewModel.Username; doctor.Gender = doctorViewModel.Gender; doctor.Birthday = new DateTime(doctorViewModel.Year, doctorViewModel.Month, doctorViewModel.Day); doctor.CreateDate = DateTime.Now; doctor.Password = BCrypt.Net.BCrypt.HashPassword(doctorViewModel.Password); db.Doctors.Add(doctor); db.SaveChanges(); BuildEmailTemplate(doctor.Id); ViewBag.thongbao = "Cảm ơn bạn. Một thư xác nhận sẽ được gửi đến địa chỉ email " + doctor.Email + " trong ít phút, bạn vui lòng mở hộp thư và bấm vào URL bên trong thư để hoàn tất"; return(View("Notification")); } else { return(View("Register", doctorViewModel)); } }
public async Task <ActionResult> RegisterDoctor(RegisterDoctorViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, Surname = model.Surname, CityOrVillage = model.CityOrVillage, District = model.District, Street = model.Street, House = model.House, Flat = model.Flat, PostalCode = model.PostalCode }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var doctor = new Doctor { AspNetUsers_Id = user.Id, Speciality_Name = model.Speciality }; DoctorsController doctorsController = new DoctorsController(); doctorsController.Create(doctor); await this.UserManager.AddToRoleAsync(user.Id, "Doctor"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> RegisterDoctor(RegisterDoctorViewModel model) { if (ModelState.IsValid) { var user = new Doctor { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, Surname = model.Surname, BirthDate = model.BirthDate, Gender = model.Gender, ContactNumber = model.ContactNumber, NIC = model.NIC, JoinedAt = DateTime.UtcNow, Specialization = model.Specialization, Qualification = model.Qualification, ChannelFee = model.ChannelFee, ChannelStartTime = model.ChannelStartTime, AverageChannelDuration = model.AverageChannelDuration, ChannelEndTime = model.ChannelEndTime, NumOfPatientsPerDay = (int)((model.ChannelEndTime - model.ChannelStartTime).TotalMinutes) / model.AverageChannelDuration, Room = model.Room }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await UserManager.AddToRoleAsync(user.Id, "Doctor"); return(RedirectToAction("AdminMenu", "Menu", new { message = "Doctor Registered Successfully" })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register([FromBody] RegisterDoctorViewModel theDoctor) //przyjmuje doctora w formie która jest w RegisterDoctor { if (ModelState.IsValid) //sprawdza czy doctorj jest zgodny z założeniami register doctor { var password = theDoctor.Password; var newDoctor = Mapper.Map <Doctor>(theDoctor);//mapuje doctora z RegisterDoctor na Doctor var result = await _userManager.CreateAsync(newDoctor, password); if (result.Succeeded) { await _signInManager.SignInAsync(newDoctor, isPersistent : false); return(RedirectToAction("Patients", "App"));//nie działa :( po zarejestrowaniu nie przechodzi do App Patients TODO } } else { return(BadRequest("Failed to register")); } return(View()); }
public RegisterStatus RegisterAsDoctor(RegisterDoctorViewModel vm) { try { using (var db = new MedCredaEntities()) { Account account = new Account(); var isAccountExists = db.Accounts.Where(x => x.Username == vm.Username || x.EmailAddress == vm.EmailAddress).Any(); if (isAccountExists) { return(RegisterStatus.EmailUsernameExists); } var viewModelParser = new ViewModelParser <Account, RegisterDoctorViewModel>(account, vm); viewModelParser.UpdateModelState(); db.Accounts.Add(account); db.SaveChanges(); } } catch (Exception ex) { //result = false; //throw; } return(RegisterStatus.Registered); }
public async Task <IActionResult> RegisterDoctor(RegisterDoctorViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = new ApplicationUser { UserName = model.Name, IsActive = true }; var createUserResult = await _userManager.CreateAsync(user, model.Password); if (createUserResult.Succeeded) { await _userManager.AddToRoleAsync(user, "Doctor"); await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.GivenName, model.Name)); var signInResult = await _signInManager.PasswordSignInAsync(user, model.Password, false, false); if (signInResult.Succeeded) { await _appService.AddSpecialization( new Specialization { Name = model.Specialization }, CancellationToken.None); var docsSpec = await _appService.GetSpecializationByName(model.Specialization, CancellationToken.None); var doctor = new Doctor { Name = model.Name, FirstName = model.FirstName, LastName = model.LastName, Phone = model.Phone, Specialization = docsSpec, ApplicationUser = user }; await _appService.AddDoctor(doctor, CancellationToken.None); return(View("RegisterSuccessful")); } } foreach (var identityError in createUserResult.Errors) { if (identityError.Code == "DuplicateUserName") { ModelState.AddModelError("", "Ta nazwa użytkownika jest już zajęta."); } else { ModelState.AddModelError("", identityError.Description); } } return(View(model)); }
public IHttpActionResult RegisterAsDoctor(RegisterDoctorViewModel vm) { return(Ok(_accountManager.RegisterAsDoctor(vm))); }