public async Task <ActionResult> Delete([FromBody] ManageServerRequest request) { if (!ModelState.IsValid) { // re-render the view when validation failed. return(BadRequest(ModelState)); } await _manageServerUseCase.Handle(new ManageServerRequest(request.CustomerId, request.ServerIds, request.Action), _serverPresenter); return(_serverPresenter.ContentResult); }
public async Task <ManageServerCustomerResponse> AddServerOwner(ManageServerRequest request) { foreach (var serverId in request.ServerIds) { await _context.CustomerServer.AddAsync(new CustomerServer(request.CustomerId, serverId)); } var success = await _context.SaveChangesAsync(); return(new ManageServerCustomerResponse(success > 0, null)); }
public async Task <ManageServerCustomerResponse> RemoveServerOwner(ManageServerRequest request) { foreach (var serverId in request.ServerIds) { var deletedCustomerServer = await _context.CustomerServer.FindAsync(request.CustomerId, serverId); _context.CustomerServer.Remove(deletedCustomerServer); //await _context.CustomerServer.Remove(new CustomerServer(request.CustomerId, serverId)); } var success = await _context.SaveChangesAsync(); return(new ManageServerCustomerResponse(success > 0, null)); }
public async Task <bool> Handle(ManageServerRequest message, IOutputPort <ManageServerResponse> outputPort) { ManageServerCustomerResponse response; if (message.Action) { response = await _customerRepository.AddServerOwner(message); } else { response = await _customerRepository.RemoveServerOwner(message); } outputPort.Handle(response.Success ? new ManageServerResponse(true) : new ManageServerResponse(response.Errors.Select(e => e.Description))); return(response.Success); }