//Add Data From Linked Tables for Display public void EditItemForDisplay(PolicyHotelCapRateGroupItem policyHotelCapRateGroupItem) { //PolicyGroupName PolicyGroupRepository policyGroupRepository = new PolicyGroupRepository(); PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyHotelCapRateGroupItem.PolicyGroupId); policyHotelCapRateGroupItem.PolicyGroupName = policyGroup.PolicyGroupName; //Currency if (policyHotelCapRateGroupItem.CurrencyCode != null) { string currencyCode = policyHotelCapRateGroupItem.CurrencyCode; CurrencyRepository currencyRepository = new CurrencyRepository(); Currency currency = new Currency(); currency = currencyRepository.GetCurrency(currencyCode); policyHotelCapRateGroupItem.CurrencyName = currency.Name; } //PolicyLocation PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(policyHotelCapRateGroupItem.PolicyLocationId); if (policyLocation != null) { policyHotelCapRateGroupItem.PolicyLocation = policyLocation.PolicyLocationName; } }
public PolicyHotelCapRateImportStep2VM PreImportCheck(HttpPostedFileBase file, int policyGroupId) { //convert file to string so that we can parse int length = file.ContentLength; byte[] tempFile = new byte[length]; file.InputStream.Read(tempFile, 0, length); byte[] array = tempFile.ToArray(); System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); string fileToText = fileToText = enc.GetString(array); // Create the xml document container, this will be used to store the data after the checks XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null); doc.AppendChild(dec); XmlElement root = doc.CreateElement("PHCRIGs"); doc.AppendChild(root); List <string> returnMessages = new List <string>(); string returnMessage; int i = 0; //Split the CSV into lines string[] lines = fileToText.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //loop through CSV lines foreach (string line in lines) { i++; if (i > 1) //ignore first line with titles { string[] cells = line.Split(','); //extract the data items from the file string locationCode = cells[0]; //Required string currencyCode = cells[1]; //Required string capRate = cells[2]; //Required string enabledFlag = cells[3] ?? ""; string enabledDate = cells[4] ?? ""; string expiryDate = cells[5] ?? ""; string travelDateValidFrom = cells[6] ?? ""; string travelDateValidTo = cells[7] ?? ""; string taxInclusiveFlag = cells[8]; //Required //Build the XML Element for items XmlElement xmlCDRItem = doc.CreateElement("PHCRIG"); XmlElement xmlLocationCode = doc.CreateElement("LocationCode"); xmlLocationCode.InnerText = locationCode; xmlCDRItem.AppendChild(xmlLocationCode); XmlElement xmlCurrencyCode = doc.CreateElement("CurrencyCode"); xmlCurrencyCode.InnerText = currencyCode; xmlCDRItem.AppendChild(xmlCurrencyCode); XmlElement xmlCapRate = doc.CreateElement("CapRate"); xmlCapRate.InnerText = capRate; xmlCDRItem.AppendChild(xmlCapRate); XmlElement xmlEnabledDate = doc.CreateElement("EnabledDate"); xmlEnabledDate.InnerText = enabledDate; xmlCDRItem.AppendChild(xmlEnabledDate); XmlElement xmlExpiryDate = doc.CreateElement("ExpiryDate"); xmlExpiryDate.InnerText = expiryDate; xmlCDRItem.AppendChild(xmlExpiryDate); XmlElement xmlTravelDateValidFrom = doc.CreateElement("TravelDateValidFrom"); xmlTravelDateValidFrom.InnerText = travelDateValidFrom; xmlCDRItem.AppendChild(xmlTravelDateValidFrom); XmlElement xmlTravelDateValidTo = doc.CreateElement("TravelDateValidTo"); xmlTravelDateValidTo.InnerText = travelDateValidTo; xmlCDRItem.AppendChild(xmlTravelDateValidTo); //Validate data if (string.IsNullOrEmpty(locationCode) == true) { returnMessage = "Row " + i + ": LocationCode is missing. Please provide a valid Location Code"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if (string.IsNullOrEmpty(currencyCode) == true) { returnMessage = "Row " + i + ": CurrencyCode is missing. Please provide a valid Currency Code"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if (string.IsNullOrEmpty(capRate) == true) { returnMessage = "Row " + i + ": CapRate is missing. Please provide a valid Cap Rate"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if (string.IsNullOrEmpty(taxInclusiveFlag) == true) { returnMessage = "Row " + i + ": TaxInclusiveFlag is missing. Please provide a valid TaxInclusiveFlag"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } string locationId = dbHierarchyDC.fnDesktopDataAdmin_GetPolicyLocationIdBasedOnCode_v1(locationCode).ToString(); if (locationId == "-1") { returnMessage = "Row " + i + ": There is no Policy Location available for the Location Code value " + locationCode + ". Please contact your Administrator"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } XmlElement xmlLocationCodeId = doc.CreateElement("LocationCodeId"); xmlLocationCodeId.InnerText = locationId; xmlCDRItem.AppendChild(xmlLocationCodeId); var currencyRepository = new CurrencyRepository(); if (currencyRepository.GetCurrency(currencyCode) == null) { returnMessage = "Row " + i + ": Currency Code " + currencyCode + " is invalid. Please provide a valid Currency Code"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } float capRateNumeric; if (float.TryParse(capRate, out capRateNumeric) == false) { returnMessage = "Row " + i + ": CapRate must be numerical. Please provide a valid Cap Rate"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if ((capRate.IndexOf('.') == -1 && capRate.Length > 12) || (capRate.IndexOf('.') != -1 && (capRate.Length - (capRate.IndexOf('.') + 1) > 5 || capRate.IndexOf('.') > 12))) { returnMessage = "Row " + i + ": CapRate exceeds the allowable size. Please provide a valid Cap Rate"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } taxInclusiveFlag = taxInclusiveFlag.ToUpper(); if (taxInclusiveFlag != "TRUE" && taxInclusiveFlag != "FALSE" && taxInclusiveFlag != "1" && taxInclusiveFlag != "0") { returnMessage = "Row " + i + ": TaxInclusiveFlag value is not valid. Please provide a valid Tax Inclusive Flag"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if (taxInclusiveFlag == "TRUE") { taxInclusiveFlag = "1"; } if (taxInclusiveFlag == "FALSE") { taxInclusiveFlag = "0"; } XmlElement xmlTaxInclusiveFlag = doc.CreateElement("TaxInclusiveFlag"); xmlTaxInclusiveFlag.InnerText = taxInclusiveFlag; xmlCDRItem.AppendChild(xmlTaxInclusiveFlag); enabledFlag = enabledFlag.ToUpper(); if (enabledFlag != "TRUE" && enabledFlag != "FALSE" && enabledFlag != "1" && enabledFlag != "0" && enabledFlag != "") { returnMessage = "Row " + i + ": EnabledFlag value is not valid. Please provide a valid Enabled Flag"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } if (enabledFlag == "TRUE" || string.IsNullOrEmpty(enabledFlag)) { enabledFlag = "1"; } if (enabledFlag == "FALSE") { enabledFlag = "0"; } XmlElement xmlEnabledFlag = doc.CreateElement("EnabledFlag"); xmlEnabledFlag.InnerText = enabledFlag; xmlCDRItem.AppendChild(xmlEnabledFlag); if (enabledDate != "" && enabledDate != "NULL") { DateTime enabledDateDT; if (DateTime.TryParseExact(enabledDate, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out enabledDateDT) == false) { returnMessage = "Row " + i + ": EnabledDate must be in the format YYYY/MM/DD. Please provide a valid date format"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } if (expiryDate != "" && expiryDate != "NULL") { DateTime enabledDateDT; if (DateTime.TryParseExact(expiryDate, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out enabledDateDT) == false) { returnMessage = "Row " + i + ": ExpiryDate must be in the format YYYY/MM/DD. Please provide a valid date format"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } if (travelDateValidFrom != "" && travelDateValidFrom != "NULL") { DateTime enabledDateDT; if (DateTime.TryParseExact(travelDateValidFrom, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out enabledDateDT) == false) { returnMessage = "Row " + i + ": TravelDateFrom must be in the format YYYY/MM/DD. Please provide a valid date format"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } if (travelDateValidTo != "" && travelDateValidTo != "NULL") { DateTime enabledDateDT; if (DateTime.TryParseExact(travelDateValidTo, "yyyy/MM/dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out enabledDateDT) == false) { returnMessage = "Row " + i + ": TravelDateTo must be in the format YYYY/MM/DD. Please provide a valid date format"; if (!returnMessages.Contains(returnMessage)) { returnMessages.Add(returnMessage); } } } //Attach the XML Element for an item to the Document root.AppendChild(xmlCDRItem); } } if (i == 0) { returnMessage = "There is no data in the file"; returnMessages.Add(returnMessage); } PolicyHotelCapRateImportStep2VM preImportCheckResult = new PolicyHotelCapRateImportStep2VM(); preImportCheckResult.ReturnMessages = returnMessages; if (returnMessages.Count != 0) { //preImportCheckResult.FileBytes = array; preImportCheckResult.IsValidData = false; } else { //DB Check string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; var output = ( from n in dbHierarchyDC.spDesktopDataAdmin_UpdatePolicyHotelCapDefinedReferencesCount_v1( policyGroupId, System.Xml.Linq.XElement.Parse(doc.OuterXml), adminUserGuid ) select n).ToList(); foreach (spDesktopDataAdmin_UpdatePolicyHotelCapDefinedReferencesCount_v1Result message in output) { returnMessages.Add(message.MessageText.ToString()); } preImportCheckResult.FileBytes = array; preImportCheckResult.IsValidData = true; } return(preImportCheckResult); }
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; }