public IActionResult Export(SearchPortfolio searchPortfolio) { try { var fileContent = _portfolioService.ExportPortfolio(searchPortfolio); return(File(fileContent?.Result, "application/ms-excel", $"Portfolios.xlsx")); } catch (System.Exception ex) { throw ex; } }
public async Task <byte[]> ExportPortfolio(SearchPortfolio searchPortfolio = null) { return(await _portfolioManager.ExportPortfolio(searchPortfolio)); }
public async Task <byte[]> ExportPortfolio(SearchPortfolio searchPortfolio = null) { try { var comlumHeadrs = new string[] { Model.Resources.Common.PortfolioName, Model.Resources.Common.PortfolioContent, Model.Resources.Common.KVRRName }; var predicate = PredicateBuilder.New <Portfolio>(true); if (searchPortfolio != null) { if (!string.IsNullOrWhiteSpace(searchPortfolio.PortfolioName)) { predicate = predicate.And(u => !string.IsNullOrWhiteSpace(u.Title) && u.Title.Contains(searchPortfolio.PortfolioName)); } if (!string.IsNullOrWhiteSpace(searchPortfolio.PortfolioContent)) { predicate = predicate.And(u => !string.IsNullOrWhiteSpace(u.Content) && u.Content.Contains(searchPortfolio.PortfolioContent)); } if (!string.IsNullOrWhiteSpace(searchPortfolio.KVRRName)) { predicate = predicate.And(u => u.KVRRPortfolios != null && u.KVRRPortfolios.Any() && u.KVRRPortfolios.First().KVRR != null && !string.IsNullOrWhiteSpace(u.KVRRPortfolios.First().KVRR.Name) && u.KVRRPortfolios.First().KVRR.Name.Contains(searchPortfolio.KVRRName)); } } var listPortfolio = _unitOfWork.PortfolioRepository.GetAllPortfolio().Where(predicate).ToList(); using (var package = new ExcelPackage()) { var worksheet = package.Workbook.Worksheets.Add("Portfolios"); using (var cells = worksheet.Cells[1, 1, 1, 3]) { cells.Style.Font.Bold = true; } for (var i = 0; i < comlumHeadrs.Count(); i++) { worksheet.Cells[1, i + 1].Value = comlumHeadrs[i]; } var j = 2; foreach (var portfolio in listPortfolio) { worksheet.Cells["A" + j].Value = portfolio.Title; worksheet.Cells["B" + j].Value = portfolio.Content; worksheet.Cells["C" + j].Value = portfolio.KVRRPortfolios != null && portfolio.KVRRPortfolios.Any() ? portfolio.KVRRPortfolios.First().KVRR.Name : string.Empty; j++; } return(package.GetAsByteArray()); } } catch (Exception ex) { throw new ApplicationException("Export Portfolio: " + ex.Message); } }
// GET: Search public ActionResult SearchAlgorithm(string searchKey) { ViewBag.SearchText = searchKey; bool isProfolio = false; bool isSection = false; bool isSectionByName = false; bool isCompany = false; //Get the user from UserRole table //Get the useraccess from UserAccess table List <int> companyId = new List <int>(); var userComapniesData = utilObj.getUsercompanyInfo(); if (userComapniesData.companyId == null) { companyId = homeRepo.GetCompanies().Select(x => x.Company_Id).ToList(); } else { companyId = userComapniesData.companyId; } //companyId.Add(1); //companyId.Add(2); //companyId.Add(3); companyId.Sort(); var companyList = homeRepo.GetCompanies().Where(c => companyId.Contains(c.Company_Id)).Select(x => new { x.Company_Name, x.Company_Id }).OrderBy(x => x.Company_Id).ToList(); Dictionary <List <int>, string> companyObject = new Dictionary <List <int>, string>(); List <string> cList = new List <string>(); List <int> compIdList = new List <int>(); foreach (var c in companyList) { cList.Add(c.Company_Name); compIdList.Add(c.Company_Id); List <int> ids = new List <int>(); ids.Add(c.Company_Id); companyObject.Add(ids, c.Company_Name); } ViewBag.companyObject = companyObject; ViewBag.CompanyList = cList; ViewBag.CompanyIdList = compIdList; //Portfolio portfolio = db.Portfolios.Find(id); var portfolioList = homeRepo.GetPortfolios().ToList(); var selectedCompanyList = companyList.Where(x => x.Company_Name.ToLower().Contains(searchKey.ToLower())).ToList(); if (selectedCompanyList.Count > 0) { isCompany = true; ViewBag.PortFolioList = portfolioList; companyList = selectedCompanyList; } else if (searchKey.ToLower().Contains("report")) { isCompany = true; } if (("portfolio".Contains(searchKey.ToLower()) || "pal".Contains(searchKey.ToLower())) && !isCompany) { isProfolio = true; ViewBag.PortFolioList = portfolioList; } if (!isProfolio && !isCompany) { var portFolioCheck = portfolioList.Where(x => x.Portfolio_Name.ToLower().Contains(searchKey.ToLower())).ToList(); if (portFolioCheck.Count > 0) { isProfolio = true; portfolioList = portFolioCheck; ViewBag.PortFolioList = portfolioList; } } if (!isProfolio && !isCompany) { if (searchKey.ToLower().Contains("section") || searchKey.ToLower().Contains("dpb") || "digital".Contains(searchKey.ToLower()) || "picture".Contains(searchKey.ToLower()) || "benchmark".Contains(searchKey.ToLower())) { var sectionCheck = homeRepo.GetMetadatas().ToList(); if (sectionCheck.Count > 0) { var sectionList = sectionCheck; List <string> secList = new List <string>(); foreach (var sec in sectionList) { secList.Add(sec.Metadata_Name); } ViewBag.SectionName = secList; isSection = true; } } else if (!isSection && !isCompany) { var sectionCheck = homeRepo.GetMetadatas().Where(x => x.Metadata_Name.ToLower().Contains(searchKey.ToLower())).ToList(); if (sectionCheck.Count > 0) { var sectionList = sectionCheck; List <string> secList = new List <string>(); foreach (var sec in sectionList) { secList.Add(sec.Metadata_Name); } ViewBag.SectionName = secList; isSectionByName = true; } } } if (isCompany) { ViewBag.PortFolioList = portfolioList; var portfolio_Agile_Lab_byComp = homeRepo.GetPALData(); SearchByCompany searchByComp = new SearchByCompany(); List <SearchPortfolio> searchPortfolio = new List <SearchPortfolio>(); List <SearchBySection> searchCompBySection = new List <SearchBySection>(); cList = new List <string>(); compIdList = new List <int>(); companyObject = new Dictionary <List <int>, string>(); foreach (var c in companyList) { cList.Add(c.Company_Name); compIdList.Add(c.Company_Id); List <int> ids = new List <int>(); ids.Add(c.Company_Id); companyObject.Add(ids, c.Company_Name); } ViewBag.companyObject = companyObject; ViewBag.CompanyList = cList; ViewBag.CompanyIdList = compIdList; var sectionCheck = homeRepo.GetMetadatas(); if (sectionCheck.Count > 0) { var sectionList = sectionCheck; List <string> secList = new List <string>(); foreach (var sec in sectionList) { secList.Add(sec.Metadata_Name); } ViewBag.SectionName = secList; } foreach (var compIdByComp in companyList) { //Portfolio foreach (var portfByComp in portfolioList) { SearchPortfolio search = new SearchPortfolio(); var tempCompQuery = portfolio_Agile_Lab_byComp.Where(x => x.Company_Id == compIdByComp.Company_Id && x.Portfolio_Id == portfByComp.Portfolio_Id).FirstOrDefault(); search.PortfolioId = tempCompQuery != null ? tempCompQuery.Portfolio_Id : portfByComp.Portfolio_Id; search.PortfolioName = portfByComp.Portfolio_Name; search.CompanyName = compIdByComp.Company_Name; search.CurrentUsage = tempCompQuery.Current_Usage; searchPortfolio.Add(search); } //section foreach (var secitem in sectionCheck) { var tempcompQ = homeRepo.GetAllObjectives().Where(x => x.Metadata_Id == secitem.Metadata_Id && x.Company_Id == compIdByComp.Company_Id).ToList(); SearchBySection SearchCompBySection = new SearchBySection(); double score = 0; foreach (var val in tempcompQ) { double score_max = val.Score_Max != null?Convert.ToDouble(val.Score_Max) : 0; score = score + score_max; } //if (tempQ.Count > 0) { SearchCompBySection.CompanyName = compIdByComp.Company_Name; SearchCompBySection.SectionName = secitem.Metadata_Name; SearchCompBySection.Score_MAx = score; searchCompBySection.Add(SearchCompBySection); } } } searchByComp.protfolio = searchPortfolio; searchByComp.section = searchCompBySection; return(View("SearchByCompanyView", searchByComp)); } if (isProfolio && !isCompany) { var portfolio_Agile_Lab = homeRepo.GetPALData();//.Where(t => companyId.Contains(t.Company_Id)).ToList(); List <SearchPortfolio> searchPortfolio = new List <SearchPortfolio>(); foreach (var compId in companyList) { foreach (var portf in portfolioList) { SearchPortfolio search = new SearchPortfolio(); var tempQuery = portfolio_Agile_Lab.Where(x => x.Company_Id == compId.Company_Id && x.Portfolio_Id == portf.Portfolio_Id).FirstOrDefault(); search.PortfolioId = tempQuery != null ? tempQuery.Portfolio_Id : portf.Portfolio_Id; search.PortfolioName = portf.Portfolio_Name; search.CompanyName = compId.Company_Name; search.CurrentUsage = tempQuery.Current_Usage; searchPortfolio.Add(search); } } //search.CompanyName = companyList.Select(x => x.Company_Name).ToList(); //search.CompanyId = companyId; return(View("PortfolioView", searchPortfolio)); } if ((isSection || isSectionByName) && !isCompany) { List <SearchBySection> searchBySec = new List <SearchBySection>(); var sectionList = homeRepo.GetMetadatas(); // var objectives = db.Objectives.Include(o => o.Company).Include(o => o.Metadata).Include(o => o.Objectives1).ToList(); if (isSectionByName) { sectionList = homeRepo.GetMetadatas().Where(x => x.Metadata_Name.ToLower().Contains(searchKey)).ToList(); } foreach (var compId in companyList) { foreach (var secitem in sectionList) { var tempQ = homeRepo.GetAllObjectives().Where(x => x.Metadata_Id == secitem.Metadata_Id && x.Company_Id == compId.Company_Id).ToList(); SearchBySection searchbySec = new SearchBySection(); double score = 0; foreach (var val in tempQ) { double score_max = val.Score_Max != null?Convert.ToDouble(val.Score_Max) : 0; score = score + score_max; } //if (tempQ.Count > 0) { searchbySec.CompanyName = compId.Company_Name; searchbySec.SectionName = secitem.Metadata_Name; searchbySec.Score_MAx = score; searchBySec.Add(searchbySec); } } } return(View("SearchBySectionView", searchBySec)); } return(View("NoResultView")); }