Beispiel #1
0
        public void UpdateAssistantTest()
        {
            // Arrange
            Users user = new Users();

            user.FirstName   = "TestAssistant";
            user.LastName    = "TestAssistant";
            user.Password    = "******";
            user.Phone       = "1111111111";
            user.Address     = "TestAddress";
            user.DateOfBirth = DateTime.Parse("03-02-1999");
            user.Email       = "*****@*****.**";
            user.Gender      = 1;
            user.RoleId      = Convert.ToInt32(Roles.Assistant);
            Accounts account     = new Accounts();
            var      sessionInfo = account.SessionUserInfo(user);

            user.Id = sessionInfo.Id;
            AdminEdit admin = new AdminEdit();

            // Act
            var result = admin.UpdateAdmin(user);

            // Assert
            Assert.IsTrue(result);
        }
Beispiel #2
0
        public ActionResult EditProfile(AdminProfileEditViewModel model, string returnUrl)
        {
            if (Session["userId"] == null)
            {
                return(Redirect("~"));
            }
            Users user = new Users();

            AutoMapper.Mapper.Map(model, user);
            user.Id = (int)Session["userId"];
            if (string.IsNullOrEmpty(model.NewPassword))
            {
                user.Password = model.Password;
            }
            else
            {
                user.Password = model.NewPassword;
            }
            AdminEdit Admin = new AdminEdit();

            try
            {
                if (Admin.UpdateAdmin(user))
                {
                    return(RedirectToAction("Profile"));
                }
                else
                {
                    return(RedirectToAction("Profile/Edit"));
                }
            }
            catch (EmailAlreadyExistsEx ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (PhoneAlreadyExistsEx ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to update information");
                return(View(model));
            }
        }