public CommandResult <List <long> > Handle(DeleteUsersCommand command) { var result = new CommandResult <List <long> >(); try { var toRemove = ctx.Users.Where(u => command.UserIds.Contains(u.Id)); var idsToRemove = toRemove.Select(u => u.Id).ToList(); var userIdsNotFound = command.UserIds.Except(idsToRemove).ToList(); if (userIdsNotFound.Any()) { var stringIds = string.Join(", ", userIdsNotFound); logger.LogWarning($"Entries not found for [{userIdsNotFound.Count}] Users. Ids: [{stringIds}]"); result.Success = false; return(result); } ctx.Users.RemoveRange(toRemove); ctx.SaveChanges(); result.Success = true; result.Response = idsToRemove; } catch (Exception e) { logger.LogWarning(e.Message); } return(result); }
public IActionResult DeleteUsers([FromQuery] IList <long> userIds) { var cmd = new DeleteUsersCommand(userIds); var response = commandProcessor.Process(cmd); if (!response.Success) { return(BadRequest()); //TODO: Not accurate } return(Ok(response.Response)); }