Exemple #1
0
        public ActionResult GetSectors(int?page, int?sortColumnIndex, int?sortDirection, string searchText)
        {
            ManageSectorModel SectorModel = new ManageSectorModel();
            SearchAttributes  searchParam = new SearchAttributes();

            searchParam.CurrentPageNumber = (page.HasValue && page.Value > 0) ? page.Value : 1;
            searchParam.RecordsPerPage    = AppSettingsUtility.GetInt(AppSettingsKeys.RecordsPerPage);
            searchParam.SortColumnIndex   = (sortColumnIndex.HasValue && sortColumnIndex.Value > 0) ? sortColumnIndex.Value : 1;
            searchParam.SortDirection     = (sortDirection.HasValue && sortDirection.Value == 1) ? Entity.SortDirection.Descending : Entity.SortDirection.Ascending;

            if (!string.IsNullOrEmpty(searchText))
            {
                searchParam.SearchText = searchText;
            }

            SectorModel.SearchParam = searchParam;
            SectorModel.GetAllSector(searchParam);

            //for Ajax Specific Request
            if (Request.IsAjaxRequest())
            {
                return(View("~/Views/Shared/PartialViews/Admin/Sector/_SectorList.cshtml", SectorModel));
            }
            else
            {
                return(View("~/Views/Admin/Sector/SectorList.cshtml", SectorModel));
            }
        }
Exemple #2
0
        /// <summary>
        /// Get Records By Search Param
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <Record> GetRecords(SearchAttributes searchParam, Guid langID)
        {
            IEnumerable <Record> records;
            List <Record>        lstRecord = new List <Record>();

            using (var context = new TSMContext())
            {
                records = context.Records.Include("Record_Languages").Where(r => r.IsDeleted == false);

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText.ToLower();
                    records = records.Where(rl => rl.Record_Languages[0].Name.ToLower().Contains(searchText));
                }

                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    records = searchParam.SortDirection == SortDirection.Ascending ? records.OrderBy(r => r.Record_Languages[0].Name) : records.OrderByDescending(r => r.Record_Languages[0].Name);
                    break;
                }
                searchParam.TotalRecordCount = records.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(records.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #3
0
        /// <summary>
        /// Get Variable By Search Param and Language
        /// </summary>
        /// <param name="searchParam"></param>
        /// <param name="LanguageId"></param>
        /// <returns></returns>
        public static List <Variable> GetVariables(SearchAttributes searchParam, Guid LanguageId)
        {
            List <Variable> lstVariables = new List <Variable>();

            using (var context = new TSMContext())
            {
                lstVariables = context.Variables.Include("Variable_Languages").Where(c => c.IsDeleted == false).ToList();

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText.ToLower();
                    lstVariables = lstVariables.Where(u => (u.Variable_Languages[0].Name.ToLower().Contains(searchText)) || (u.Variable_Languages[0].DisplayName.ToLower().Contains(searchText))).ToList();
                }
                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    lstVariables = searchParam.SortDirection == SortDirection.Ascending ? lstVariables.OrderBy(u => u.Variable_Languages[0].Name).ToList() : lstVariables.OrderByDescending(u => u.Variable_Languages[0].Name).ToList();
                    break;

                case 2:
                    lstVariables = searchParam.SortDirection == SortDirection.Ascending ? lstVariables.OrderBy(u => u.Variable_Languages[0].DisplayName).ToList() : lstVariables.OrderByDescending(u => u.Variable_Languages[0].DisplayName).ToList();
                    break;
                }
                searchParam.TotalRecordCount = lstVariables.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(lstVariables.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #4
0
        /// <summary>
        /// Get Users
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <User> GetUsers(SearchAttributes searchParam)
        {
            IEnumerable <User> users;

            using (var context = new TSMContext())
            {
                users = context.Users.Where(u => !u.IsDeleted.Value);
                //users = context.Users;

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText.ToLower();
                    users = users.Where(u => u.Email.ToLower().Contains(searchText) || u.FirstName.ToLower().Contains(searchText) || u.LastName.ToLower().Contains(searchText));
                }

                switch (searchParam.SortColumnIndex)
                {
                case 2:
                    users = searchParam.SortDirection == SortDirection.Ascending ? users.OrderBy(u => u.Email) : users.OrderByDescending(u => u.Email);
                    break;

                case 1:
                    users = searchParam.SortDirection == SortDirection.Ascending ? users.OrderBy(u => u.FirstName).ThenBy(u => u.LastName) : users.OrderByDescending(u => u.FirstName).ThenByDescending(u => u.LastName);
                    break;
                }

                searchParam.TotalRecordCount = users.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);
                //return users.ToList();
                return(users.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #5
0
        /// <summary>
        /// Get Record Language By Search Param
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <Record_Language> GetRecordLanguages(SearchAttributes searchParam, Guid langID)
        {
            //IEnumerable<Record> records;
            //List<Record> lstRecord = new List<Record>();

            using (var context = new TSMContext())
            {
                var lstrecordLanguage = context.Record_Languages.Include("Record").Where(r => r.Record.IsDeleted == false && r.Record.IsActive == true && r.LanguageID == langID);

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText.ToLower();
                    lstrecordLanguage = lstrecordLanguage.Where(rl => rl.Name.ToLower().Contains(searchText));
                }

                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    lstrecordLanguage = searchParam.SortDirection == SortDirection.Ascending ? lstrecordLanguage.OrderBy(r => r.Name) : lstrecordLanguage.OrderByDescending(r => r.Name);
                    break;
                }
                searchParam.TotalRecordCount = lstrecordLanguage.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(lstrecordLanguage.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
        public ActionResult Records(int?page, int?sortColumnIndex, int?sortDirection, string searchText)
        {
            RecordListModel  model       = new RecordListModel();
            SearchAttributes searchParam = new SearchAttributes();

            searchParam.CurrentPageNumber = (page.HasValue && page.Value > 0) ? page.Value : 1;
            searchParam.RecordsPerPage    = AppSettingsUtility.GetInt(AppSettingsKeys.RecordsPerPage);
            if (sortColumnIndex.HasValue)
            {
                searchParam.SortColumnIndex = sortColumnIndex.Value;
            }
            else
            {
                searchParam.SortColumnIndex = 1;
            }
            searchParam.SortDirection = (sortDirection.HasValue && sortDirection.Value == 1) ? Entity.SortDirection.Descending : Entity.SortDirection.Ascending;

            if (!string.IsNullOrEmpty(searchText))
            {
                searchParam.SearchText = searchText;
            }
            model.SearchParam = searchParam;
            model.Populate(searchParam);

            //for Ajax Specific Request
            if (Request.IsAjaxRequest())
            {
                return(View("~/Views/Shared/PartialViews/Admin/Record/_RecordList.cshtml", model));
            }
            else
            {
                return(View("~/Views/Admin/Record/RecordList.cshtml", model));
            }
        }
Exemple #7
0
        /// <summary>
        /// Get Pages
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <Content> GetPages(SearchAttributes searchParam)
        {
            IEnumerable <Content> pages;

            using (var context = new TSMContext())
            {
                pages = context.Contents.Where(c => c.IsActive && c.IsPublic && c.Type != ContentType.News);

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText;
                    pages = pages.Where(p => p.Type.ToString().Contains(searchText));
                }

                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    pages = searchParam.SortDirection == SortDirection.Ascending ? pages.OrderBy(p => p.Type.ToString()) : pages.OrderByDescending(p => p.Type.ToString());
                    break;
                }

                searchParam.TotalRecordCount = pages.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(pages.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #8
0
        /// <summary>
        /// Get Content By SearchAttributes
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <Content> GetContents(SearchAttributes searchParam, Guid langID)
        {
            List <Content> listContent = new List <Content>();

            using (var context = new TSMContext())
            {
                listContent = context.Contents.Include("Content_Languages").Where(c => c.IsActive && c.Type == ContentType.News).ToList().FindAll(c => c.Content_Languages.Find(cl => cl.LanguageID == langID) != null);

                // listContent=from lc in listContent join cl in context.Content_Languages on lc.ID equals cl.ID where cl.LanguageID==langID select lc;
                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText;
                    listContent = listContent.Where(u => u.Content_Languages.Any(v => v.Title.ToLower().Contains(searchText.ToLower()) && v.LanguageID == langID)).ToList();
                }
                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    listContent = searchParam.SortDirection == SortDirection.Ascending ? listContent.OrderBy(u => u.ContentDate).ToList() : listContent.OrderByDescending(u => u.ContentDate).ToList();
                    break;

                case 2:
                    listContent = searchParam.SortDirection == SortDirection.Ascending ? listContent.Where(u => u.Content_Languages.Count > 0).OrderBy(u => u.Content_Languages[0].Title).ToList() : listContent.Where(u => u.Content_Languages.Count > 0).OrderByDescending(u => u.Content_Languages[0].Title).ToList();
                    break;
                }
                searchParam.TotalRecordCount = listContent.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(listContent.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #9
0
        /// <summary>
        /// Get Content Languages by search attribute
        /// </summary>
        /// <param name="searchParam"></param>
        /// <param name="langID"></param>
        /// <returns></returns>
        public static List <Content_Language> GetContentLanguages(SearchAttributes searchParam, Guid langID)
        {
            using (var context = new TSMContext())
            {
                var contentLanguages = context.Content_Languages.Include("Content").Where(cl => cl.Content.IsActive && cl.Content.Type == ContentType.News && cl.LanguageID == langID);
                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText;
                    contentLanguages = contentLanguages.Where(cl => cl.Title.ToLower().Contains(searchText.ToLower()));
                }


                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    contentLanguages = searchParam.SortDirection == SortDirection.Ascending ? contentLanguages.OrderBy(cl => cl.Content.ContentDate) : contentLanguages.OrderByDescending(cl => cl.Content.ContentDate);
                    break;

                case 2:
                    contentLanguages = searchParam.SortDirection == SortDirection.Ascending ? contentLanguages.OrderBy(cl => cl.Title) : contentLanguages.OrderByDescending(cl => cl.Title);
                    break;
                }
                searchParam.TotalRecordCount = contentLanguages.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(contentLanguages.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #10
0
        /// <summary>
        /// Search Param
        /// </summary>
        /// <param name="CacheKey"></param>
        public static SearchAttributes GetSearchParam()
        {
            SearchAttributes searchParam = new SearchAttributes();

            searchParam.CurrentPageNumber = 1;
            searchParam.RecordsPerPage    = 20000;
            searchParam.SortColumnIndex   = 1;
            searchParam.SortDirection     = TSM.Entity.SortDirection.Descending;

            return(searchParam);
        }
Exemple #11
0
 /// <summary>
 /// Populate Users
 /// </summary>
 /// <param name="search"></param>
 public void Populate(SearchAttributes searchParam)
 {
     try
     {
         this.Users       = UserService.GetUsers(searchParam);
         this.SearchParam = searchParam;
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("ManageUserModel", "Populate", ex, "");
     }
 }
Exemple #12
0
 /// <summary>
 /// Populate Pages
 /// </summary>
 /// <param name="search"></param>
 public void Populate(SearchAttributes searchParam)
 {
     try
     {
         this.Pages       = PageService.GetPages(searchParam);
         this.SearchParam = searchParam;
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("PageListModel", "Populate", ex, "");
     }
 }
Exemple #13
0
 /// <summary>
 /// Populate News List
 /// </summary>
 public void Populate(SearchAttributes searchParam)
 {
     try
     {
         List <Content_Language> NewsCont = NewsService.GetContentLanguages(searchParam, TSM.Model.TSMContext.CurrentSiteLanguageID);
         //this.NewsContents = NewsService.GetContents(searchParam,TSM.Model.TSMContext.CurrentSiteLanguageID).Where(z => z.Type == ContentType.News).ToList();
         this.NewsContents = NewsCont.Select(n => n.Content).Where(z => z.Type == ContentType.News).ToList();
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("ManageNewsModel", "Populate", ex, "");
     }
 }
Exemple #14
0
 /// <summary>
 /// Get All Sectors
 /// </summary>
 /// <returns></returns>
 public void GetAllSector(SearchAttributes searchParam)
 {
     try
     {
         this.lstSector   = new List <TSMSector>();
         this.SearchParam = searchParam;
         this.lstSector   = SectorService.GetSectors(searchParam, TSMContext.CurrentLanguageID);
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("ManageUserModel", "Populate", ex, "");
     }
 }
Exemple #15
0
 /// <summary>
 /// Populate Records
 /// </summary>
 /// <param name="search"></param>
 public void Populate(SearchAttributes searchParam)
 {
     try
     {
         var lstRecordLanguage = RecordService.GetRecordLanguages(searchParam, TSM.Model.TSMContext.CurrentSiteLanguageID);
         this.Records = lstRecordLanguage.Select(r => r.Record).ToList();
         //this.Records = RecordService.GetRecords(searchParam,TSM.Model.TSMContext.CurrentSiteLanguageID);
         this.SearchParam = searchParam;
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("RecordListModel", "Populate", ex, "");
     }
 }
Exemple #16
0
 public void Populate(SearchAttributes searchParam)
 {
     try
     {
         var variableLanguages = VariableService.GetVariableLanguages(searchParam, TSMContext.CurrentLanguageID);
         this.Variables = variableLanguages.Select(v => v.Variable).ToList();
         // this.Variables = VariableService.GetVariables();
         this.SearchParam = searchParam;
     }
     catch (Exception ex)
     {
         ErrorLog.WriteLog("ManageVariableModel", "Populate", ex, "");
     }
 }
        public ActionResult ResultSearch(SearchAttributes searchParameters)
        {
            string strWithoutSpaces = Regex.Replace(searchParameters.SearchQuery, @"^\s+", "");

            strWithoutSpaces = Regex.Replace(strWithoutSpaces, @"\s+$", "");

            if (searchParameters.SearchQuery != null)
            {
                return(RedirectToAction(
                           "ResultSearch",
                           "Main",
                           new { searchQuery = strWithoutSpaces, selectSearch = searchParameters.Select }));
            }

            return(HttpNotFound());
        }
        public PartialViewResult SearchMenu()
        {
            var model = new SearchAttributes();

            model.SelectList = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = ((int)SearchType.ByNamesOrArticles).ToString(), Text = "Articles"
                },
                new SelectListItem {
                    Value = ((int)SearchType.ByTags).ToString(), Text = "Tags"
                },
                new SelectListItem {
                    Value = ((int)SearchType.ByDate).ToString(), Text = "Date"
                }
            };
            return(PartialView(model));
        }
Exemple #19
0
        public ActionResult PopulateAdvanceSearchFilter(string[] region, string[] country, string[] sector, string[] document, string[] year,
                                                        string[] period, string[] last_Update, string[] counterpart, string[] DocCheckboxData, string[] thematicCheckboxData,
                                                        string[] designProcessCheckboxData, string[] pagesize, string[] page, int?sortColumnIndex, int?sortDirection)
        {
            SearchMapModel model = new SearchMapModel();

            #region [Page]
            int pageSize = 5;
            if (pagesize != null)
            {
                int.TryParse(pagesize[0], out pageSize);
            }
            int Pages = 1;
            if (page != null)
            {
                int.TryParse(page[0], out Pages);
            }
            #endregion

            SearchAttributes searchParam = new SearchAttributes();
            searchParam.CurrentPageNumber = Pages;
            // searchParam.RecordsPerPage = AppSettingsUtility.GetInt(AppSettingsKeys.RecordsPerPage);
            searchParam.RecordsPerPage = pageSize;
            if (sortColumnIndex.HasValue)
            {
                searchParam.SortColumnIndex = sortColumnIndex.Value;
            }
            else
            {
                searchParam.SortColumnIndex = 1;
            }
            searchParam.SortDirection = (sortDirection.HasValue && sortDirection.Value == 1) ? Entity.SortDirection.Descending : Entity.SortDirection.Ascending;
            model.SearchParam         = searchParam;
            model.PageSize            = pageSize;
            List <RecordData> recordDataList = new List <RecordData>();

            model.GetFilterRecordInformation(region, country, sector, document, year, period, last_Update, counterpart,
                                             DocCheckboxData, thematicCheckboxData, designProcessCheckboxData, pageSize, searchParam, sortColumnIndex, sortDirection, out recordDataList);

            return(View("~/Views/Shared/PartialViews/search/_RecordFilter.cshtml", model));
        }
        /// <summary>
        /// Populate
        /// </summary>
        /// <param name="query"></param>
        public void Populate(string query, int pageNo)
        {
            this.Query = query;
            if (string.IsNullOrEmpty(query))
            {
                return;
            }

            string indexPath = HttpContext.Current.Server.MapPath("~/LuceneIndex/");
            var    result    = SiteSearchService.Search(query, indexPath);

            //Implement Paging
            this.SearchParam = new SearchAttributes();
            this.SearchParam.RecordsPerPage   = 10;
            this.SearchParam.TotalRecordCount = result.Count;
            SearchParam.TotalPages            = (int)Math.Ceiling((double)SearchParam.TotalRecordCount / SearchParam.RecordsPerPage);
            SearchParam.CurrentPageNumber     = pageNo;

            this.SearchResult = result.Skip((SearchParam.CurrentPageNumber - 1) * SearchParam.RecordsPerPage)
                                .Take(SearchParam.RecordsPerPage).ToList();
        }
Exemple #21
0
        /// <summary>
        /// Page Action Result
        /// </summary>
        /// <returns></returns>
        public ActionResult Pages(int?page, int?sortColumnIndex, int?sortDirection)
        {
            PageListModel    model       = new PageListModel();
            SearchAttributes searchParam = new SearchAttributes();

            searchParam.CurrentPageNumber = (page.HasValue && page.Value > 0) ? page.Value : 1;
            searchParam.RecordsPerPage    = AppSettingsUtility.GetInt(AppSettingsKeys.RecordsPerPage);
            searchParam.SortColumnIndex   = 1;
            searchParam.SortDirection     = (sortDirection.HasValue && sortDirection.Value == 1) ? Entity.SortDirection.Descending : Entity.SortDirection.Ascending;

            model.Populate(searchParam);

            //for Ajax Specific Request
            if (Request.IsAjaxRequest())
            {
                return(View("~/Views/Shared/PartialViews/Admin/Page/_PageList.cshtml", model));
            }
            else
            {
                return(View("~/Views/Admin/Page/PageList.cshtml", model));
            }
        }
Exemple #22
0
        /// <summary>
        /// Get Sectors For Listing
        /// </summary>
        /// <param name="searchParam"></param>
        /// <returns></returns>
        public static List <TSMSector> GetSectors(SearchAttributes searchParam, Guid LanguageId)
        {
            IEnumerable <TSMSector> TSMsector;

            using (var context = new TSMContext())
            {
                TSMsector = context.TSMSector.Where(u => u.IsDeleted == false);

                if (!string.IsNullOrEmpty(searchParam.SearchText))
                {
                    string searchText = searchParam.SearchText;
                    TSMsector = TSMsector.Where(u => u.Name.ToLower().Contains(searchText.ToLower()));
                }

                switch (searchParam.SortColumnIndex)
                {
                case 1:
                    TSMsector = searchParam.SortDirection == SortDirection.Ascending ? TSMsector.OrderBy(u => u.NomenclatureType) : TSMsector.OrderByDescending(u => u.NomenclatureType);
                    break;

                case 2:
                    TSMsector = searchParam.SortDirection == SortDirection.Ascending ? TSMsector.OrderBy(u => u.Type) : TSMsector.OrderByDescending(u => u.Type);
                    break;

                case 3:
                    TSMsector = searchParam.SortDirection == SortDirection.Ascending ? TSMsector.OrderBy(u => u.Name) : TSMsector.OrderByDescending(u => u.Name);
                    break;
                }

                searchParam.TotalRecordCount = TSMsector.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(TSMsector.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #23
0
        public static List <Content> GetContents(SearchAttributes searchParam)
        {
            List <Content> listContent = new List <Content>();

            using (var context = new TSMContext())
            {
                listContent = context.Contents.Include("Content_Languages").Where(c => c.IsActive).OrderBy(c => c.Type.ToString()).ToList();
                switch (searchParam.SortColumnIndex)
                {
                case 2:
                    listContent = searchParam.SortDirection == SortDirection.Ascending ? listContent.OrderBy(u => u.Content_Languages[0].SubTitle).ToList() : listContent.OrderByDescending(u => u.Content_Languages[0].SubTitle).ToList();
                    break;

                case 1:
                    listContent = searchParam.SortDirection == SortDirection.Ascending ? listContent.OrderBy(u => u.Content_Languages[0].Title).ToList() : listContent.OrderByDescending(u => u.Content_Languages[0].Title).ToList();
                    break;
                }
                searchParam.TotalRecordCount = listContent.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(listContent.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        /// <exception cref="NotImplementedException"></exception>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(ObjectStructureName))
            {
                throw new ArgumentException($"Required paramater '{nameof(ObjectStructureName)}' was not given.");
            }

            var sb = new StringBuilder();

            sb.Append($"{ObjectStructureName}?");

            if (Select != null && Select.Any())
            {
                var selectSb = new StringBuilder("oslc.select=");
                foreach (var att in Select)
                {
                    selectSb.Append($"{att}{SELECT_SEPERATOR}");
                }

                var selectStr = selectSb.ToString();
                if (selectStr.EndsWith(SELECT_SEPERATOR))
                {
                    selectStr = selectStr.Remove(selectStr.Length - SELECT_SEPERATOR.Length);
                }

                sb.Append(selectStr);
            }
            else
            {
                sb.Append("oslc.select=*");
            }

            if (SearchAttributes.Any() && !string.IsNullOrEmpty(SearchTerm))
            {
                var searchSb = new StringBuilder("&searchAttributes=");
                foreach (var attribute in SearchAttributes)
                {
                    searchSb.Append($"{attribute}{SELECT_SEPERATOR}");
                }

                var searchStr = searchSb.ToString();
                if (searchStr.EndsWith(SELECT_SEPERATOR))
                {
                    searchStr = searchStr.Remove(searchStr.Length - SELECT_SEPERATOR.Length);
                }

                sb.Append(searchStr);
                sb.Append($"&oslc.searchTerms=\"{SearchTerm}\"");
            }

            if (OrderBy != null)
            {
                sb.Append("&orderBy=");

                sb.Append(OrderByDescending ? "-" : "%2B");

                sb.Append(OrderBy);
            }

            if (PageSize != null && PageSize > 0)
            {
                sb.Append($"&oslc.pageSize={PageSize}");

                if (PageNumber != null && PageNumber > 1)
                {
                    sb.Append($"&pageno={PageNumber}");
                }
            }

            if (UseLean)
            {
                sb.Append("&lean=1");
            }

            return(sb.ToString());
        }
Exemple #25
0
        public static List <Record> GetFilterRecordInformation(List <Guid> recordID, int pageSize, SearchAttributes searchParam)
        {
            List <Record> records = new List <Record>();

            using (var context = new TSMContext())
            {
                var filteredRecordsID = recordID;

                var recordData = context.Records.Include("Record_Languages").Include("Variables").
                                 Include("Documents").Include("Countries").
                                 Include("Regions").Include("Sectors").Where(r => filteredRecordsID.Contains(r.ID)).ToList();

                records = recordData.ToList();
                searchParam.TotalRecordCount = records.Count();
                searchParam.TotalPages       = (int)Math.Ceiling((double)searchParam.TotalRecordCount / searchParam.RecordsPerPage);

                return(records.Skip((searchParam.CurrentPageNumber - 1) * searchParam.RecordsPerPage)
                       .Take(searchParam.RecordsPerPage).ToList());
            }
        }
Exemple #26
0
        public static List <Record> GetFilterRecordInformationForSearch(List <Guid> recordID, int pageSize, SearchAttributes searchParam)
        {
            List <Record> records        = new List <Record>();
            List <Record> listRecordData = new List <Record>();

            using (var context = new TSMContext())
            {
                var filteredRecordsID = recordID;
                var recordData        = context.Records.Include("Record_Languages").Include("Variables").
                                        Include("Documents").Include("Countries").
                                        Include("Regions").Include("Sectors").ToList();
                listRecordData = recordData;
                return(listRecordData);
            }
        }
Exemple #27
0
        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);
        }
        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
            }
        }
Exemple #29
0
        public ActionResult ExportPDF(string[] region, string[] country, string[] sector, string[] document, string[] year,
                                      string[] period, string[] last_Update, string[] counterpart, string[] DocCheckboxData, string[] thematicCheckboxData,
                                      string[] designProcessCheckboxData, string[] pagesize, string[] page, int?sortColumnIndex, int?sortDirection, string filetype)
        {
            SearchMapModel model = new SearchMapModel();

            #region [Page]
            int pageSize = 20000;
            //if (pagesize != null)
            //{
            //    int.TryParse(pagesize[0], out pageSize);
            //}
            int Pages = 1;
            if (page != null)
            {
                int.TryParse(page[0], out Pages);
            }
            #endregion

            SearchAttributes searchParam = new SearchAttributes();
            searchParam.CurrentPageNumber = Pages;
            // searchParam.RecordsPerPage = AppSettingsUtility.GetInt(AppSettingsKeys.RecordsPerPage);
            searchParam.RecordsPerPage = pageSize;
            if (sortColumnIndex.HasValue)
            {
                searchParam.SortColumnIndex = sortColumnIndex.Value;
            }
            else
            {
                searchParam.SortColumnIndex = 1;
            }
            searchParam.SortDirection = (sortDirection.HasValue && sortDirection.Value == 1) ? Entity.SortDirection.Descending : Entity.SortDirection.Ascending;
            model.SearchParam         = searchParam;
            List <ExportRecordData> exportRecordData = new List <ExportRecordData>();

            exportRecordData = model.GetExportFilteredData(region, country, sector, document, year, period, last_Update, counterpart,
                                                           DocCheckboxData, thematicCheckboxData, designProcessCheckboxData, pageSize, model.SearchParam, sortColumnIndex, sortDirection);
            ExportList <ExportRecordData> exp = new ExportList <ExportRecordData>();

            string filePathExport = string.Empty;
            exp.PathTemplateFolder = Server.MapPath("~/ExportTemplates/");

            if (filetype == "excel")
            {
                filePathExport = Server.MapPath("~/ExportFiles/" + DateTime.Now.Ticks + ".xlsx");
                exp.ExportTo(exportRecordData, ExportToFormat.Excel2007, filePathExport);
            }
            else if (filetype == "pdf")
            {
                filePathExport = Server.MapPath("~/ExportFiles/" + DateTime.Now.Ticks + ".csv");
                exp.ExportTo(exportRecordData, ExportToFormat.CSV, filePathExport);
            }
            else if (filetype == "csv")
            {
                filePathExport = Server.MapPath("~/ExportFiles/" + DateTime.Now.Ticks + ".csv");
                exp.ExportTo(exportRecordData, ExportToFormat.CSV, filePathExport);
            }
            else
            {
                filePathExport = Server.MapPath("~/ExportFiles/" + DateTime.Now.Ticks + ".csv");
                exp.ExportTo(exportRecordData, ExportToFormat.CSV, filePathExport);
            }

            //return this.File(filePathExport, "application/octet-stream", System.IO.Path.GetFullPath(filePathExport));
            return(Json(new { fileurl = "/ExportFiles/" + System.IO.Path.GetFileName(filePathExport) }, JsonRequestBehavior.AllowGet));
        }
Exemple #30
0
        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).");
        }