Beispiel #1
0
        public void UpdatePnrs(IssueDomesticTicketsModel model)
        {
            var obj = SessionStore.GetTravelSession();

            foreach (var p in model.DomesticPnrsList)
            {
                TBO_PNRs objToUpdate = new TBO_PNRs();
                objToUpdate = entity.TBO_PNRs.Where(m => m.PNRId == p.PnrId).FirstOrDefault();

                objToUpdate.RecLoc = p.PNR;

                objToUpdate.UpdatedBy   = obj.AppUserId;
                objToUpdate.UpdatedDate = DateTime.UtcNow;

                entity.ApplyCurrentValues(objToUpdate.EntityKey.EntitySetName, objToUpdate);

                //if (p.ItinaryList != null)
                //    UpdateItinary(p.ItinaryList);

                if (p.PassengersList != null)
                {
                    UpdatePassengers(p.PassengersList);
                }
            }
        }
        public ServiceResponse Save(OfflineBookViewModel models)
        {
            try
            {
                int    confirmTicketstatus = 24;
                var    model     = models;
                long   masterpnr = 0;
                string bookingref;
                using (var ts = new TransactionScope(TransactionScopeOption.Required))
                {
                    ATLTravelPortal.Areas.Airline.Repository.GeneralProvider generalProvider = new GeneralProvider();
                    var  agent = generalProvider.GetAgents(model.UserDetail.AgentId);
                    bool isByPassDealByBranch      = generalProvider.GetBranchSettings(agent.BranchOfficeId, 12);
                    bool isByPassDealByDistrubutor = generalProvider.GetDistributorSettings(agent.DistributorId, 13);

                    System.Data.Objects.ObjectParameter BranchaDeal     = new System.Data.Objects.ObjectParameter("Amount", 0);
                    System.Data.Objects.ObjectParameter DistributorDeal = new System.Data.Objects.ObjectParameter("Amount", 0);

                    var    currency        = generalProvider.GetCurrencyByCode("NPR");
                    double totalFareAmount = models.PNRDetails[0].PassengerDetail[0].FareDetail.SellingBaseFare + models.PNRDetails[0].PassengerDetail[0].FareDetail.SellingFSC - models.PNRDetails[0].PassengerDetail[0].FareDetail.DiscountAmount;

                    var branchDealAmount = _entity.Air_GetBranchDeal
                                               (agent.DistributorId,
                                               model.PNRDetails[0].SegmentDetail.FirstOrDefault().AirlineId, model.PNRDetails[0].SegmentDetail.FirstOrDefault().DepartCityId,
                                               model.PNRDetails[0].SegmentDetail.FirstOrDefault().ArrivalCityId, false, totalFareAmount, currency.CurrencyId, model.PNRDetails[0].SegmentDetail.FirstOrDefault().BIC, BranchaDeal);


                    var distributorDealAmount = _entity.Air_GetBranchDeal
                                                    (agent.AgentId,
                                                    model.PNRDetails[0].SegmentDetail.FirstOrDefault().AirlineId, model.PNRDetails[0].SegmentDetail.FirstOrDefault().DepartCityId,
                                                    model.PNRDetails[0].SegmentDetail.FirstOrDefault().ArrivalCityId, false, totalFareAmount + (double)BranchaDeal.Value + branchDealAmount, currency.CurrencyId, model.PNRDetails[0].SegmentDetail.FirstOrDefault().BIC, DistributorDeal);



                    var mpnrDetail = new TBO_MasterPNRs
                    {
                        SessionId         = model.UserDetail.SessionId.ToString(),
                        AgentId           = model.UserDetail.AgentId,
                        ServiceProviderId = 5,
                        Prefix            = model.PNRDetails[0].PassengerDetail[0].Prefix.ToString(),
                        FirstName         = model.PNRDetails[0].PassengerDetail[0].FirstName.ToUpper(),
                        MiddleName        = model.PNRDetails[0].PassengerDetail[0].MiddleName,
                        LastName          = model.PNRDetails[0].PassengerDetail[0].LastName.ToUpper(),
                        TicketStatusId    = confirmTicketstatus,
                        Email             = "*****@*****.**",
                        Phone             = model.PNRDetails[0].PassengerDetail[0].Phone,
                        Address           = "104 Level 1 The Chamber, Mumbai",
                        CreatedBy         = model.UserDetail.AppUserId,
                        CreatedDate       = DateTime.UtcNow,
                        IssuedDate        = DateTime.UtcNow,
                        DispatchedDate    = null,
                        //  BookingReference = "AH" + RandomGenerator.GenerateRandomAlphanumeric()
                        isBranchByPassDeal      = isByPassDealByBranch,
                        isDistributorByPassDeal = isByPassDealByDistrubutor
                    };

                    _entity.AddToTBO_MasterPNRs(mpnrDetail);
                    _entity.SaveChanges();

                    mpnrDetail.BookingReference = "AH" + RandomGenerator.GenerateRandomAlphanumeric() + mpnrDetail.MPNRId;
                    _entity.ApplyCurrentValues(mpnrDetail.EntityKey.EntitySetName, mpnrDetail);
                    _entity.SaveChanges();


                    masterpnr  = mpnrDetail.MPNRId;
                    bookingref = mpnrDetail.BookingReference;

                    foreach (var pnrData in model.PNRDetails)
                    {
                        var pnrDetail = new TBO_PNRs
                        {
                            MPNRId         = mpnrDetail.MPNRId,
                            BookingId      = 0,
                            TicketStatusId = confirmTicketstatus,
                            RecLoc         = pnrData.PNR.ToUpper(),
                            // BookingSource = pnrData.BookingSource,
                        };

                        _entity.AddToTBO_PNRs(pnrDetail);
                        _entity.SaveChanges();

                        var sectorDetail = new TBO_PNRsectors
                        {
                            MPNRId            = mpnrDetail.MPNRId,
                            PNRId             = pnrDetail.PNRId,
                            PlatingCarrierId  = pnrData.SegmentDetail.FirstOrDefault().AirlineId,
                            DepartCityId      = pnrData.SegmentDetail.FirstOrDefault().DepartCityId,
                            DepartDate        = pnrData.SegmentDetail.FirstOrDefault().DepartDate.Value,
                            DepartTime        = pnrData.SegmentDetail.FirstOrDefault().DepartTime.Value,
                            DestinationCityId = pnrData.SegmentDetail.Last().ArrivalCityId,
                            ArriveDate        = pnrData.SegmentDetail.LastOrDefault().ArrivalDate.Value,
                            ArriveTime        = pnrData.SegmentDetail.FirstOrDefault().ArrivalTime.Value,
                            StartTerminal     = pnrData.SegmentDetail.FirstOrDefault().StartTerminal,
                            EndTerminal       = pnrData.SegmentDetail.LastOrDefault().EndTerminal,
                        };
                        _entity.AddToTBO_PNRsectors(sectorDetail);
                        _entity.SaveChanges();

                        foreach (var seg in pnrData.SegmentDetail)
                        {
                            var segmentDetail = new TBO_PNRsegments
                            {
                                MPNRId           = mpnrDetail.MPNRId,
                                PNRId            = pnrDetail.PNRId,
                                SectorId         = sectorDetail.SectorId,
                                AirlineId        = seg.AirlineId,
                                FlightNumber     = seg.FlightNumber,
                                DepartCityId     = seg.DepartCityId,
                                DepartDate       = seg.DepartDate.Value,
                                DepartTime       = seg.DepartTime.Value,
                                ArrivalCityId    = seg.ArrivalCityId,
                                ArrivalDate      = seg.ArrivalDate.Value,
                                ArrivalTime      = seg.ArrivalTime.Value,
                                BIC              = seg.BIC,
                                StartTerminal    = seg.StartTerminal,
                                EndTerminal      = seg.EndTerminal,
                                AirlineRefNumber = seg.AirlineRefNumber.ToUpper(),
                                VndRemarks       = seg.VndRemarks,
                                FlightDuration   =
                                    String.IsNullOrEmpty(seg.Duration)
                                        ? (seg.FlightDuration.Hours.ToString() + ":" +
                                           seg.FlightDuration.Minutes.ToString())
                                        : seg.Duration,
                                Baggage   = Baggage.No.ToString(),
                                FareBasis = null,
                                FlightKey = null,
                                NVB       = null,
                                NVA       = null
                            };

                            _entity.AddToTBO_PNRsegments(segmentDetail);
                            _entity.SaveChanges();
                        }

                        foreach (var paxData in pnrData.PassengerDetail)
                        {
                            var paxDetail = new TBO_Passengers();
                            paxDetail.PNRId      = pnrDetail.PNRId;
                            paxDetail.MPNRId     = mpnrDetail.MPNRId;
                            paxDetail.Prefix     = paxData.Prefix.ToString();
                            paxDetail.FirstName  = paxData.FirstName.ToUpper();
                            paxDetail.MiddleName = paxData.MiddleName;
                            paxDetail.LastName   = paxData.LastName.ToUpper();
                            paxDetail.Gender     = "N/A";
                            if (!string.IsNullOrEmpty(paxData.DOB.Trim()))
                            {
                                paxDetail.DOB = Convert.ToDateTime(paxData.DOB);
                            }
                            paxDetail.Nationality     = paxData.NationalityId;
                            paxDetail.Country         = paxData.PassportIssuedCountryId;
                            paxDetail.PassportNumber  = paxData.PassportNumber;
                            paxDetail.PassportExpDate = paxData.PassportExpDate;

                            paxDetail.Phone           = paxData.Phone;
                            paxDetail.Email           = "*****@*****.**";
                            paxDetail.PassengerTypeId = (int)paxData.PaxType;
                            paxDetail.FFAirline       = paxData.FrequentFlyerAirlineCode != null ? (int?)_entity.Airlines.Where(
                                x => x.AirlineCode == paxData.FrequentFlyerAirlineCode).
                                                        Select(y => y.AirlineId).FirstOrDefault()
                                    : null;
                            paxDetail.FFNumber       = paxData.FrequentFlyerNo != "" ? paxData.FrequentFlyerNo : null;
                            paxDetail.DOCA           = "2nd Floor, Buddha Complex, Swayambhu, Kathmandu, Nepal";
                            paxDetail.SSR            = paxData.Meal != null ? paxData.Meal.Code : null;
                            paxDetail.SSRDescription =
                                paxData.Meal != null
                                    ? paxData.Meal.Description = paxData.Meal.Code
                                    : null;
                            paxDetail.SeatName        = paxData.Seat != null ? paxData.Seat.Code : null;
                            paxDetail.SeatDescription =
                                paxData.Seat != null ? paxData.Seat.Description : null;
                            paxDetail.UpdatedBy   = 1;
                            paxDetail.UpdatedDate = DateTime.UtcNow;

                            _entity.AddToTBO_Passengers(paxDetail);
                            _entity.SaveChanges();

                            var fareDetail = new TBO_PNRTickets
                            {
                                PNRId            = pnrDetail.PNRId,
                                MPNRId           = mpnrDetail.MPNRId,
                                PassengerId      = paxDetail.PassengerId,
                                TicketNumber     = paxData.FareDetail.TicketNumber.ToUpper(),
                                AdditionalTxnFee = paxData.FareDetail.SellingAdditionalTxnFee,
                                AirlineTransFee  = paxData.FareDetail.AirlineTransFee,
                                BaseFare         = paxData.FareDetail.SellingBaseFare,
                                Tax               = paxData.FareDetail.SellingTax,
                                OtherCharges      = paxData.FareDetail.SellingOtherCharges,
                                ServiceTax        = paxData.FareDetail.SellingServiceTax,
                                MarkupAmount      = paxData.FareDetail.MarkupAmount,
                                CommissionAmount  = 0,
                                DiscountAmount    = paxData.FareDetail.CommissionAmount,
                                Currency          = "NPR",
                                FSC               = paxData.FareDetail.SellingFSC,
                                TicketStatusId    = confirmTicketstatus,
                                TktId             = paxData.FareDetail.TicketId,
                                TourCode          = paxData.FareDetail.TourCode,
                                ValidatingAirline = paxData.FareDetail.ValidatingAirline,
                                Remarks           = paxData.FareDetail.Remarks,
                                CorporateCode     = paxData.FareDetail.CorporateCode,
                                EndorseMent       = paxData.FareDetail.Endorsement,
                                //value with Rounding
                                SellingAdditionalTxnFee =
                                    Math.Ceiling(paxData.FareDetail.SellingAdditionalTxnFee),
                                SellingAirlineTransFee =
                                    Math.Ceiling(paxData.FareDetail.SellingAirlineTransFee),
                                SellingBaseFare     = Math.Ceiling(paxData.FareDetail.SellingBaseFare),
                                SellingTax          = Math.Ceiling(paxData.FareDetail.SellingTax),
                                SellingOtherCharges =
                                    Math.Ceiling(paxData.FareDetail.SellingOtherCharges),
                                SellingServiceTax =
                                    Math.Ceiling(paxData.FareDetail.SellingServiceTax),
                                SellingFSC            = Math.Ceiling(paxData.FareDetail.SellingFSC),
                                BranchDealAmount      = (double)BranchaDeal.Value,
                                DistrubutorDealAmount = (double)DistributorDeal.Value
                            };

                            _entity.AddToTBO_PNRTickets(fareDetail);
                            _entity.SaveChanges();
                        }
                    }

                    ts.Complete();
                }
                IssueTicket(masterpnr, model.UserDetail.AppUserId);

                _entity.SaveChanges();
                _entity.Air_UpdateTicketStatusId(masterpnr, "ISSUEPNR", false, model.UserDetail.AppUserId);

                _response = new ServiceResponse("Record successfully created!! \n Your Booking Reference No is :" + bookingref, MessageType.Success, true, "Save");


                return(_response);
            }
            catch (Exception ex)
            {
                _response = new ServiceResponse(ex.Message, MessageType.Exception, false, "Save");
                return(_response);
            }
        }