Пример #1
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdateDTO userForUpdateDTO)
        {
            //
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _dateRepository.GetUser(id);

            _mapper.Map(userForUpdateDTO, userFromRepo);

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

            throw new Exception($"Error while updating user with id: {id}");
        }
Пример #2
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdate userforupdate)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(id);

            _mapper.Map(userforupdate, user);
            //   var userToReturn = _mapper.Map<UserForDetaildDTO>(user);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            else
            {
                throw new Exception($"faild to update ");
            }
        }