예제 #1
0
        private IReceipt SubmitReceipt(SubmitReceipt request)
        {
            //Check ticket is available
            var ticket = TicketRepo.GetTicket(request.TicketId);

            if (ticket == null)
            {
//                throw new Exception(TicketMessage.TicketDoesNotFound);
            }

            if (ticket.Status.Equals((int)TicketConstant.Lock))
            {
//                throw new Exception(TicketMessage.TicketIsNotAvail);
            }

            //Check departure date
            if (!DateTime.TryParseExact(request.DepartureDate, "dd-MM-yyyy", CultureInfo.InvariantCulture,
                                        DateTimeStyles.None, out var departureDate))
            {
//                throw new Exception(TicketMessage.InvalidDepartureDate);
            }

            //Check ticket does not booking before
            var status =
                TicketStatusRepo.GetTicketStatus(ticket.UserAuthId, ticket.Code, departureDate, ticket.DepartureTime);

            if (status.Status != (int)TicketStatusConstant.Available)
            {
//                throw new Exception(TicketMessage.TicketIsNotAvail);
            }

            //Create new receipt
            var newReceipt = new Receipt.Repository.OrmLite.Receipt();

            newReceipt.PopulateWith(ticket);
            newReceipt.AgentId       = Convert.ToInt32(base.UserSession.UserAuthId);
            newReceipt.DepartureDate = departureDate;
            newReceipt.Note          = request.Note;
            newReceipt.Status        = (int)ReceiptStatusConstant.Submited;

            //Generate new code
            var code = ReceiptRepo.GenerateNewCode(ConfigUtils.GetAppSetting("receipt.code.len", 6));

            newReceipt.Code = code;

            //Create new receipt
            var receipt = ReceiptRepo.CreateReceipt(newReceipt);

            //Update ticket status
            var newStatus = TicketStatusRepo.UpdateTicketStatus(ticket.UserAuthId, ticket.Code, departureDate,
                                                                ticket.DepartureTime, (int)TicketStatusConstant.Booked);

            return(receipt);
        }
예제 #2
0
        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);
        }