public ActionResult <string> UpdateAccount(Guid id, EditAccountDto editAccount)
        {
            var account = _context.Accounts.Find(id);

            if (account == null)
            {
                return(NotFound("No account find with this id"));
            }

            // The method below could also be achieved by ignoring NULL values in the DTO
            if (editAccount.Name != null)
            {
                account.Name = editAccount?.Name;
            }

            if (editAccount.Iban != null)
            {
                account.Iban = editAccount?.Iban;
            }

            if (editAccount.FavoriteQuote != null)
            {
                account.FavoriteQuote = editAccount?.FavoriteQuote;
            }

            _context.SaveChanges();
            return(Ok(account));
        }
        public EditAccountDto Update(EditAccountDto editAccountDto)
        {
            Account account = mapper.Map <Account>(editAccountDto);

            repository.UpdateEntity(account);
            repository.Save();
            return(editAccountDto);
        }
        public void Update()
        {
            // Arrange
            var            mock = new Mock <IAccountService>();
            EditAccountDto user = new EditAccountDto();

            user.Email    = "testemail";
            user.Name     = "testUser";
            user.Password = "******";
            mock.Setup(AccountService => AccountService.Update(user)).Returns(user);

            // Act
            EditAccountDto result = mock.Object.Update(user);

            // Assert
            Assert.AreEqual(user, result);
        }
示例#4
0
        public void Edit([FromBody] EditAccountDto model)
        {
            var appUser = _userManager.Users.SingleOrDefault(user => user.Email == model.Email);

            if (appUser == null)
            {
                throw new ApplicationException(ExceptionMessages.UserDoesNotExists);
            }

            var resultPassword = _signInManager.CheckPasswordSignInAsync(appUser, model.OldPassword, false).Result;

            if (!resultPassword.Succeeded)
            {
                throw new ApplicationException(ExceptionMessages.InternalServerError);
            }

            var resultChangePassword = _userManager.ChangePasswordAsync(appUser, model.OldPassword, model.NewPassword).Result;

            if (!resultChangePassword.Succeeded)
            {
                throw new ApplicationException(ExceptionMessages.InternalServerError);
            }
        }