Ejemplo n.º 1
0
 public ActionResult SavePersonalInfo(UserModel.User user)
 {
     if (ModelState.IsValid)
     {
         var UpdateEmail = false;
         string email = user.BillingEmail;
         var UserCurrentEmail = user.GetCurrentEmail(User.Identity.Name);
         var UserCurrentCompany = user.GetCompany(User.Identity.Name);
         var EnteredEmailValid = user.IsEmailValid(email);
         var regexItem = new Regex(@"\d");
         Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
         Match match = regex.Match(email);
         if (!match.Success)
         {
             //Bad Email
             ModelState.AddModelError("BillingEmail", "Invalid Email");
         }
         else if (EnteredEmailValid && UserCurrentEmail != email)
         {
             //Email Taken
             ModelState.AddModelError("BillingEmail", "Email in use on another account");
             TempData["ViewData"] = ViewData;
         }
         else
         {
             UpdateEmail = true;
         }
         if (user.BillingName.Length < 5)
         {
             //Bad Username
             ModelState.AddModelError("BillingName", "Username must be a least 5 characters in length");
         }
         else if (user.DoesUsernameExist(user.BillingName) && user.BillingName != User.Identity.Name)
         {
             //Username already exists
             ModelState.AddModelError("BillingName", "Username is not available");
         }
         else if (user.Company.Length < 1)
         {
             //No company entered
             ModelState.AddModelError("Company", "Company name is not valid");
         }
         else if (UpdateEmail)
         {
             if (EnteredEmailValid && UserCurrentEmail == email)
             {
                 //Same email
             }
             else
             {
                 //Update email
                 var emailUpdateStatus = user.UpdateEmail(email, User.Identity.Name);
                 if (emailUpdateStatus == BusinessEntities.EmailUpdateStatus.Error)
                 {
                     //error view
                     return RedirectToAction("Error", "User");
                 }
             }
             //Update Username
             if (user.BillingName != User.Identity.Name)
             {
                 var userEmail = user.GetCurrentEmail(User.Identity.Name);
                 if (user.UpdateUsername(user.BillingName, User.Identity.Name))
                 {
                     //Authentication
                     HttpCookie userNameCookie = new HttpCookie("QueueViewUserName");
                     DateTime now = DateTime.Now;
                     userNameCookie.Value = User.Identity.Name;
                     userNameCookie.Expires = now.AddDays(-1D);
                     Response.Cookies.Add(userNameCookie);
                     FormsAuthentication.SignOut();
                     FormsAuthentication.SetAuthCookie(user.BillingName, false);
                 }
                 else
                 {
                     //error view
                     return RedirectToAction("Error", "User");
                 }
             }
             if (UserCurrentCompany != user.Company)
             {
                 if (!user.UpdateCompany(user.Company, User.Identity.Name))
                 {
                     //error view
                     return RedirectToAction("Error", "User");
                 }
             }
         }
     }
     TempData["ViewData"] = ViewData;
     return RedirectToAction("AccountDashboard", "User", new {ADID = "PersonalInfo"});
 }