public async Task <ActionResult <Response <QueryCustomerModel> > > PutCustomer(int id, CommandCustomerModel customer) { try { var command = new UpdateCommand <CommandCustomerModel>() { Id = id, Data = customer }; bool result = await _customerCommandHandler.HandleAsync(command); if (!result) { return(NotFound(new { message = "Customer not found" })); } var response = new Response <QueryCustomerModel>(); response.Success = result; return(response); } catch (Exception ex) { // log ex as exception return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <QuerySingleResponse <QueryCustomerModel> > > CustomerTicket(CommandCustomerTicketModel customerTickets) { var command = new InsertCommand <CommandCustomerModel>() { Data = customerTickets }; var data = await _customerCommandHandler.HandleAsync(command); if (data.CustomerId > 0) { customerTickets.Tickets.ForEach(f => { f.CustomerId = data.CustomerId; var ticketCommand = new InsertCommand <CommandTicketModel>() { Data = f }; var ticketData = _ticketCommandHandler.HandleAsync(ticketCommand).Result; }); } var response = new QuerySingleResponse <QueryCustomerModel>(); response.Success = true; response.Data = data; return(StatusCode(StatusCodes.Status201Created, response)); }