public async Task <bool> UpdatTicketAsync(int id, CommandTicketModel ticket) { var ticketEntity = await _context.Ticket.FindAsync(id); if (ticketEntity != null) { ticketEntity.IssueStartedOn = ticket.IssueStartedOn; ticketEntity.Status = ticket.Status; ticketEntity.Subject = ticket.Subject; ticketEntity.Category = ticket.Category; ticketEntity.CustomerId = ticket.CustomerId; ticketEntity.Description = ticket.Description; _context.Entry(ticketEntity).State = EntityState.Modified; } else { throw new Exception("Ticket does not exists."); } try { await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { throw new Exception("Something went wrong, please contact system administrator."); } }
public ActionResult UpdateTicket(int id, CommandTicketModel ticket) { if (ModelState.IsValid) { _restService.SendAsync <CommandTicketModel>($"api/Ticket/{id}", HttpMethod.Put, ticket); return(RedirectToAction("Index", "Ticket", new { customerId = ticket.CustomerId })); } return(View(ticket)); }
public async Task <QueryTicketModel> InsertTicketAsync(CommandTicketModel ticket) { try { var ticketEntity = ticket.TO <Ticket>(); ticketEntity.CreatedOn = DateTime.Now; _context.Ticket.Add(ticketEntity); await _context.SaveChangesAsync(); return(ticketEntity.TO <QueryTicketModel>()); } catch (Exception ex) { throw new Exception("Something went wrong, please contact system administrator."); } }
public async Task <ActionResult <QuerySingleResponse <QueryTicketModel> > > PostTicket(CommandTicketModel ticket) { var command = new InsertCommand <CommandTicketModel>() { Data = ticket }; var data = await _ticketCommandHandler.HandleAsync(command); var response = new QuerySingleResponse <QueryTicketModel>(); response.Data = data; response.Success = true; return(CreatedAtAction("GetTicket", new { id = data.TicketId }, response)); }
public async Task <ActionResult <Response <QueryTicketModel> > > PutTicket(int id, CommandTicketModel ticket) { try { var command = new UpdateCommand <CommandTicketModel>() { Id = id, Data = ticket }; bool result = await _ticketCommandHandler.HandleAsync(command); if (!result) { return(NotFound(new { message = "Ticket not found" })); } var response = new Response <QueryTicketModel>(); response.Success = result; return(response); } catch (Exception ex) { // log ex as exception return(StatusCode(StatusCodes.Status500InternalServerError)); } }