public void DeletePassenger(Int64?passengerId, string mode)
        {
            var obj = SessionStore.GetTravelSession();

            TBO_Passengers objToUpdate = new TBO_Passengers();

            objToUpdate = entity.TBO_Passengers.Where(m => m.PassengerId == passengerId).FirstOrDefault();

            if (mode == "remove")
            {
                objToUpdate.IsDeleted = true;
            }
            else if (mode == "include")
            {
                objToUpdate.IsDeleted = false;
            }

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

            entity.ApplyCurrentValues(objToUpdate.EntityKey.EntitySetName, objToUpdate);
            entity.SaveChanges();
        }
Exemplo n.º 2
0
        //public bool IssueTicket(Int64 PNRId, int UserId)
        //{
        //    string GDSRefNo = ent.PNRs.Where(x => x.PNRId == PNRId).FirstOrDefault().GDSRefrenceNumber;
        //    Abacus.Ticketing.TicketIssueManager manager = new Abacus.Ticketing.TicketIssueManager();
        //    try
        //    {
        //        var retriveData = BookingManager.RetrievePNR(GDSRefNo);

        //        if (string.IsNullOrEmpty(retriveData.PassengerList.FirstOrDefault().TicketNumber))
        //        {
        //            retriveData = manager.IssueTicket(GDSRefNo, (decimal)0);
        //        }

        //        int TicketStatusId = ent.PNRs.Where(x => x.PNRId == PNRId).FirstOrDefault().TicketStatusId;

        //        if (TicketStatusId != 4)
        //        {
        //            var dbPassengerList = ent.Passengers.Where(x => x.PNRId == PNRId && x.isDeleted == false).ToArray();
        //            int paxCounter = 0;
        //            foreach (var item in retriveData.PassengerList)
        //            {
        //                Passengers pass = dbPassengerList.ElementAt(paxCounter);
        //                pass.TicketNumber = item.TicketNumber;

        //                ent.ApplyCurrentValues(pass.EntityKey.EntitySetName, pass);
        //                ent.SaveChanges();
        //                paxCounter++;
        //            }
        //            ent.Air_IssueTickets(PNRId, UserId);
        //        }
        //        return true;
        //    }
        //    catch (GDS.GDSException ex)
        //    {

        //        throw ex;
        //    }
        //    catch (Exception ex)
        //    {

        //        throw ex;
        //    }
        //}


        public bool IssueTicket(Int64 PNRId, int UserId)
        {
            var result = ent.PNRs.Where(x => x.PNRId == PNRId).FirstOrDefault();

            if (result != null)
            {
                string GDSRefNo = result.GDSRefrenceNumber;
                Abacus.Ticketing.TicketIssueManager manager = new Abacus.Ticketing.TicketIssueManager();
                try
                {
                    var retriveData = BookingManager.RetrievePNR(GDSRefNo, null);

                    if (string.IsNullOrEmpty(retriveData.PassengerList.FirstOrDefault().TicketNumber))
                    {
                        retriveData = manager.IssueTicket(GDSRefNo, (decimal)0);
                    }

                    int TicketStatusId = ent.PNRs.Where(x => x.PNRId == PNRId).FirstOrDefault().TicketStatusId;

                    if (TicketStatusId != 4)
                    {
                        var dbPassengerList = ent.Passengers.Where(x => x.PNRId == PNRId && x.isDeleted == false).ToArray();
                        int paxCounter      = 0;
                        foreach (var item in retriveData.PassengerList)
                        {
                            Passengers pass = dbPassengerList.ElementAt(paxCounter);
                            pass.TicketNumber = item.TicketNumber;

                            ent.ApplyCurrentValues(pass.EntityKey.EntitySetName, pass);
                            ent.SaveChanges();
                            paxCounter++;
                        }
                        ent.Air_IssueTickets(PNRId, UserId);
                    }
                    return(true);
                }
                catch (GDS.GDSException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                string GDSRefNo = ent.TBO_PNRs.Where(x => x.MPNRId == PNRId).FirstOrDefault().RecLoc;
                Abacus.Ticketing.TicketIssueManager manager = new Abacus.Ticketing.TicketIssueManager();
                try
                {
                    var retriveData = BookingManager.RetrievePNR(GDSRefNo, null);

                    if (string.IsNullOrEmpty(retriveData.PassengerList.FirstOrDefault().TicketNumber))
                    {
                        retriveData = manager.IssueTicket(GDSRefNo, (decimal)0);
                    }

                    int TicketStatusId = ent.TBO_MasterPNRs.Where(x => x.MPNRId == PNRId).FirstOrDefault().TicketStatusId;

                    if (TicketStatusId != 4 || TicketStatusId != 16 || TicketStatusId != 19)
                    {
                        var dbPassengerList = ent.TBO_Passengers.Where(x => x.MPNRId == PNRId && x.IsDeleted == false).ToArray();
                        int paxCounter      = 0;
                        foreach (var item in retriveData.PassengerList)
                        {
                            TBO_Passengers pass    = dbPassengerList.ElementAt(paxCounter);
                            TBO_PNRTickets tickets = pass.TBO_PNRTickets.FirstOrDefault();

                            tickets.TicketNumber = item.TicketNumber;

                            ent.ApplyCurrentValues(tickets.EntityKey.EntitySetName, tickets);
                            ent.SaveChanges();
                            paxCounter++;
                        }
                        ent.TBO_Air_IssueTickets(PNRId, UserId);
                    }
                    return(true);
                }
                catch (GDS.GDSException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        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);
            }
        }