public void Update(RegularUserDto updatedUser)
        {
            Guard.WhenArgument(updatedUser, "regularUserDto").IsNull().Throw();

            var user = this.usersRepo.GetById(updatedUser.Id);

            if (user != null)
            {
                user.FirstName   = updatedUser.FirstName;
                user.LastName    = updatedUser.LastName;
                user.Age         = updatedUser.Age;
                user.CurrentCar  = updatedUser.CurrentCar;
                user.FavoriteCar = updatedUser.FavoriteCar;

                this.usersRepo.Update(user);
            }
        }
示例#2
0
        public void NotCallRegularUserRepoUpdate_WhenUserIsNonExistent()
        {
            //Arrange
            var usersRepoMock = new Mock <IEfRepository <RegularUser> >();
            var userDto       = new RegularUserDto()
            {
                Id = Guid.NewGuid().ToString()
            };
            var         regularUserService = new Services.RegularUserService(usersRepoMock.Object);
            RegularUser nullUserFromRepo   = null;

            usersRepoMock.Setup(m => m.GetById(userDto.Id)).Returns(nullUserFromRepo);

            //Act
            regularUserService.Update(userDto);

            //Assert
            usersRepoMock.Verify(m => m.Update(nullUserFromRepo), Times.Never);
        }
示例#3
0
        public ActionResult Edit(ProfileEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            var updatedUser = new RegularUserDto()
            {
                Id          = this.User.Identity.GetUserId(),
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Age         = model.Age,
                CurrentCar  = model.CurrentCar,
                FavoriteCar = model.FavoriteCar
            };

            this.regularUserService.Update(updatedUser);

            return(this.RedirectToAction("Details", "Profile", new { id = this.User.Identity.GetUserId() }));
        }