public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (string.IsNullOrWhiteSpace(model.MobileCountryCode)) { ModelState.AddModelError("MobilePhone", string.Format(UiHints.DisplayTemplates.Required, "Country code")); return View(model); } else { if (string.IsNullOrWhiteSpace(model.MobilePhone)) { ModelState.AddModelError("MobilePhone", string.Format(UiHints.DisplayTemplates.Required, "Mobile number")); return View(model); } model.MobileCountryCode = model.MobileCountryCode.Trim(); model.MobilePhone = model.MobilePhone.Trim(); if (model.MobilePhone.IndexOf("0") == 0) { model.MobilePhone = model.MobilePhone.Substring(1, model.MobilePhone.Length - 1); } string fullMobileNo = model.MobileCountryCode + model.MobilePhone; if (model.MobileCountryCode.IndexOf("+") != 0) { fullMobileNo = "+" + fullMobileNo; model.MobileCountryCode = "+" + model.MobileCountryCode; } if (!PhoneNumberHelper.PhoneNumberValidator(fullMobileNo)) { ModelState.AddModelError("MobilePhone", NotificationMessage.InvalidMobileNumber); return View(model); } else { if (Services.Users.GetByMobileNumber(model.MobilePhone, model.MobileCountryCode)) { ModelState.AddModelError("MobilePhone", NotificationMessage.MobileNumExists); return View(model); } } } if (!string.IsNullOrWhiteSpace(model.HomePhoneCountryCode) || !string.IsNullOrWhiteSpace(model.HomePhone)) { if (string.IsNullOrWhiteSpace(model.HomePhoneCountryCode)) { ModelState.AddModelError("HomePhoneValidate", NotificationMessage.CountryCodeIsRequired); return View(model); } if (string.IsNullOrWhiteSpace(model.HomePhone)) { ModelState.AddModelError("HomePhoneValidate", NotificationMessage.HomePhoneIsRequired); return View(model); } model.HomePhoneCountryCode = model.HomePhoneCountryCode.Trim(); model.HomePhone = model.HomePhone.Trim(); if (model.HomePhoneCountryCode.IndexOf("+") != 0) { model.HomePhoneCountryCode = "+" + model.HomePhoneCountryCode; } if (model.HomePhone.IndexOf("0") == 0) { model.HomePhone = model.HomePhone.Substring(1, model.HomePhone.Length - 1); } if (!PhoneNumberHelper.PhoneNumberValidator(model.HomePhoneCountryCode + model.HomePhone)) { ModelState.AddModelError("HomePhone", NotificationMessage.InvalidMobileNumber); return View(model); } } var AppUser = new ApplicationUser { UserName = model.UserName, Email = model.Email, MobilePhone = model.MobilePhone, MobileCountryCode = model.MobileCountryCode, HomePhone = !string.IsNullOrEmpty(model.HomePhone) ? model.HomePhone.Trim() : string.Empty, HomePhoneCountryCode = !string.IsNullOrWhiteSpace(model.HomePhoneCountryCode) ? model.HomePhoneCountryCode.Trim() : string.Empty, DateSentEmail = DateTime.UtcNow, Role = model.Role, CompletedStep = Step.Step0, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, ExpiredDate = DateTime.Now.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["DaysExp"])), Status = (int)Status.NULL }; var result = await _userManager.CreateAsync(AppUser, model.Password); if (result.Succeeded) { await SendConfirmEmail(AppUser.Id); return Redirect("Congratulation"); } else { AddErrors(result); return View(model); } } else { return View(model); } }
public ActionResult Register(string role) { if (Role.Specialist.ToString().Equals(role)) { ViewBag.headerRegister = "Join"; ViewBag.header = CONSULTANT_REGISTRATION_HEADER; } else { ViewBag.headerRegister = "Register"; ViewBag.header = CLIENT_REGISTRATION_HEADER; } RegisterViewModel model = new RegisterViewModel(); model.Role = (Role)Enum.Parse(typeof(Role), role); return View(model); }