예제 #1
0
        //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("Location Name");
            headers.Add("Location Code");
            headers.Add("Currency Name");
            headers.Add("Currency Code");
            headers.Add("Hotel Cap Rate Amount");
            headers.Add("Enabled Flag");
            headers.Add("Enabled Date");
            headers.Add("Expiry Date");
            headers.Add("Travel Date Valid From");
            headers.Add("Travel Date Valid To");
            headers.Add("Tax Inclusive Flag");
            headers.Add("Creation TimeStamp");
            headers.Add("Last Update Time Stamp");
            headers.Add("Advice");

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

            //Add Items
            List <PolicyHotelCapRateGroupItem> policyHotelCapRateGroupItems = db.PolicyHotelCapRateGroupItems.Where(x => x.PolicyGroupId == id).ToList();

            foreach (PolicyHotelCapRateGroupItem item in policyHotelCapRateGroupItems)
            {
                //Edit Item
                EditItemForDisplay(item);

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

                //Advice Count
                int adviceCount = 0;
                PolicyHotelCapRateGroupItemLanguageRepository policyHotelCapRateGroupItemLanguageRepository = new PolicyHotelCapRateGroupItemLanguageRepository();
                List <PolicyHotelCapRateGroupItemLanguage>    policyHotelCapRateGroupItemLanguages          = policyHotelCapRateGroupItemLanguageRepository.GetItems(item.PolicyHotelCapRateItemId);
                if (policyHotelCapRateGroupItemLanguages != null)
                {
                    adviceCount = policyHotelCapRateGroupItemLanguages.Count();
                }

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

                string short_date_format = "yyyy/MM/dd";

                sb.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}",
                                !string.IsNullOrEmpty(item.PolicyGroupName) ? item.PolicyGroupName : "",
                                !string.IsNullOrEmpty(policyLocation.LocationName) ? policyLocation.LocationName : "",
                                !string.IsNullOrEmpty(policyLocation.LocationCode) ? policyLocation.LocationCode : "",
                                !string.IsNullOrEmpty(item.CurrencyName) ? item.CurrencyName : "",
                                !string.IsNullOrEmpty(item.CurrencyCode) ? item.CurrencyCode : "",
                                item.CapRate.HasValue ? item.CapRate.Value.ToString() : "",
                                item.EnabledFlag == true ? "True" : "False",
                                item.EnabledDate.HasValue ? item.EnabledDate.Value.ToString(short_date_format) : "",
                                item.ExpiryDate.HasValue ? item.ExpiryDate.Value.ToString(short_date_format) : "",
                                item.TravelDateValidFrom.HasValue ? item.TravelDateValidFrom.Value.ToString(short_date_format) : "",
                                item.TravelDateValidTo.HasValue ? item.TravelDateValidTo.Value.ToString(short_date_format) : "",
                                item.TaxInclusiveFlag == true ? "True" : "False",
                                item.CreationTimestamp.HasValue ? item.CreationTimestamp.Value.ToString(date_format) : "",
                                item.LastUpdateTimestamp.HasValue ? item.LastUpdateTimestamp.Value.ToString(date_format) : "",
                                adviceCount > 0 ? "True" : "False"
                                );

                sb.Append(Environment.NewLine);
            }

            return(Encoding.ASCII.GetBytes(sb.ToString()));
        }
        //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()));
        }