public ActionResult ChangeContactInfo(ChangeContactInfoViewModel model)
 {
     if (ModelState.IsValid)
     {
         var personToUpdate = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);
         try
         {
             _volunteerSvc.UpdateDetails(new Person {
                 Id = personToUpdate.Id,
                 Cluster= personToUpdate.Cluster,
                 ClusterId = personToUpdate.ClusterId,
                 FirstName = personToUpdate.FirstName,
                 LastName = personToUpdate.LastName,
                 UserId = personToUpdate.UserId,
                 Email =  model.Email,
                 PhoneNumber = model.PhoneNumber
             });
             return RedirectToAction("ContactInfoChanged");
         }
         catch (PersonEmailAlreadyInUseException)
         {
             ModelState.AddModelError("Email", "This Email Address is already in use!");
         }
     }
     return View();
 }
示例#2
0
 public ActionResult ChangeContactInfo()
 {
     if (WebSecurity.CurrentUserId == 1)
     {
         TempData["AdminContactError"] = "Administrator is not allowed to have contact details!";
         return RedirectToAction("Index", "Home");
     }
     var personToUpdate = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);
     ChangeContactInfoViewModel model = new ChangeContactInfoViewModel { Email = personToUpdate.Email, PhoneNumber = personToUpdate.PhoneNumber };
     return View(model);
 }
        public ActionResult ChangeContactInfo()
        {
            if (_webSecurity.CurrentUserId == 1)
            {
                TempData["AdminContactError"] = "Administrator is not allowed to have contact details!";
                return RedirectToAction("Index", "Home");
            }
            var personToUpdate = _volunteerSvc.GetPersonDetailsForChangeContactInfo(_webSecurity.CurrentUserId);
            if (personToUpdate != null)
            {
                ChangeContactInfoViewModel model = new ChangeContactInfoViewModel { Email = personToUpdate.Email, PhoneNumber = personToUpdate.PhoneNumber };
                return View(model);
            }

            return View("ChangeContactInfo", DetermineLayout(), null);
        }
        public void ChangeContactInfo_Assign_ValidData_Redirects_To_ContactInfoChanged_View()
        {
            // Arrange
            _volunteerService.Setup(x => x.FindByUserId(It.IsAny<int>())).Returns(new Person());

            // Act
            var model = new ChangeContactInfoViewModel { Email = "*****@*****.**", PhoneNumber = "123456789" };

            Mother.ControllerHelpers.SetupControllerModelState(model, _controllerUnderTest);

            var response = _controllerUnderTest.ChangeContactInfo(model);

            // Assert
            var view = response as RedirectToRouteResult;
            Assert.IsNotNull(view);

            var action = view.RouteValues["action"];
            Assert.AreEqual("ContactInfoChanged", action.ToString());
        }
        public void ChangeContactInfo_DuplicateEmailAddress_ReturnsChangeContactInfoView_With_ModelState_Error()
        {
            // Arrange
            _volunteerService.Setup(x => x.UpdateDetails(It.IsAny<Person>())).Throws<PersonEmailAlreadyInUseException>();

            // Act
            var model = new ChangeContactInfoViewModel { Email = "*****@*****.**", PhoneNumber = "123456789" };

            Mother.ControllerHelpers.SetupControllerModelState(model, _controllerUnderTest);

            var response = _controllerUnderTest.ChangeContactInfo(model);

            // Assert
            var result = response as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ViewData.ModelState.ContainsKey("Email"));
            Assert.IsTrue(result.ViewName.Equals("ChangeContactInfo"));
            Assert.IsTrue(result.ViewData.ModelState.Count >= 1);
        }
 public ActionResult ChangeContactInfo(ChangeContactInfoViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _volunteerSvc.UpdateDetails(new Person {
                 UserId = _webSecurity.CurrentUserId,
                 Email =  model.Email,
                 PhoneNumber = model.PhoneNumber
             });
             return RedirectToAction("ContactInfoChanged");
         }
         catch (PersonEmailAlreadyInUseException)
         {
             ModelState.AddModelError("Email", "This Email Address is already in use!");
         }
     }
     return View("ChangeContactInfo", DetermineLayout(), model);
 }
        public void ChangeContactInfo_Invalid_ModelState_Directs_User_To_ChangeContactInfo_View()
        {
            // Arrange

            // Act
            var model = new ChangeContactInfoViewModel { Email = "*****@*****.**", PhoneNumber = "" };

            Mother.ControllerHelpers.SetupControllerModelState(model, _controllerUnderTest);

            var response = _controllerUnderTest.ChangeContactInfo(model);

            // Assert
            var result = response as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ViewName.Equals("ChangeContactInfo"));
            Assert.IsTrue(result.ViewData.ModelState.Count >= 1);
        }
 public ActionResult ChangeContactInfo()
 {
     var personToUpdate = _volunteerSvc.FindByUserId(WebSecurity.CurrentUserId);
     ChangeContactInfoViewModel model = new ChangeContactInfoViewModel { Email = personToUpdate.Email, PhoneNumber = personToUpdate.PhoneNumber };
     return View(model);
 }
        public ActionResult ChangeContactInfo(ChangeContactInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _volunteerSvc.UpdateDetails(new Person {
                        UserId = _webSecurity.CurrentUserId,
                        Email =  model.Email,
                        PhoneNumber = model.PhoneNumber,
                        OrganizationId = model.SelectedOrganizationId
                    });
                    return RedirectToAction("ContactInfoChanged");
                }
                catch (PersonEmailAlreadyInUseException)
                {
                    ModelState.AddModelError("Email", "This Email Address is already in use!");
                }
            }
            // rehydrate organizations if necessary.
            model.Organizations = model.Organizations ?? _organizationService.GetActiveList();

            return View("ChangeContactInfo", DetermineLayout(), model);
        }