Exemple #1
0
        public async Task <IActionResult> EditUserAsync(int userId, UserForEditDTO userForEditDTO)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userForEdit = await _unitOfWork.Users.FindOneAsync(u => u.UserId == userId);

            var userToEqual = _mapper.Map <UserModel>(userForEditDTO);

            if (userForEdit == null)
            {
                return(BadRequest("Error: The user cannot be found!"));
            }

            var editedUser = _mapper.Map(userForEditDTO, userForEdit);

            if (userForEdit == userToEqual)
            {
                return(StatusCode(304));
            }

            if (await _unitOfWork.SaveAllAsync())
            {
                return(Ok("Info: The user has been updated."));
            }

            throw new Exception("Error: Saving edited user to database failed!");
        }
        public async Task <IActionResult> Put(UserForEditDTO model)
        {
            User user    = mapper.Map <User>(model);
            User oldUser = await userRepository.Get(model.Id).ConfigureAwait(true);

            user.PasswordHash = oldUser.PasswordHash;
            user.PasswordSalt = oldUser.PasswordSalt;
            userRepository.Edit(user);
            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <UserForGetDTO>(await userRepository.Get(user.Id).ConfigureAwait(true))));
        }
Exemple #3
0
        public async Task <IActionResult> UpdateUser(int id, UserForEditDTO userForEditDTO)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(userForEditDTO, userFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Updating Failed");
        }
        public async Task <IActionResult> UpdateUser(int id, UserForEditDTO userToEdit)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userfromRepo = await _repository.GetUser(id);

            _mapper.Map(userToEdit, userfromRepo);

            if (await _repository.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating user with {id} failed on save");
        }
Exemple #5
0
        public async Task <IActionResult> UpdateUser(int id, UserForEditDTO user)
        {
            var result = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (id != int.Parse(result))
            {
                return(Unauthorized());
            }

            var userEntity = await datingRepository.GetUser(id);

            mapper.Map(user, userEntity);

            if (await datingRepository.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating user with id {id} failed on save.");
        }