Beispiel #1
0
        public async ValueTask <IActionResult> Put([FromBody] UserBase model)
        {
            if (ModelState.IsValid)
            {
                var user = await _repo.Item().Where(u => model.Id == u.Id).FirstOrDefaultAsync();

                if (user != null)
                {
                    ApplicationUser userMappedFromModel = model.Convert <UserBase, ApplicationUser>(_mapper);
                    userMappedFromModel.PasswordHash   = user.PasswordHash;
                    userMappedFromModel.IsSet          = user.IsSet;
                    userMappedFromModel.Code           = user.Code;
                    userMappedFromModel.CodeIssued     = user.CodeIssued;
                    userMappedFromModel.CodeWillExpire = user.CodeWillExpire;
                    (bool succeeded, ApplicationUser updatedUser, string error) = await _repo.Update(userMappedFromModel, userMappedFromModel.Id);

                    if (succeeded)
                    {
                        return(Ok(updatedUser.Convert(_mapper)));
                    }
                    return(BadRequest(new ErrorDTO {
                        Message = error
                    }));
                }
            }
            return(BadRequest(new ErrorDTO {
                Errors = ModelState.Values.SelectMany(e => e.Errors).ToList()
            }));
        }