/// <summary> /// Populate Sector by Id /// </summary> /// <param name="search"></param> public TSMSector GetSectorByID(Guid id) { TSMSector objSector = new TSMSector(); try { objSector = SectorService.GetSector(id); if (objSector != null) { this.ParentNomenclature = new List <TSMSector>(); this.ChildNomenclature = new List <TSMSector>(); this.ID = objSector.ID; this.Nomenclaturetype = objSector.NomenclatureType; this.Sectortype = objSector.Type; this.ParentCode = objSector.ParentID.ToString(); this.SectorName = objSector.Name; this.NomenclatureCode = objSector.Code; this.IsActive = objSector.IsActive; } } catch (Exception ex) { ErrorLog.WriteLog("ManageUserModel", "Populate", ex, ""); } return(objSector); }
public static TSMSector GetSectorByName(string Name) { TSMSector tsmSector = new TSMSector(); return(tsmSector); }
public SectorType INTGetType(string sitcCode) { var SectorData = new TSMSector(); using (var context = new TSMContext()) { SectorData = context.TSMSector.Where(u => u.Code == sitcCode && u.IsDeleted == false && u.NomenclatureType == NomenclatureType.ITC).FirstOrDefault(); } var type = SectorData.Type; return(type); }
/// <summary> /// Save /// </summary> public TSMSector Save() { TSMSector tsmSector = new TSMSector(); try { if (this.ID != Guid.Empty) { tsmSector = SectorService.GetSector(this.ID); tsmSector.ID = this.ID; tsmSector.LastModifiedBy = TSM.Model.TSMContext.CurrentUser.ID; tsmSector.LastModifiedDate = DateTime.UtcNow; } else { tsmSector = new TSMSector(); tsmSector.CreatedBy = TSM.Model.TSMContext.CurrentUser.ID; tsmSector.CreatedDate = DateTime.UtcNow; } tsmSector.LanguageID = TSMContext.CurrentLanguageID; tsmSector.Code = this.NomenclatureCode; tsmSector.IsActive = this.IsActive; tsmSector.IsDeleted = false; tsmSector.Name = this.SectorName; tsmSector.NomenclatureType = this.Nomenclaturetype; Guid newGuid = new Guid(); try { var childcode = this.ChildCode; var parentCode = this.ParentCode; if (childcode != null) { newGuid = Guid.Parse(childcode); tsmSector.ParentID = newGuid; } else if (parentCode != null) { newGuid = Guid.Parse(parentCode); tsmSector.ParentID = newGuid; } } catch { tsmSector.ParentID = null; } tsmSector.Type = this.Sectortype; SectorService.Save(tsmSector); } catch (Exception ex) { ErrorLog.WriteLog("ManageUserModel", "Save", ex, ""); } return(tsmSector); }
/// <summary> /// Delete TSM SECTOR /// </summary> /// <param name="tsmSector"></param> public static void Delete(TSMSector tsmSector) { using (var context = new TSMContext()) { context.TSMSector.Attach(tsmSector); context.Entry(tsmSector).Property(u => u.IsActive).IsModified = true; context.Entry(tsmSector).Property(u => u.IsDeleted).IsModified = true; context.Entry(tsmSector).Property(u => u.LastModifiedDate).IsModified = true; context.Entry(tsmSector).Property(u => u.LastModifiedBy).IsModified = true; context.SaveChanges(); } }
/// <summary> /// Delete Sector /// </summary> /// <param name="id"></param> /// <param name="Model"></param> public void Delete(Guid id) { TSMSector tsmSector = SectorService.GetSector(id); if (tsmSector != null) { tsmSector.IsActive = false; tsmSector.IsDeleted = true; tsmSector.LastModifiedBy = TSMContext.CurrentUser.ID; tsmSector.LastModifiedDate = DateTime.UtcNow; SectorService.Delete(tsmSector); } }
/// <summary> /// Populate Sector /// </summary> /// <param name="search"></param> public TSMSector GetSector(Guid id) { TSMSector objSector = new TSMSector(); try { objSector = SectorService.GetSector(id); } catch (Exception ex) { ErrorLog.WriteLog("ManageUserModel", "Populate", ex, ""); } return(objSector); }
public JsonResult getCode(string value) { TSMSector tsmSector = new TSMSector(); ManageSectorModel mng = new ManageSectorModel(); Guid newGuid = new Guid(); newGuid = Guid.Parse(value); try { tsmSector = mng.GetSector(newGuid); } catch { } return(this.Json(new { Code = tsmSector.Code }, JsonRequestBehavior.AllowGet)); }
public ActionResult ManageSector(Guid?id) { ManageSectorModel SectorModel = new ManageSectorModel(); if (id.HasValue && id.Value != Guid.Empty) { TSMSector tsmSector = SectorModel.GetSectorByID(id.Value); SectorModel.ChildNomenclature = new List <TSMSector>(); } if (SectorModel.ParentNomenclature == null) { SectorModel.ParentNomenclature = new List <TSMSector>(); SectorModel.ChildNomenclature = new List <TSMSector>(); } return(View("~/Views/Admin/Sector/manage-sector.cshtml", SectorModel)); }
//GET ID by Name public static string GetINTSectorIDByName(string name, SectorType secType) { var INT_Nom = new TSMSector(); //string name = name.Trim(); using (var context = new TSMContext()) { INT_Nom = context.TSMSector.Where(u => u.Name == name && u.IsDeleted == false && u.NomenclatureType == NomenclatureType.International && u.Type == secType).FirstOrDefault(); } string intID = ""; if (INT_Nom != null) { intID = INT_Nom.Code; } return(intID); }
public Guid GetITCSectorIDByName(string name, SectorType secType) { var ITC_Nom = new TSMSector(); //string name = name.Trim(); using (var context = new TSMContext()) { ITC_Nom = context.TSMSector.Where(u => u.Name == name && u.IsDeleted == false && u.NomenclatureType == NomenclatureType.ITC && u.Type == secType).FirstOrDefault(); } Guid itcID = Guid.Empty; if (ITC_Nom != null) { itcID = ITC_Nom.ID; } return(itcID); }
//GET ID by Code public Guid GetINTSectorID(string sitcCode, SectorType secType) { var INT_Nom = new TSMSector(); string code = sitcCode.Trim(); using (var context = new TSMContext()) { INT_Nom = context.TSMSector.Where(u => u.Code == sitcCode && u.IsDeleted == false && u.NomenclatureType == NomenclatureType.International && u.Type == secType).FirstOrDefault(); } Guid intID = Guid.Empty; if (INT_Nom != null) { intID = INT_Nom.ID; } return(intID); }
public static string GetITCSectorByID(Guid id, SectorType secType) { var ITC_Nom = new TSMSector(); //string code = sitcCode.Trim(); using (var context = new TSMContext()) { ITC_Nom = context.TSMSector.Where(u => u.ID == id && u.IsDeleted == false && u.NomenclatureType == NomenclatureType.ITC && u.Type == secType).FirstOrDefault(); } string itcID = ""; if (ITC_Nom != null) { itcID = ITC_Nom.Code; } return(itcID); }
/// <summary> /// Save Sector /// </summary> /// <param name="user"></param> /// <returns></returns> public static TSMSector Save(TSMSector tsmsSctor) { using (var context = new TSMContext()) { if (context.TSMSector.Where(v => v.ID == tsmsSctor.ID).Count() > 0) { context.TSMSector.Attach(tsmsSctor); context.Entry(tsmsSctor).State = EntityState.Modified; } else { context.TSMSector.Add(tsmsSctor); } //Save to DB context.SaveChanges(); return(tsmsSctor); } }
public ActionResult ManageSector(ManageSectorModel TSMSectorModel) { try { bool exist = false; if (TSMSectorModel.ID == Guid.Empty) { exist = TSMSectorModel.CheckSector(); } if (exist == false) { TSMSector tsmSector = TSMSectorModel.Save(); if (TSMSectorModel.ID != Guid.Empty) { TempData["Success"] = "true"; return(Redirect(Url.Action("manage-sector", "Admin") + "?id=" + tsmSector.ID)); } else { TempData["Success"] = "true"; return(Redirect(Url.Action("manage-sector", "Admin") + "?id=" + tsmSector.ID)); } } else { TempData["Exist"] = "true"; TempData["Success"] = "false"; } } catch (Exception ex) { TempData["Success"] = "false"; ErrorLog.WriteLog("SectorController", "ManageSector", ex, ""); } return(View("~/Views/Admin/Sector/manage-sector.cshtml", TSMSectorModel)); }
public void RebuildRecordAsync() { Console.WriteLine("Index Rebuild Started"); Guid languageId = TSM.Model.TSMContext.CurrentLanguageID; List <Record> record = new List <Record>(); List <Guid> listRecordsID = RecordService.GetAllRecordID(); List <ExportRecordData> ExportdataList = new List <ExportRecordData>(); if (listRecordsID != null) { SearchAttributes searchParam = GetSearchParam(); record = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam); ExportRecordData ExportRecordData = new ExportRecordData(); ExportRecordData.Records = new List <ExportRecord>(); #region [If Not Null Record] if (record != null) { #region [Data Load] //Get Variable Items List <Variable_Language> variableItems = new List <Variable_Language>(); variableItems = SearchServices.GetVariableLanguageForVariable(languageId).ToList(); //Get Get All Country With Region List <Country> listofAllCountries = new List <Country>(); listofAllCountries = SearchServices.GetAllCountryWithRegion(); //Get list of All Region List <Region_Language> listofAllRegion = new List <Region_Language>(); listofAllRegion = SearchServices.GetAllRegionWithLanguage(); //Get list of All Country with language List <Country_Language> lstCountryLang = new List <Country_Language>(); lstCountryLang = SearchServices.GetAllCountry(languageId); //Get Sector Language List <Sector_Language> lstSectorLanguage = new List <Sector_Language>(); lstSectorLanguage = SearchServices.GetAllSectorNames(languageId); //Get Sector List <TSMSector> lstTSMSector = new List <TSMSector>(); lstTSMSector = SearchServices.GetAllSector(); // Get Record Variable List <Record_Variable> recordVariables = new List <Record_Variable>(); recordVariables = SearchServices.GetAllRecordVariable(); #endregion TotalRecord = record.Count; Console.WriteLine("Total Records: " + TotalRecord.ToString()); foreach (var exportRecordData in record) { try { ExportRecordData.Variables = new List <KeyValue>(); foreach (var keyValue in variableItems) { KeyValue keyValuevariableLanguageItem = new KeyValue { Key = keyValue.ID.ToString(), Value = keyValue.Name }; ExportRecordData.Variables.Add(keyValuevariableLanguageItem); } ExportRecord exportRecord = null; #region [sector = 0 && country = 1] if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count == 0)) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString(); //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } #endregion #region [sector > 0 && country = 1] else if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count > 0)) { foreach (var sec in exportRecordData.Sectors) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString(); //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion #region [sector > 0 && country > 1] else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count > 0)) { foreach (var cnt in exportRecordData.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); foreach (var sec in exportRecordData.Sectors) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString(); //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } } #endregion #region [sector = 0 && country > 1] else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count == 0)) { foreach (var cnt in exportRecordData.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString(); //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion recordProcessed++; int percentRecord = (recordProcessed / TotalRecord) * 100; //Console.Clear(); Console.WriteLine(recordProcessed.ToString() + " of " + TotalRecord.ToString() + " records done. Plese wait..."); } catch (Exception ee) { recordNotProcessed++; Console.WriteLine(recordNotProcessed.ToString() + " of " + TotalRecord.ToString()); ErrorLog.WriteLog("Import", "Import", ee, ""); } } } ExportdataList.Add(ExportRecordData); if (DeleteFile()) { Console.WriteLine("Delete Success"); if (SaveXMLToData(ExportdataList)) { Console.WriteLine("Save Success"); } else { Console.WriteLine("Save Error!"); } } else { Console.Write("Delete Error!"); } #endregion } Console.WriteLine(recordProcessed.ToString() + " of " + TotalRecord.ToString() + " & " + recordNotProcessed.ToString() + " fail(s)."); }
public void RebuildRecordAsync() { Guid languageId = TSM.Model.TSMContext.CurrentLanguageID; List <Record> record = new List <Record>(); List <Guid> listRecordsID = RecordService.GetAllRecordID(); List <ExportRecordData> ExportdataList = new List <ExportRecordData>(); var cacheProvider = CacheFactory.Get(); if (listRecordsID != null) { SearchAttributes searchParam = GetSearchParam(); record = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam); ExportRecordData ExportRecordData = new ExportRecordData(); ExportRecordData.Records = new List <ExportRecord>(); #region [If Not Null Record] if (record != null) { #region [Cache Data Load] //Get Variable Items List <Variable_Language> variableItems = new List <Variable_Language>(); variableItems = SearchServices.GetVariableLanguageForVariable(languageId).ToList(); //Get Get All Country With Region List <Country> listofAllCountries = new List <Country>(); listofAllCountries = SearchServices.GetAllCountryWithRegion(); //Get list of All Region List <Region_Language> listofAllRegion = new List <Region_Language>(); listofAllRegion = SearchServices.GetAllRegionWithLanguage(); //Get list of All Country with language List <Country_Language> lstCountryLang = new List <Country_Language>(); lstCountryLang = SearchServices.GetAllCountry(languageId); //Get Sector Language List <Sector_Language> lstSectorLanguage = new List <Sector_Language>(); lstSectorLanguage = SearchServices.GetAllSectorNames(languageId); //Get Sector List <TSMSector> lstTSMSector = new List <TSMSector>(); lstTSMSector = SearchServices.GetAllSector(); // Get Record Variable List <Record_Variable> recordVariables = new List <Record_Variable>(); recordVariables = SearchServices.GetAllRecordVariable(); #endregion foreach (var exportRecordData in record) { try { ExportRecordData.Variables = new List <KeyValue>(); foreach (var keyValue in variableItems) { KeyValue keyValuevariableLanguageItem = new KeyValue { Key = keyValue.ID.ToString(), Value = keyValue.Name }; ExportRecordData.Variables.Add(keyValuevariableLanguageItem); } ExportRecord exportRecord = null; #region [sector = 0 && country = 1] if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count == 0)) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower(); //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } #endregion #region [sector > 0 && country = 1] else if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count > 0)) { foreach (var sec in exportRecordData.Sectors) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower(); //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion #region [sector > 0 && country > 1] else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count > 0)) { foreach (var cnt in exportRecordData.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); foreach (var sec in exportRecordData.Sectors) { exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower(); //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } } #endregion #region [sector = 0 && country > 1] else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count == 0)) { foreach (var cnt in exportRecordData.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); exportRecord = new ExportRecord(); //document try { if (exportRecordData.Documents.Count > 0) { exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = exportRecordData.ID; //Name exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower(); //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion recordProcessed++; } catch (Exception ee) { recordNotProcessed++; ErrorLog.WriteLog("RebuildDownload", "AsyncCall", ee, ""); } } } ExportdataList.Add(ExportRecordData); //Save(ExportdataList); //return; if (SaveXMLToData(ExportdataList)) { isSaved = 1; TotalRows = ExportdataList[0].Records.Count.ToString(); //lblNumberRows.Text = TotalRows; ScriptManager.RegisterStartupScript(this, GetType(), "disableButton1", "$('#btnRebuildDownloadCache').prop('disabled', false); $('#loaderImg').hide();", true); ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess1", "$('#dvSuccess').show();", true); ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure1", "$('#dvFailure').hide();", true); } else { isSaved = 2; ScriptManager.RegisterStartupScript(this, GetType(), "disableButton1", "$('#btnRebuildDownloadCache').prop('disabled', false); $('#loaderImg').hide();", true); ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess", "$('#dvSuccess').hide();", true); ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure", "$('#dvFailure').show();", true); } #endregion } }
public ExportRecordData CreateNewRecord(Guid recd) { ExportRecordData ExportRecordData = new ExportRecordData(); if (recd != Guid.Empty) { Guid recID = recd; List <Guid> listRecordsID = new List <Guid>(); listRecordsID.Add(recID); List <Record> recordlist = new List <Record>(); SearchAttributes searchParam = GetSearchParam(); recordlist = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam); Record rec = recordlist.FirstOrDefault(); Guid languageId = TSM.Model.TSMContext.CurrentLanguageID; ExportRecordData.Records = new List <ExportRecord>(); #region [Data Load] //Get Variable Items List <Variable_Language> variableItems = new List <Variable_Language>(); variableItems = SearchServices.GetVariableLanguageForVariable(languageId).ToList(); //Get Get All Country With Region List <Country> listofAllCountries = new List <Country>(); listofAllCountries = SearchServices.GetAllCountryWithRegion(); //Get list of All Region List <Region_Language> listofAllRegion = new List <Region_Language>(); listofAllRegion = SearchServices.GetAllRegionWithLanguage(); //Get list of All Country with language List <Country_Language> lstCountryLang = new List <Country_Language>(); lstCountryLang = SearchServices.GetAllCountry(languageId); //Get Sector Language List <Sector_Language> lstSectorLanguage = new List <Sector_Language>(); lstSectorLanguage = SearchServices.GetAllSectorNames(languageId); //Get Sector List <TSMSector> lstTSMSector = new List <TSMSector>(); lstTSMSector = SearchServices.GetAllSector(); // Get Record Variable List <Record_Variable> recordVariables = new List <Record_Variable>(); recordVariables = SearchServices.GetAllRecordVariable(); #endregion ExportRecordData.Variables = new List <KeyValue>(); foreach (var keyValue in variableItems) { KeyValue keyValuevariableLanguageItem = new KeyValue { Key = keyValue.ID.ToString(), Value = keyValue.Name }; ExportRecordData.Variables.Add(keyValuevariableLanguageItem); } ExportRecord exportRecord = null; #region [sector = 0 && country = 1] if ((rec.Countries.Count == 1) && (rec.Sectors.Count == 0)) { exportRecord = new ExportRecord(); //document try { if (rec.Documents.Count > 0) { exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = rec.ID; //Name exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name; //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == rec.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == rec.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = rec.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, rec.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } #endregion #region [sector > 0 && country = 1] else if ((rec.Countries.Count == 1) && (rec.Sectors.Count > 0)) { foreach (var sec in rec.Sectors) { exportRecord = new ExportRecord(); //document try { if (rec.Documents.Count > 0) { exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = rec.ID; //Name exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name; //Regions start var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == rec.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Region end //Country start Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == rec.Countries[0].ID).FirstOrDefault(); exportRecord.Countries = countryLanguage.Name; //country end exportRecord.CountryCode = rec.Countries[0].ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, rec.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion #region [sector > 0 && country > 1] else if ((rec.Countries.Count > 1) && (rec.Sectors.Count > 0)) { foreach (var cnt in rec.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == rec.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); foreach (var sec in rec.Sectors) { exportRecord = new ExportRecord(); //document try { if (rec.Documents.Count > 0) { exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = rec.ID; //Name exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name; //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, rec.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key)); } } //sector Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault(); exportRecord.Sectors = secLang.Name; exportRecord.SectorType = sec.Type.ToString(); var intSec = exportRecord.Sectors; //International Nomenclature Code string intNId = ""; if (sec.International_NomenclatureID != Guid.Empty) { try { var interNid = sec.International_NomenclatureID.Value; TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } catch { } } if (intNId == "") { TSMSector INT_Nom = new TSMSector(); INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault(); if (INT_Nom != null) { intNId = INT_Nom.Code; } } //ITC Nomenclature Code string itcNid = ""; if (sec.ITC_NomenclatureID != Guid.Empty) { try { var itcid = sec.ITC_NomenclatureID.Value; TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } catch { } } if (itcNid == "") { TSMSector ITC_Nom = new TSMSector(); ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault(); if (ITC_Nom != null) { itcNid = ITC_Nom.Code; } } exportRecord.ITCCode = itcNid; exportRecord.INTCode = intNId; if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } } #endregion #region [sector = 0 && country > 1] else if ((rec.Countries.Count > 1) && (rec.Sectors.Count == 0)) { foreach (var cnt in rec.Countries) { Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault(); var selectedRegion = new List <Region>(); Country tmpCountry = listofAllCountries.Where(c => c.ID == rec.Countries[0].ID).FirstOrDefault(); if (tmpCountry != null) { foreach (var r in tmpCountry.Regions) { selectedRegion.Add(r); } } var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList(); exportRecord = new ExportRecord(); //document try { if (rec.Documents.Count > 0) { exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString(); } else { exportRecord.Document = null; } } catch { exportRecord.Document = ""; } //ID exportRecord.RecordID = rec.ID; //Name exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name; //Regions if (regionLanguageList.Count > 0) { exportRecord.Regions = regionLanguageList[0].ToString(); } //Country exportRecord.Countries = countryLanguage.Name; exportRecord.CountryCode = cnt.ISOCode; //variable values exportRecord.VariableValues = new List <string>(); List <string> recordVariableKey = new List <string>(); foreach (var variableValue in ExportRecordData.Variables) { if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "") { recordVariableKey.Add(variableValue.Key); exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, rec.ID, recordVariableKey, variableValue.Key, recordVariables)); //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key)); } } if (exportRecord != null) { ExportRecordData.Records.Add(exportRecord); ExportRecordData.RecID = exportRecord.RecordID; } } } #endregion } return(ExportRecordData); }