private IReceipt CancelReceipt(CancelReceipt request) { //Check receipt is available var existingReceipt = receiptRepo.GetReceipt(request.Code); if (existingReceipt == null) { throw new Exception(ReceiptMessage.ReceiptDoesNotExist); } //Check ticket is available var ticket = ticketRepo.GetTicket(existingReceipt.TicketId); if (ticket == null) { throw new Exception(TicketMessage.TicketDoesNotFound); } //Check ticket does not sold before var status = ticketStatusRepo.GetTicketStatus(ticket.UserAuthId, ticket.Code, existingReceipt.DepartureDate, ticket.DepartureTime); if (status.Status.Equals((int)TicketStatusConstant.Sold)) { throw new Exception(TicketMessage.TickerIsSold); } //Update receipt var newReceipt = receiptRepo.UpdateReceipt(existingReceipt, ToCancelReceipt(existingReceipt, request)); //Update ticket status var newStatus = ticketStatusRepo.UpdateTicketStatus(ticket.UserAuthId, ticket.Code, newReceipt.DepartureDate, ticket.DepartureTime, (int)TicketStatusConstant.Available); return(newReceipt); }
private static IReceipt ToCancelReceipt(IReceipt existingReceipt, CancelReceipt request) { var receipt = ((Receipt.Repository.OrmLite.Receipt)existingReceipt).CreateCopy(); receipt.Status = (int)ReceiptStatusConstant.Cancelled; receipt.Note = request.Note; return(receipt); }
public object Post(CancelReceipt request) { //Create new receipt var receipt = CancelReceipt(request); return(new CancelReceiptResponse() { Status = (int)CommonStatus.Success, Data = receipt.ConvertTo <Receipt.ServiceModel.Types.Receipt>() }); }