public async Task <ActionResult> Register(DoctorRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.RegisterViewModel.Email, Email = model.RegisterViewModel.Email }; var result = await UserManager.CreateAsync(user, model.RegisterViewModel.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); var doctor = new Doctors(); doctor.DoctorUserID = user.Id; doctor.DoctorCode = model.Doctors.DoctorCode; doctor.NameAr = model.Doctors.NameAr; doctor.NameEn = model.Doctors.NameEn; _context.Doctors.Add(doctor); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult Register(string currentId) { DoctorRegisterViewModel registerDoctor = new DoctorRegisterViewModel(); registerDoctor.UserId = currentId; return(View("RegisterDoctor", registerDoctor)); }
public void RegisterNewDoctor(DoctorRegisterViewModel RegisteringDoctor) { //first register his address. AddressModel AddressToAdd = new AddressModel(); AddressToAdd.BuildingNumber = RegisteringDoctor.BuildingNumber; AddressToAdd.StreetName = RegisteringDoctor.StreetName; AddressToAdd.City = RegisteringDoctor.City; AddressToAdd.State = RegisteringDoctor.State; AddressToAdd.ZipCode = RegisteringDoctor.ZipCode; _context.Addresses.Add(AddressToAdd); _context.SaveChanges(); //get the PK of the building. var AddressPk = _context.Addresses.Where(a => a.StreetName == RegisteringDoctor.StreetName && a.BuildingNumber == RegisteringDoctor.BuildingNumber && a.City == RegisteringDoctor.City && a.State == RegisteringDoctor.State && a.ZipCode == RegisteringDoctor.ZipCode).Select(a => a.PrimaryKey).FirstOrDefault(); DoctorModel doctor = new DoctorModel(); doctor.DoctorHospitalBuildingKey = AddressPk; doctor.UserId = RegisteringDoctor.UserId; _context.Doctors.Add(doctor); _context.SaveChanges(); }
public ActionResult AddDoctor() { if (Session["userId"] == null) { return(Redirect("~")); } var model = new DoctorRegisterViewModel { Password = Default.Password.GetDescription() }; return(View(model)); }
public ActionResult AddDoctor(DoctorRegisterViewModel model, string returnUrl) { if (Session["userId"] == null) { return(Redirect("~")); } Users user = new Users(); user.RoleId = Convert.ToInt32(Roles.Doctor); AutoMapper.Mapper.Map(model, user); user.CreatedBy = (int)Session["userId"]; DoctorAvailability availability = new DoctorAvailability(); DoctorFee doctorFee = new DoctorFee(); doctorFee.Fee = model.Fee; List <DoctorSpecialization> doctorSpecialization = new List <DoctorSpecialization>(); foreach (var item in model.Specializations) { DoctorSpecialization DoctorSpecialization = new DoctorSpecialization(); DoctorSpecialization.SpecializationId = (int)item; doctorSpecialization.Add(DoctorSpecialization); } try { if (new Accounts().AddUser(user, availability, doctorSpecialization, doctorFee)) { return(Redirect("~/Admin/Doctors")); } else { return(RedirectToAction("~/Admin/Doctors/Add")); } } catch (EmailAlreadyExistsEx ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } catch (PhoneAlreadyExistsEx ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", "Unable to add doctor"); return(View(model)); } }
public async Task <IActionResult> Edit(DoctorRegisterViewModel model) { var user = _unitOfWork.doctorRepository.GetDoctorById(model.Doctor.Id); var doctor = new Doctor { Address = user.Address, Phone = user.Phone, SpecializationId = user.SpecializationId, Name = user.Name, }; _unitOfWork.Complete(); return(View()); }
public async Task <IActionResult> Update(string returnUrl = null) { var model = new DoctorRegisterViewModel(); var user = (DoctorUser)await _userManager.GetUserAsync(HttpContext.User); model.FirstName = user.FirstName; model.LastName = user.LastName; model.Address = user.Address; model.starttime = user.starttime; model.endtime = user.endtime; model.PhoneNumber = user.PhoneNumber; model.UserPhoto = model.UserPhoto; ViewData["ReturnUrl"] = "/Doctor/Profile"; return(View(model)); }
public async Task <ActionResult> RegisterDoctor(DoctorRegisterViewModel model) { if (ModelState.IsValid) { var doctor = new Doctor { UserName = model.UserName, Email = model.Email, UserType = model.Roles, Gender = model.Gender, PhoneNumber = model.PhoneNumber, BirthDate = model.BirthDate, CityId = model.CityId, CardId = model.CardNumber, CategoryId = model.CategoryId }; var result = await UserManager.CreateAsync(doctor, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(doctor, 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>"); await this.UserManager.AddToRoleAsync(doctor.Id, model.Roles); return(RedirectToAction("Index", "Doctors")); } ViewBag.Country = db.Countries.ToList(); ViewBag.GovernorateId = new SelectList(db.Governorates.ToList(), "Id", "GovernorateName"); ViewBag.CityId = new SelectList(db.Cities.ToList(), "Id", "CitiesName"); ViewBag.Roles = new SelectList(db.Roles.Where(a => !a.Name.Contains("Admin") && !a.Name.Contains("Guest") && !a.Name.Contains("مريض")).ToList(), "Name", "Name"); ViewBag.CategoryId = new SelectList(db.Categories.ToList(), "Id", "CategoryName"); AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Update(DoctorRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = "/Doctor/Profile"; var currentUser = await _userManager.GetUserAsync(HttpContext.User); var DBuser = _context.Doctors.SingleOrDefault(u => u.Id == currentUser.Id); if (DBuser != null) { if (DBuser.FirstName != model.FirstName || DBuser.LastName != model.LastName) { var messages = (from message in _context.Messages where message.DoctorID == currentUser.Id select message).ToList(); foreach (Message m in messages) { m.DoctorName = model.FirstName + " " + model.LastName; } } DBuser.FirstName = model.FirstName; DBuser.LastName = model.LastName; DBuser.Address = model.Address; DBuser.starttime = model.starttime; DBuser.endtime = model.endtime; DBuser.PhoneNumber = model.PhoneNumber; using (var memoryStream = new MemoryStream()) { if (model.UserPhoto != null) { await model.UserPhoto.CopyToAsync(memoryStream); DBuser.UserPhoto = memoryStream.ToArray(); } } _context.SaveChanges(); return(Redirect("/Doctor/Profile")); } return(View(model)); }
public async Task <IActionResult> DoctorRegister(DoctorRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new DoctorUser { FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email, Address = model.Address, PhoneNumber = model.PhoneNumber, AccountType = "Doctor", starttime = model.starttime, endtime = model.endtime }; using (var memoryStream = new MemoryStream()) { await model.UserPhoto.CopyToAsync(memoryStream); user.UserPhoto = memoryStream.ToArray(); } var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult DocotrRegister(DoctorRegisterViewModel doctorView) { if (ModelState.IsValid) { var doctor = new Doctor() { FirstName = doctorView.FirstName, LastName = doctorView.LastName, Sex = doctorView.Sex, Age = doctorView.Age, PhoneNo = doctorView.PhoneNo, UserId = doctorView.UserId, Password = doctorView.Password, RegistrationStatus = false }; _context.Doctors.Add(doctor); _context.SaveChanges(); return(View()); } else { return(View("Error")); } }
public ActionResult Associate() { var model = new DoctorRegisterViewModel(); return View(model); }
public IActionResult ProcessRegisterForm(DoctorRegisterViewModel doctor) { _doctorServices.RegisterNewDoctor(doctor); return(RedirectToAction("Index", "Doctor")); }