Example #1
0
        public async Task <IHttpActionResult> PutParent(string id, ParentDTOInUp userModel)
        {
            string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;

            if (!id.Equals(userModel.Id))
            {
                logger.Info("Id does not match, put parent, account controller");
                return(BadRequest("Id not match"));
            }

            logger.Info($"Admin {userId} {userModel.UserName} sent to user service, put parent");
            var updatedParent = await service.UpdateParent(id, userModel);

            if (updatedParent == null)
            {
                logger.Info($"User {userModel.UserName} has not been updated. Update failed, put parent.");
                return(NotFound());
            }

            return(Ok(updatedParent));
        }
Example #2
0
        public async Task <ParentDTOOut> UpdateParent(string id, ParentDTOInUp parentInUp)
        {
            logger.Info($"Converting parent {parentInUp.UserName} with simple dto converter, user service update parent");
            Parent parent = Utilities.ConverterDTO.SimpleDTOConverter <Parent>(parentInUp);

            logger.Info($"getting user with id {parentInUp.Id}, with db.authreposito, update parent, user service ");
            AppUser user = await db.AuthRepository.FindUserById(id);

            if (user == null)
            {
                logger.Info("Throwing an user not found exception, no user found update parent, user service");
                throw new UserNotFoundException($"User with ID {id} does not exists.");
            }

            logger.Info($"Updating user {parentInUp.UserName}");
            user.FirstName = parentInUp.FirstName;
            user.LastName  = parentInUp.LastName;
            user.Email     = parentInUp.Email;
            user.UserName  = parentInUp.UserName;

            logger.Info("waiting for result from auth repository, update user, user service");
            var result = await db.AuthRepository.UpdateUser(user);

            if (!result.Succeeded)
            {
                logger.Info("Update has failed, result not succeeded, user service");
                return(null);
            }

            logger.Info("Getting updated user with auth repository");
            var userUpdated = await db.AuthRepository.FindUserById(parentInUp.Id);

            logger.Info("Convertin user to parent dto");
            ParentDTOOut parentDTO = Utilities.ConverterDTO.SimpleDTOConverter <ParentDTOOut>(userUpdated);

            return(parentDTO);
        }