public static string GetRecordNameByID(Guid recordID, Guid langID) { string recordName = ""; Record_Language records_language = new Record_Language(); using (var context = new TSMContext()) { records_language = context.Record_Languages.Where(r => r.ID == recordID && r.LanguageID == langID).FirstOrDefault(); recordName = records_language.Name; } return(recordName); }
/// <summary> /// Get Record Language /// </summary> /// <param name="id"></param> /// <param name="languageID"></param> /// <returns></returns> public static Record_Language GetRecordLanguage(Guid id, Guid languageID) { Record_Language recordLanguage = null; using (var context = new TSMContext()) { var record = context.Records.Include("Record_Languages").Include("Variables"). Include("Documents").Include("Countries"). Include("Regions").Include("Sectors").Where(r => r.ID == id && r.IsDeleted == false).FirstOrDefault(); recordLanguage = record.Record_Languages.Where(rl => rl.LanguageID == languageID).FirstOrDefault(); recordLanguage.Record = record; return(recordLanguage); } }
/// <summary> /// Get Country Names /// </summary> /// <param name="RecordLanguage"></param> /// <param name="languageID"></param> /// <returns></returns> private string GetCountryNames(Record_Language recordLanguage, Guid languageID) { var countryLanguages = CountryService.GetCountries(languageID); var countries = recordLanguage.Record.Countries; string countryName = string.Empty; bool isCoOrdinateSet = false; this.CountryCodes = string.Empty; //Read Country co-ordinates from json file string json = string.Empty; string jsonFilePath = HttpContext.Current.Server.MapPath("~/CountryJson/CountryJSON.json"); List <CountryJSON> countryJSONData = new List <CountryJSON>(); if (File.Exists(jsonFilePath)) { json = File.ReadAllText(jsonFilePath); countryJSONData = new JavaScriptSerializer().Deserialize <List <CountryJSON> >(json); } if (countries != null) { foreach (var country in countries) { var countryLanguage = countryLanguages.Where(cl => cl.ID == country.ID).FirstOrDefault(); if (countryLanguage != null) { countryName += countryLanguage.Name + ", "; this.CountryCodes += countryLanguage.Country.ISOCode + ","; if (!isCoOrdinateSet) { var data = countryJSONData.Where(cj => cj.Name == countryLanguage.Name).FirstOrDefault(); if (data != null) { this.Latitude = data.Latitude; this.Longitude = data.Longitude; isCoOrdinateSet = true; } } } } } this.CountryCodes = this.CountryCodes.TrimEnd(','); return(countryName.Trim().TrimEnd(',')); }
/// <summary> /// Get Region Name /// </summary> /// <param name="recordLanguage"></param> /// <param name="languageID"></param> /// <returns></returns> private string GetRegionName(Record_Language recordLanguage, Guid languageID) { var regionLanguages = RegionService.GetRegions(languageID); var region = recordLanguage.Record.Regions.Where(r => r.Type == RegionType.Geographical).FirstOrDefault(); string regionName = string.Empty; if (region != null) { var regionLanguage = regionLanguages.Where(rl => rl.ID == region.ID).FirstOrDefault(); if (regionLanguage != null) { regionName = regionLanguage.Name; } } return(regionName); }
/// <summary> /// Populate Record /// </summary> /// <param name="id"></param> /// <param name="languageID"></param> public void PopulateRecord(Guid id, Guid languageID) { try { //Populate record if (id != Guid.Empty) { this.Record = RecordService.GetRecord(id); if (this.Record != null && this.Record.Record_Languages != null && this.Record.Record_Languages.Count > 0) { Record_Language recordLanguage = new Record_Language(); this.IsActive = this.Record.IsActive; this.IsPublic = this.Record.IsPublic; if (this.Record.Record_Languages.Any(rl => rl.LanguageID == languageID)) { recordLanguage = this.Record.Record_Languages.Where(rl => rl.LanguageID == languageID).FirstOrDefault(); } else // populate with default language id { var defaultLanguageID = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.DefaultLanguageID)); recordLanguage = this.Record.Record_Languages.Where(rl => rl.LanguageID == defaultLanguageID).FirstOrDefault(); } //populate name if (recordLanguage != null) { this.Name = recordLanguage.Name; this.Record.Record_Languages = new List<Record_Language>(); this.Record.Record_Languages.Add(recordLanguage); } //Populate selected Countries if (this.Record.Countries != null && this.Record.Countries.Count > 0) { this.SelectedCountries = (from c in this.Record.Countries select c.ID).ToList(); } //Populate selected Regions if (this.Record.Regions != null && this.Record.Regions.Count > 0) { this.SelectedRegions = (from r in this.Record.Regions select r.ID).ToList(); } //Populate selected Sectors if (this.Record.Sectors != null && this.Record.Sectors.Count > 0) { this.SelectedSectors = (from s in this.Record.Sectors select s.ID).ToList(); } if (this.SelectedSectors != null && this.SelectedSectors.Count > 0) { this.Sector_Languages = PrioritySectorService.GetSectorLanguage(this.SelectedSectors); } //populate documents this.Documents = string.Empty; if (this.Record.Documents != null && this.Record.Documents.Count > 0) { foreach (var document in this.Record.Documents) { this.Documents += document.Path + "|"; } this.Documents = this.Documents.TrimEnd('|'); } } } } catch (Exception ex) { ErrorLog.WriteLog("ManageRecordModel", "PopulateRecord", ex, string.Empty); } }