//Export Items to CSV
        public byte[] Export(int id)
        {
            StringBuilder sb = new StringBuilder();

            //Add Headers
            List <string> headers = new List <string>();

            headers.Add("Policy Group Name");
            headers.Add("Deal Code Value");
            headers.Add("Deal Code Description");
            headers.Add("Deal Code Type Description");
            headers.Add("Location Name");
            headers.Add("Location Code");
            headers.Add("GDS Name ");
            headers.Add("Product Name");
            headers.Add("Supplier Name");
            headers.Add("Supplier Code");
            headers.Add("Travel Indicator Description");
            headers.Add("Travel Indicator");
            headers.Add("Endorsement");
            headers.Add("Endorsement Override");
            headers.Add("OSI 1");
            headers.Add("Enabled Flag");
            headers.Add("Enabled Date");
            headers.Add("Expiry Date");
            headers.Add("Creation TimeStamp");
            headers.Add("Last Update Time Stamp");

            sb.AppendLine(String.Join(",", headers.Select(x => x.ToString()).ToArray()));

            //Add Items
            List <PolicySupplierDealCode> policySupplierDealCodes = db.PolicySupplierDealCodes.Where(x => x.PolicyGroupId == id).ToList();

            foreach (PolicySupplierDealCode item in policySupplierDealCodes)
            {
                //Edit Item
                EditItemForDisplay(item);

                //Location
                PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository();
                PolicyLocation           policyLocation           = new PolicyLocation();
                policyLocation = policyLocationRepository.GetPolicyLocation(Int32.Parse(item.PolicyLocationId.ToString()));
                if (policyLocation != null)
                {
                    policyLocationRepository.EditForDisplay(policyLocation);
                }

                //TravelIndicator
                TravelIndicatorRepository travelIndicatorRepository = new TravelIndicatorRepository();
                TravelIndicator           travelIndicator           = new TravelIndicator();
                if (item.TravelIndicator != null)
                {
                    travelIndicator = travelIndicatorRepository.GetTravelIndicator(item.TravelIndicator);
                }

                //PolicySupplierDealCodeOSI
                PolicySupplierDealCodeOSI policySupplierDealCodeOSI = null;
                if (item.PolicySupplierDealCodeOSIs != null)
                {
                    policySupplierDealCodeOSI = item.PolicySupplierDealCodeOSIs.FirstOrDefault();
                }

                string date_format = "MM/dd/yy HH:mm";

                sb.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19}",
                                !string.IsNullOrEmpty(item.PolicyGroupName) ? item.PolicyGroupName : "",
                                !string.IsNullOrEmpty(item.PolicySupplierDealCodeValue) ? item.PolicySupplierDealCodeValue : "",
                                !string.IsNullOrEmpty(item.PolicySupplierDealCodeDescription) ? item.PolicySupplierDealCodeDescription : "",
                                !string.IsNullOrEmpty(item.PolicySupplierDealCodeTypeDescription) ? item.PolicySupplierDealCodeTypeDescription : "",

                                !string.IsNullOrEmpty(policyLocation.LocationName) ? policyLocation.LocationName : "",
                                !string.IsNullOrEmpty(policyLocation.LocationCode) ? policyLocation.LocationCode : "",

                                !string.IsNullOrEmpty(item.GDSName) ? item.GDSName : "",

                                !string.IsNullOrEmpty(item.ProductName) ? item.ProductName : "",
                                !string.IsNullOrEmpty(item.SupplierName) ? item.SupplierName : "",
                                !string.IsNullOrEmpty(item.SupplierCode) ? item.SupplierCode : "",

                                //Valid when Deal Code Type = Tour Code
                                travelIndicator != null && !string.IsNullOrEmpty(travelIndicator.TravelIndicatorDescription) ? travelIndicator.TravelIndicatorDescription : "",
                                item.TravelIndicator != null && !string.IsNullOrEmpty(item.TravelIndicator) ? item.TravelIndicator : "",
                                item.Endorsement != null && !string.IsNullOrEmpty(item.Endorsement) ? item.Endorsement : "",
                                item.EndorsementOverride != null && !string.IsNullOrEmpty(item.EndorsementOverride) ? item.EndorsementOverride : "",

                                policySupplierDealCodeOSI != null ? policySupplierDealCodeOSI.PolicySupplierDealCodeOSIDescription : "",
                                item.EnabledFlag == true ? "True" : "False",
                                item.EnabledDate.HasValue ? item.EnabledDate.Value.ToString(date_format) : "",
                                item.ExpiryDate.HasValue ? item.ExpiryDate.Value.ToString(date_format) : "",
                                item.CreationTimestamp.HasValue ? item.CreationTimestamp.Value.ToString(date_format) : "",
                                item.LastUpdateTimestamp.HasValue ? item.LastUpdateTimestamp.Value.ToString(date_format) : ""
                                );

                sb.Append(Environment.NewLine);
            }

            return(Encoding.ASCII.GetBytes(sb.ToString()));
        }
Пример #2
0
        public void EditForDisplay(TransactionFeeCarHotel transactionFee)
        {
            TravelIndicatorRepository travelIndicatorRepository = new TravelIndicatorRepository();
            TravelIndicator           travelIndicator           = new TravelIndicator();

            travelIndicator = travelIndicatorRepository.GetTravelIndicator(transactionFee.TravelIndicator);
            if (travelIndicator != null)
            {
                transactionFee.TravelIndicatorDescription = travelIndicator.TravelIndicatorDescription;
            }

            CurrencyRepository currencyRepository = new CurrencyRepository();
            Currency           currency           = new Currency();

            currency = currencyRepository.GetCurrency(transactionFee.FeeCurrencyCode);
            if (currency != null)
            {
                transactionFee.FeeCurrencyName = currency.Name;
            }
            currency = currencyRepository.GetCurrency(transactionFee.TicketPriceCurrencyCode);
            if (currency != null)
            {
                transactionFee.TicketPriceCurrencyName = currency.Name;
            }


            BookingSourceRepository bookingSourceRepository = new BookingSourceRepository();
            BookingSource           bookingSource           = new BookingSource();

            bookingSource = bookingSourceRepository.GetBookingSource(transactionFee.BookingSourceCode);
            if (bookingSource != null)
            {
                transactionFee.BookingSourceDescription = bookingSource.BookingSourceDescription;
            }

            BookingOriginationRepository bookingOriginationRepository = new BookingOriginationRepository();
            BookingOrigination           bookingOrigination           = new BookingOrigination();

            bookingOrigination = bookingOriginationRepository.GetBookingOrigination(transactionFee.BookingOriginationCode);
            if (bookingOrigination != null)
            {
                transactionFee.BookingOriginationCode = bookingOrigination.BookingOriginationCode;
            }

            ChargeTypeRepository chargeTypeRepository = new ChargeTypeRepository();
            ChargeType           chargeType           = new ChargeType();

            chargeType = chargeTypeRepository.GetChargeType(transactionFee.ChargeTypeCode);
            if (bookingOrigination != null)
            {
                transactionFee.ChargeTypeDescription = chargeType.ChargeTypeDescription;
            }

            TravelerBackOfficeTypeRepository travelerBackOfficeTypeRepository = new TravelerBackOfficeTypeRepository();
            TravelerBackOfficeType           travelerBackOfficeType           = new TravelerBackOfficeType();

            travelerBackOfficeType = travelerBackOfficeTypeRepository.GetTravelerBackOfficeType(transactionFee.TravelerClassCode);
            if (travelerBackOfficeType != null)
            {
                transactionFee.TravelerBackOfficeTypeDescription = travelerBackOfficeType.TravelerBackOfficeTypeDescription;
            }

            if (transactionFee.ProductId != null)
            {
                ProductRepository productRepository = new ProductRepository();
                Product           product           = new Product();
                product = productRepository.GetProduct((int)transactionFee.ProductId);
                if (product != null)
                {
                    transactionFee.ProductName = product.ProductName;

                    //Supplier
                    if (!String.IsNullOrEmpty(transactionFee.SupplierCode))
                    {
                        SupplierRepository supplierRepository = new SupplierRepository();
                        Supplier           supplier           = new Supplier();
                        supplier = supplierRepository.GetSupplier(transactionFee.SupplierCode, (int)transactionFee.ProductId);
                        if (supplier != null)
                        {
                            transactionFee.SupplierName = supplier.SupplierName;
                        }
                    }
                }
            }

            if (transactionFee.PolicyLocationId != null)
            {
                PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository();
                PolicyLocation           policyLocation           = new PolicyLocation();
                policyLocation = policyLocationRepository.GetPolicyLocation((int)transactionFee.PolicyLocationId);
                if (policyLocation != null)
                {
                    transactionFee.PolicyLocationName = policyLocation.PolicyLocationName;
                }
            }

            //IncursGSTFlag is nullable
            if (transactionFee.IncursGSTFlag != true)
            {
                transactionFee.IncursGSTFlag = false;
            }
            transactionFee.IncursGSTFlagNonNullable = (bool)transactionFee.IncursGSTFlag;
        }