Esempio n. 1
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdatedDto userForUpdatedDto)
        {
            //checks if the id equals to the token id
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(userForUpdatedDto, userFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception("$Updating user {id} failed on save ");
        }
Esempio n. 2
0
        public async Task <IActionResult> GetUser(int id, UserForUpdatedDto userForUpdatedDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userfromrepo = await _repo.GetUser(id);

            _mapper.Map(userForUpdatedDto, userfromrepo);

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

            throw new Exception($"Updating User {id} failed on save");
        }
Esempio n. 3
0
        public async Task <IActionResult> updateUser(UserForUpdatedDto userForUpdatedDto, string name)
        {
            var user = await _repo.GetUser(name.ToLower());

            if (user.UserName.ToString() != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized());
            }
            _mapper.Map(userForUpdatedDto, user);

            /*
             *  Configure it in angular with preload resolvers
             */
            if (await _repo.SaveAll())
            {
                return(Ok(user));
            }
            return(BadRequest("Problem with updating user"));
        }