public async Task <IActionResult> PutPolicyLocation([FromRoute] int id, [FromBody] PolicyLocation policyLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != policyLocation.PolicyLocationID) { return(BadRequest()); } _context.Entry(policyLocation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PolicyLocationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Delete(int id) { //Set Access Rights ViewData["Access"] = ""; if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(id); if (policyLocation == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); SelectList travelPortTypes = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription"); ViewData["TravelPortTypeList"] = travelPortTypes; policyLocationRepository.EditForDisplay(policyLocation); return(View(policyLocation)); }
public async Task <IActionResult> Edit(int id, [Bind("PolicyID,PolicyLocationID,LocationNumber,LocationDescription,LocationAddress,LocationCity,LocationState,LocationZip")] PolicyLocation policyLocation) { if (id != policyLocation.PolicyLocationID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(policyLocation); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PolicyLocationExists(policyLocation.PolicyLocationID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(policyLocation)); }
public ActionResult Delete(int id, FormCollection collection) { //Get Item From Database PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(id); if (policyLocation == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Delete Item try { policyLocation.VersionNumber = Int32.Parse(collection["VersionNumber"]); policyLocationRepository.Delete(policyLocation); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/PolicyLocation.mvc/Delete/" + id.ToString(); return(View("VersionError")); } //Generic Error ViewData["Message"] = "The policy location cannot be deleted while it is in use by a policy item."; return(View("Error")); } return(RedirectToAction("List")); }
//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 ActionResult Edit(int id, FormCollection collection) { //Get Item From Database PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(id); //Check Exists if (policyLocation == null) { ViewData["ActionMethod"] = "EditPost"; return(View("RecordDoesNotExistError")); } //Update Item from Form try { UpdateModel(policyLocation); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Database Update try { policyLocationRepository.EditPolicyLocationLocation(policyLocation); policyLocationRepository.Update(policyLocation); } catch (SqlException ex) { //Versioning Error if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/PolicyLocation.mvc/Edit/" + policyLocation.PolicyLocationId; return(View("VersionError")); } LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } //Success return(RedirectToAction("List")); }
//Delete From DB public void Delete(PolicyLocation policyLocation) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_DeletePolicyLocation_v1( policyLocation.PolicyLocationId, adminUserGuid, policyLocation.VersionNumber ); }
public async Task <IActionResult> Create([Bind("PolicyID,PolicyLocationID,LocationNumber,LocationDescription,LocationAddress,LocationCity,LocationState,LocationZip")] PolicyLocation policyLocation) { if (ModelState.IsValid) { _context.Add(policyLocation); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(policyLocation)); }
public async Task <IActionResult> PostPolicyLocation([FromBody] PolicyLocation policyLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PolicyLocation.Add(policyLocation); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPolicyLocation", new { id = policyLocation.PolicyLocationID }, policyLocation)); }
//Get single item public PolicyLocation GetPolicyLocation(int policyLocationId) { HierarchyRepository hierarchyRepository = new HierarchyRepository(); CountryRepository countryRepository = new CountryRepository(); CityRepository cityRepository = new CityRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = db.PolicyLocations.SingleOrDefault(c => c.PolicyLocationId == policyLocationId); if (policyLocation != null) { if (policyLocation.GlobalFlag) { policyLocation.LocationType = "Global"; } else if (policyLocation.CityCode != null) { policyLocation.LocationType = "City"; City city = cityRepository.GetCity(policyLocation.CityCode); Country country = countryRepository.GetCountry(city.CountryCode); policyLocation.ParentName = country.CountryName; } else if (policyLocation.CountryCode != null) { policyLocation.LocationType = "Country"; Country country = countryRepository.GetCountry(policyLocation.CountryCode); GlobalSubRegion globalSubRegion = hierarchyRepository.GetGlobalSubRegion(country.GlobalSubRegionCode); policyLocation.ParentName = globalSubRegion.GlobalSubRegionName; } else if (policyLocation.GlobalSubRegionCode != null) { policyLocation.ParentName = "GlobalSubRegion"; GlobalSubRegion globalSubRegion = hierarchyRepository.GetGlobalSubRegion(policyLocation.GlobalSubRegionCode); GlobalRegion globalRegion = hierarchyRepository.GetGlobalRegion(globalSubRegion.GlobalRegionCode); policyLocation.ParentName = globalRegion.GlobalRegionName; } else if (policyLocation.GlobalRegionCode != null) { policyLocation.LocationType = "GlobalRegion"; GlobalRegion globalRegion = hierarchyRepository.GetGlobalRegion(policyLocation.GlobalRegionCode); policyLocation.ParentName = globalRegion.Global.GlobalName; } } return(policyLocation); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(PolicyHotelVendorGroupItem policyHotelVendorGroupItem) { //PolicyHotelStatusDescription if (policyHotelVendorGroupItem.PolicyHotelStatusId != null) { int policyHotelStatusId = (int)policyHotelVendorGroupItem.PolicyHotelStatusId; PolicyHotelStatusRepository policyHotelStatusRepository = new PolicyHotelStatusRepository(); PolicyHotelStatus policyHotelStatus = new PolicyHotelStatus(); policyHotelStatus = policyHotelStatusRepository.GetPolicyHotelStatus(policyHotelStatusId); policyHotelVendorGroupItem.PolicyHotelStatus = policyHotelStatus.PolicyHotelStatusDescription; } //PolicyGroupName PolicyGroupRepository policyGroupRepository = new PolicyGroupRepository(); PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyHotelVendorGroupItem.PolicyGroupId); policyHotelVendorGroupItem.PolicyGroupName = policyGroup.PolicyGroupName; policyHotelVendorGroupItem.PolicyGroupId = policyGroup.PolicyGroupId; //SupplierName SupplierRepository supplierRepository = new SupplierRepository(); Supplier supplier = new Supplier(); supplier = supplierRepository.GetSupplier(policyHotelVendorGroupItem.SupplierCode, policyHotelVendorGroupItem.ProductId); if (supplier != null) { policyHotelVendorGroupItem.SupplierName = supplier.SupplierName; } //PolicyLocationName PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(policyHotelVendorGroupItem.PolicyLocationId); if (policyLocation != null) { policyHotelVendorGroupItem.PolicyLocationName = policyLocation.PolicyLocationName; } ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(policyHotelVendorGroupItem.ProductId); if (product != null) { policyHotelVendorGroupItem.ProductName = product.ProductName; } }
//Edit Location fields public void EditPolicyLocationLocation(PolicyLocation policyLocation) { string locationType = policyLocation.LocationType; #region if (locationType == "GlobalRegion") { policyLocation.CityCode = null; policyLocation.CountryCode = null; policyLocation.GlobalSubRegionCode = null; policyLocation.GlobalRegionCode = policyLocation.LocationCode; policyLocation.GlobalFlag = false; } else if (locationType == "GlobalSubRegion") { policyLocation.CityCode = null; policyLocation.CountryCode = null; policyLocation.GlobalSubRegionCode = policyLocation.LocationCode; policyLocation.GlobalRegionCode = null; policyLocation.GlobalFlag = false; } else if (locationType == "Country") { policyLocation.CityCode = null; policyLocation.CountryCode = policyLocation.LocationCode; policyLocation.GlobalSubRegionCode = null; policyLocation.GlobalRegionCode = null; policyLocation.GlobalFlag = false; } else if (locationType == "City") { policyLocation.CityCode = policyLocation.LocationCode; policyLocation.CountryCode = null; policyLocation.GlobalSubRegionCode = null; policyLocation.GlobalRegionCode = null; policyLocation.GlobalFlag = false; } else if (locationType == "Global") { policyLocation.CityCode = null; policyLocation.CountryCode = null; policyLocation.GlobalSubRegionCode = null; policyLocation.GlobalRegionCode = null; policyLocation.GlobalFlag = true; } #endregion }
//Add policyLocation public void Add(PolicyLocation policyLocation) { string adminUserGuid = HttpContext.Current.User.Identity.Name.Split(new[] { '|' })[0]; db.spDesktopDataAdmin_InsertPolicyLocation_v1( policyLocation.PolicyLocationName, policyLocation.GlobalFlag, policyLocation.GlobalRegionCode, policyLocation.GlobalSubRegionCode, policyLocation.CountryCode, policyLocation.CityCode, policyLocation.TravelPortCode, policyLocation.TravelPortTypeId, adminUserGuid ); }
// GET: /Create public ActionResult Create() { //Set Access Rights ViewData["Access"] = ""; if (!hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); SelectList travelPortTypes = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription"); ViewData["TravelPortTypeList"] = travelPortTypes; PolicyLocation policyLocation = new PolicyLocation(); return(View(policyLocation)); }
// GET: /Edit public ActionResult View(int id) { PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(id); if (policyLocation == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); SelectList travelPortTypes = new SelectList(travelPortTypeRepository.GetAllTravelPortTypes().ToList(), "TravelPortTypeId", "TravelPortTypeDescription"); ViewData["TravelPortTypeList"] = travelPortTypes; policyLocationRepository.EditForDisplay(policyLocation); return(View(policyLocation)); }
public ActionResult Delete(int id, string languageCode) { //Get Item PolicyMessageGroupItemLanguage policyMessageGroupItemLanguage = new PolicyMessageGroupItemLanguage(); policyMessageGroupItemLanguage = policyMessageGroupItemLanguageRepository.GetItem(id, languageCode); //Check Exists if (policyMessageGroupItemLanguage == null) { ViewData["ActionMethod"] = "DeleteGet"; return(View("RecordDoesNotExistError")); } PolicyMessageGroupItem policyMessageGroupItem = new PolicyMessageGroupItem(); policyMessageGroupItem = policyMessageGroupItemRepository.GetPolicyMessageGroupItem(id); PolicyMessageGroupItemHotelLanguageVM policyMessageGroupItemLanguageVM = new PolicyMessageGroupItemHotelLanguageVM(); policyMessageGroupItemLanguageVM.PolicyMessageGroupItemName = policyMessageGroupItem.PolicyMessageGroupItemName == null ? "[NONE]" : policyMessageGroupItem.PolicyMessageGroupItemName; policyMessageGroupItemLanguageVM.PolicyMessageGroupItemId = policyMessageGroupItem.PolicyMessageGroupItemId; policyMessageGroupItemLanguageVM.PolicyMessageGroupItemLanguage = policyMessageGroupItemLanguage; PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyMessageGroupItem.PolicyGroupId); policyMessageGroupItemLanguageVM.PolicyGroupId = policyGroup.PolicyGroupId; policyMessageGroupItemLanguageVM.PolicyGroupName = policyGroup.PolicyGroupName; Product product = new Product(); product = productRepository.GetProduct((int)policyMessageGroupItem.ProductId); policyMessageGroupItemLanguageVM.ProductName = product.ProductName; PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation((int)policyMessageGroupItem.PolicyLocationId); policyMessageGroupItemLanguageVM.PolicyLocationName = policyLocation.PolicyLocationName; return(View(policyMessageGroupItemLanguageVM)); }
public ActionResult Create(PolicyLocation policyLocation) { //Update Model from Form try { policyLocationRepository.EditPolicyLocationLocation(policyLocation); UpdateModel(policyLocation); } catch { string n = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { n += error.ErrorMessage; } } ViewData["Message"] = "ValidationError : " + n; return(View("Error")); } //Database Update try { policyLocationRepository.Add(policyLocation); } catch (SqlException ex) { LogRepository logRepository = new LogRepository(); logRepository.LogError(ex.Message); ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List")); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(PolicyCarTypeGroupItem policyCarTypeGroupItem) { //PolicyGroupName PolicyGroupRepository policyGroupRepository = new PolicyGroupRepository(); PolicyGroup policyGroup = new PolicyGroup(); policyGroup = policyGroupRepository.GetGroup(policyCarTypeGroupItem.PolicyGroupId); policyCarTypeGroupItem.PolicyGroupName = policyGroup.PolicyGroupName; //CarStatus PolicyCarStatusRepository policyCarStatusRepository = new PolicyCarStatusRepository(); PolicyCarStatus policyCarStatus = new PolicyCarStatus(); policyCarStatus = policyCarStatusRepository.GetPolicyCarStatus(policyCarTypeGroupItem.PolicyCarStatusId); policyCarTypeGroupItem.PolicyCarStatusDescription = policyCarStatus.PolicyCarStatusDescription; //CarType Category CarTypeCategoryRepository carTypeCategoryRepository = new CarTypeCategoryRepository(); CarTypeCategory carTypeCategory = new CarTypeCategory(); carTypeCategory = carTypeCategoryRepository.GetCarTypeCategory(policyCarTypeGroupItem.CarTypeCategoryId); if (carTypeCategory != null) { policyCarTypeGroupItem.CarTypeCategoryName = carTypeCategory.CarTypeCategoryName; } //PolicyLocation PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation(policyCarTypeGroupItem.PolicyLocationId); if (policyLocation != null) { policyCarTypeGroupItem.PolicyLocation = policyLocation.PolicyLocationName; } }
//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())); }
//Add Data From Linked Tables for Display public void EditItemForDisplay(PolicySupplierDealCode policySupplierDealCode) { //PolicySupplierDealCodeType PolicySupplierDealCodeTypeRepository policySupplierDealCodeTypeRepository = new PolicySupplierDealCodeTypeRepository(); PolicySupplierDealCodeType policySupplierDealCodeType = new PolicySupplierDealCodeType(); policySupplierDealCodeType = policySupplierDealCodeTypeRepository.GetPolicySupplierDealCodeType(policySupplierDealCode.PolicySupplierDealCodeTypeId); if (policySupplierDealCodeType != null) { policySupplierDealCode.PolicySupplierDealCodeTypeDescription = policySupplierDealCodeType.PolicySupplierDealCodeTypeDescription; } //GDS GDSRepository gdsRepository = new GDSRepository(); GDS gds = new GDS(); gds = gdsRepository.GetGDS(policySupplierDealCode.GDSCode); if (gds != null) { policySupplierDealCode.GDSName = gds.GDSName; } //PolicyLocation PolicyLocationRepository policyLocationRepository = new PolicyLocationRepository(); PolicyLocation policyLocation = new PolicyLocation(); policyLocation = policyLocationRepository.GetPolicyLocation((int)policySupplierDealCode.PolicyLocationId); if (policyLocation != null) { policySupplierDealCode.PolicyLocationName = policyLocation.PolicyLocationName; } //Supplier SupplierRepository supplierRepository = new SupplierRepository(); Supplier supplier = new Supplier(); supplier = supplierRepository.GetSupplier(policySupplierDealCode.SupplierCode, policySupplierDealCode.ProductId); if (supplier != null) { policySupplierDealCode.SupplierName = supplier.SupplierName; } //EnabledFlag is nullable if (policySupplierDealCode.EnabledFlag != true) { policySupplierDealCode.EnabledFlag = false; } policySupplierDealCode.EnabledFlagNonNullable = (bool)policySupplierDealCode.EnabledFlag; //OSIFlag is nullable if (policySupplierDealCode.OSIFlag != true) { policySupplierDealCode.OSIFlag = false; } policySupplierDealCode.OSIFlagNonNullable = (bool)policySupplierDealCode.OSIFlag; //Product ProductRepository productRepository = new ProductRepository(); Product product = new Product(); product = productRepository.GetProduct(policySupplierDealCode.ProductId); if (product != null) { policySupplierDealCode.ProductName = product.ProductName; } //PolicyGroup PolicyGroupRepository policyGroupRepository = new PolicyGroupRepository(); PolicyGroup policyGroup = policyGroupRepository.GetGroup(policySupplierDealCode.PolicyGroupId); policySupplierDealCode.PolicyGroupName = policyGroup.PolicyGroupName; //Tour Code Type TourCodeTypeRepository tourCodeTypeRepository = new TourCodeTypeRepository(); TourCodeType tourCodeType = tourCodeTypeRepository.GetTourCodeType(policySupplierDealCode.TourCodeTypeId ?? 0); if (tourCodeType != null) { policySupplierDealCode.TourCodeType = tourCodeType; } }
//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())); }
//Add Data From Linked Tables for Display public void EditForDisplay(PolicyLocation policyLocation) { if (policyLocation.TravelPortCode != null) { TravelPortRepository travelPortRepository = new TravelPortRepository(); TravelPort travelPort = new TravelPort(); travelPort = travelPortRepository.GetTravelPort(policyLocation.TravelPortCode); if (travelPort != null) { policyLocation.TravelPortName = travelPort.TravelportName; policyLocation.LocationCode = travelPort.TravelPortCode; policyLocation.LocationName = travelPort.TravelportName; } } if (policyLocation.TravelPortTypeId != null) { int travelPortTypeId = (int)policyLocation.TravelPortTypeId; TravelPortTypeRepository travelPortTypeRepository = new TravelPortTypeRepository(); TravelPortType travelPortType = new TravelPortType(); travelPortType = travelPortTypeRepository.GetTravelPortType(travelPortTypeId); if (travelPortType != null) { policyLocation.TravelPortType = travelPortType.TravelPortTypeDescription; } } HierarchyRepository hierarchyRepository = new HierarchyRepository(); string globalRegionCode = policyLocation.GlobalRegionCode; if (globalRegionCode != null) { GlobalRegion globalRegion = new GlobalRegion(); globalRegion = hierarchyRepository.GetGlobalRegion(globalRegionCode); policyLocation.LocationCode = globalRegion.GlobalRegionCode; policyLocation.LocationName = globalRegion.GlobalRegionName; } string globalSubRegionCode = policyLocation.GlobalSubRegionCode; if (globalSubRegionCode != null) { GlobalSubRegion globalSubRegion = new GlobalSubRegion(); globalSubRegion = hierarchyRepository.GetGlobalSubRegion(globalSubRegionCode); policyLocation.LocationCode = globalSubRegion.GlobalSubRegionCode; policyLocation.LocationName = globalSubRegion.GlobalSubRegionName; } string countryCode = policyLocation.CountryCode; if (countryCode != null) { Country country = new Country(); country = hierarchyRepository.GetCountry(countryCode); policyLocation.LocationCode = country.CountryCode; policyLocation.LocationName = country.CountryName; } string cityCode = policyLocation.CityCode; if (cityCode != null) { CityRepository cityRepository = new CityRepository(); City city = new City(); city = cityRepository.GetCity(cityCode); policyLocation.LocationCode = city.CityCode; policyLocation.LocationName = city.Name; } if (policyLocation.GlobalFlag) { policyLocation.LocationName = "Global"; policyLocation.LocationCode = "Global"; } }
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; }