public BusinessHandlerResponse <TicketsIssued> UpdateTicket(TicketsIssued ticket) { try { var ticketFromDb = db.TicketsIssueds.FirstOrDefault(a => a.TicketId == ticket.TicketId); if (ticketFromDb != null) { if (ticketFromDb.AgentCode != ticket.AgentCode) { ticketFromDb.AgentCode = ticket.AgentCode; } if (ticketFromDb.Category != ticket.Category) { ticketFromDb.Category = ticket.Category; } if (ticketFromDb.TicketStatusCode != ticket.TicketStatusCode) { ticketFromDb.TicketStatusCode = ticket.TicketStatusCode; } if (ticketFromDb.Zone != ticket.Zone) { ticketFromDb.Zone = ticket.Zone; } if (ticketFromDb.Notes != ticket.Notes) { ticketFromDb.Notes = (string.IsNullOrWhiteSpace(ticket.Notes)) ? ticket.Notes : ticket.Notes.Trim(); } if (ticketFromDb.SoldTo != ticket.SoldTo) { ticketFromDb.SoldTo = (string.IsNullOrWhiteSpace(ticket.SoldTo)) ? ticket.SoldTo : ticket.SoldTo.Trim(); } if (ticketFromDb.TicketNumber != ticket.TicketNumber) { ticketFromDb.TicketNumber = ticket.TicketNumber; } ticketFromDb.Paid = ticket.Paid; } else { throw new Exception("Unknown Ticket " + ticket.TicketNumber); } db.SaveChanges(); return(new BusinessHandlerResponse <TicketsIssued>() { IsASuccess = true }); } catch (Exception ex) { logger.logMessage(ex.Message, LogLevel.error); return(new BusinessHandlerResponse <TicketsIssued>() { IsASuccess = false, Errors = new List <string> { "Failed due to an unknown error please check the logs" } }); } }
public ScannedStatus ConfirmArrival(ScannedTicket scannedTicket, bool forceUpdate = false) { logger.logMessage("Request to mak ticket " + scannedTicket.TicketNumber, LogLevel.debug); var ticketScanned = db.TicketsIssueds.FirstOrDefault(a => a.TicketNumber == scannedTicket.TicketNumber); var ticketScannedOutcome = new ScannedStatus(); if (ticketScanned == null) { return(new ScannedStatus { StatusOfScan = TicketScannedStatus.TicketDoesNotExist }); } else { ticketScannedOutcome.TableNumber = ticketScanned.TableNumber; ticketScannedOutcome.TicketNumber = ticketScanned.TicketNumber; ticketScannedOutcome.TicketId = ticketScanned.TicketId; if (ticketScanned.ArrivedAt != null) { ticketScannedOutcome.StatusOfScan = TicketScannedStatus.TicketAlreadyScanned; ticketScannedOutcome.TicketScannedMessage = string.Format("Ticket was scanned at {0} and was sold by {1} to {2}", ticketScanned.ArrivedAt, ticketScanned.Agent.AgentName, ticketScanned.SoldTo); } else { ticketScanned.ArrivalConfirmedBy = scannedTicket.ScannedBy; ticketScanned.ArrivedAt = DateTime.Now; ticketScannedOutcome.StatusOfScan = TicketScannedStatus.Ok; ticketScannedOutcome.Zone = ticketScanned.Zone; ticketScannedOutcome.TicketNotPaid = ticketScanned.TicketStatusCode != Constants.TicketStatus.Paid && ticketScanned.TicketStatusCode != Constants.TicketStatus.PaidNoCharge; if (ticketScannedOutcome.TicketNotPaid) { if (forceUpdate) { db.SaveChanges(); } } else { db.SaveChanges(); } } } return(ticketScannedOutcome); }