public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var ticketPriority = await _context.TicketPriorities.FindAsync(request.Id); if (ticketPriority == null) { throw new RestException(HttpStatusCode.NotFound, new { ticketPriority = "Could not find" }); } _context.Remove(ticketPriority); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving the data"); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var role = await _context.Roles.FindAsync(request.Id); if (role == null) { throw new RestException(HttpStatusCode.NotFound, new { role = "Could not find" }); } if (role.IsStatic == true) { throw new RestException(HttpStatusCode.NotFound, new { role = "Could not delete a static role" }); } _context.Remove(role); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving the data"); }