public IActionResult Put(int id, [FromBody] ChangeApplicationUserDto dto , [FromServices] IChangeApplicationUserCommand command , [FromServices] ChangeApplicationUserValidator validator) { dto.Id = id; var result = validator.Validate(dto); if (result.IsValid) { ApplicationUser applicationUser = _mapper.Map <ApplicationUser>(dto); _useCaseExecutor.ExecuteCommand(command, dto); return(Ok("Application user updated successfully")); } return(UnprocessableEntity(UnprocessableEntityResponse.Message(result.Errors))); }
public void Execute(ChangeApplicationUserDto request) { ApplicationUser item = context.ApplicaitonUsers.Find(request.Id); if (request.FirstName != null) { item.FirstName = request.FirstName; } if (request.LastName != null) { item.LastName = request.LastName; } if (request.Email != null) { item.Email = request.Email; } context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Detached; if (request.Password != null) { HashSalt hashSalt = Password.GenerateSaltedHash(64, request.Password); item.Password = hashSalt.Hash; item.Salt = hashSalt.Salt; } item.UpdatedAt = DateTime.Now; var tp = context.ApplicaitonUsers.Attach(item); tp.State = Microsoft.EntityFrameworkCore.EntityState.Modified; context.SaveChanges(); }