/// <summary> /// /// </summary> /// <returns></returns> public static DocumentData GetSitcAndRecord(Guid languageID, List <Guid> listRecord) { Guid startImplementationYear = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.StartYearVariableID)); Guid endImplementationYear = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.EndYearVariableID)); //List<Record_Variable> listRecordVariable = new List<Record_Variable>(); List <Guid> recordIdFilteredYear = new List <Guid>(); int currentYear = DateTime.Now.Year; List <RecordYear> ryear = new List <RecordYear>(); using (var context = new TSMContext()) { var filteredRecordsID = listRecord; var result1 = (from rv in context.Record_Variables where filteredRecordsID.Contains(rv.RecordID) && rv.LanguageID == languageID && (rv.VariableID == startImplementationYear || rv.VariableID == endImplementationYear) select rv).ToList(); foreach (var rec in listRecord) { RecordYear RecVar = new RecordYear(); try { var rec1 = result1.Where(r => r.RecordID == rec && r.VariableID == startImplementationYear).FirstOrDefault().Value; var rec2 = result1.Where(r => r.RecordID == rec && r.VariableID == endImplementationYear).FirstOrDefault().Value; RecVar.RecordID = rec; RecVar.StartYear = Convert.ToInt32(rec1); RecVar.EndYear = Convert.ToInt32(rec2); if (RecVar.EndYear >= currentYear) { recordIdFilteredYear.Add(rec); } } catch { } } var filterSectorRecords = (from r in context.Records where recordIdFilteredYear.Contains(r.ID) && r.Sectors.Count > 0 && r.IsDeleted == false && r.IsActive == true select r).ToList(); int serviceCount = 0; int productCount = 0; foreach (var rec in filterSectorRecords) { foreach (var r in rec.Sectors) { if (r.Type == SectorType.Product) { productCount = productCount + 1; } else if (r.Type == SectorType.Service) { serviceCount = serviceCount + 1; } } } DocumentData documentData = new DocumentData(); documentData.ResultWithSitcWTOCount = serviceCount; documentData.ResultOfOtherRecordCount = productCount; return(documentData); //var filteredRecords = GetRecordList(languageID, selectedRegions, selectedCountries, selectedSectors, selectedDocumentTypes, documentTypeVariableID); //var filteredRecordsID = filteredRecords.Select(r => r.ID).ToList(); //var filteredRecordsID = listRecord; //DocumentData documentData = new DocumentData(); //documentData.ResultWithSitcWTOCount = (from r in context.Records where recordIdFilteredYear.Contains(r.ID) && r.Sectors.Count > 0 select r).ToList().Count; //documentData.ResultOfOtherRecordCount = (from r in context.Records where recordIdFilteredYear.Contains(r.ID) && r.Sectors.Count == 0 select r).ToList().Count; //return documentData; } }
public static List <DocumentData> GetRecordPerYearWithDocumentType(Guid languageID, List <Guid> listOfRecordIds) { Guid yearVariableID = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.YearVariableID)); var documentTypeVariableID = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.DocumentTypeVariableID)); using (var context = new TSMContext()) { //var filteredRecords = GetRecordList(languageID, selectedRegions, selectedCountries, selectedSectors, selectedDocumentTypes, documentTypeVariableID); //var filteredRecordsID = filteredRecords.Select(r => r.ID).ToList(); var filteredRecordsID = listOfRecordIds; var result = from rv in context.Record_Variables where filteredRecordsID.Contains(rv.RecordID) && rv.VariableID == yearVariableID && rv.LanguageID == languageID group rv by rv.Value into grps select new { value = grps.Key, recordCount = grps.Count() }; List <Record_Variable> recordVariablesYearWise = new List <Record_Variable>(); Record_Variable recordVaraibleYearWise; foreach (var record in result) { if ((!string.IsNullOrEmpty(record.value)) && (record.value != "0")) { recordVaraibleYearWise = new Record_Variable(); recordVaraibleYearWise.Value = record.value; recordVaraibleYearWise.RecordCount = record.recordCount; recordVariablesYearWise.Add(recordVaraibleYearWise); } } recordVariablesYearWise = recordVariablesYearWise.OrderBy(rv => rv.Value).ToList(); int minYear = 1993; if (recordVariablesYearWise.Count > 0) { int.TryParse(recordVariablesYearWise.FirstOrDefault().Value.ToString(), out minYear); } //int minYear = Convert.ToInt32(recordVariablesYearWise.FirstOrDefault().Value); int maxYear = 2025; if (recordVariablesYearWise.Count > 0) { int.TryParse(recordVariablesYearWise.LastOrDefault().Value.ToString(), out maxYear); } List <DocumentData> listDocumentData = new List <DocumentData>(); for (int year = minYear; year <= maxYear; year++) { var itemYear = Convert.ToString(year); var result1 = (from rv in context.Record_Variables where filteredRecordsID.Contains(rv.RecordID) && rv.VariableID == yearVariableID && rv.Value == itemYear && rv.LanguageID == languageID select rv).ToList(); List <Record_Variable> listRecordVariableDocuemtType = new List <Record_Variable>(); foreach (var item in result1) { Record_Variable recordVariable = new Record_Variable(); recordVariable = context.Record_Variables.Where(r => r.VariableID == documentTypeVariableID && r.RecordID == item.RecordID && r.LanguageID == languageID).FirstOrDefault(); if (recordVariable != null) { listRecordVariableDocuemtType.Add(recordVariable); } } var nationalCount = (from lst in listRecordVariableDocuemtType where lst.Value == "National" select lst).ToList().Count; var internationalCount = (from lst in listRecordVariableDocuemtType where lst.Value != "National" select lst).ToList().Count; DocumentData dt = new DocumentData(); dt.Year = itemYear; dt.NationalCount = nationalCount; dt.InterNtionalCount = internationalCount; listDocumentData.Add(dt); } return(listDocumentData); } }