// // GET: /Company/Details/5 public ActionResult Details(string id) { var companyModel = new CompanyRepository().GetByRowKey(id); var companyViewModel = new CompanyViewModel( companyModel, CompanySubscriptionHelper.GetAllCompanySubscriptionsFromCache().ToArray(), new CountryRepository().GetAll().ToArray(), new SubscriptionProductRepository().GetAll().ToArray()); return(MenuView(companyViewModel, "Find A Product", "SubMenuFindAProduct", string.Empty)); }
public PartialViewResult GetSearchResultsAsPartialView(string country = "", int page = 1, int productsPerPage = 25, string categoryID = "#00000000-0000-0000-0000-000000000000", string searchText = "") { var companySubscriptionArray = CompanySubscriptionHelper.GetAllCompanySubscriptionsFromCache().ToArray(); var countryArray = new CountryRepository().GetAll().ToArray(); var subscriptionProductArray = new SubscriptionProductRepository().GetAll().ToArray(); var categoryArray = CategoryHelper.GetAllCategoriesFromCache().ToArray(); var productArray = ProductHelper.GetAllProductsFromCache().ToArray(); var companyArray = CompanyHelper.GetAllCompaniesFromCache().Where(c => c.Country != null).ToArray(); CategoryModel parentCategory = null; var cleanCategoryID = categoryID.Replace("#", string.Empty); //get parent category of sub categories if ((categoryID != null)) { parentCategory = (from category in categoryArray where category.RowKey.Equals(cleanCategoryID) select category).SingleOrDefault();//will return null for all cateogries } //check if root category was selected if (parentCategory == null) { parentCategory = CategoryHelper.AllCategories; } var childCategoryArray = new List <CategoryModel>().ToArray(); if (parentCategory != CategoryHelper.AllCategories) { childCategoryArray = (from child in categoryArray where child.ParentID == cleanCategoryID select child).ToArray(); } else { childCategoryArray = (from child in categoryArray where child.ParentID == "0" select child).ToArray(); } var categoryAndDescendantsList = CategoryHelper.GetAllDescendantsFlattened(cleanCategoryID, categoryArray, childCategoryArray).ToList(); var results = new List <CompanyModel>(); //search by searchtext if (searchText != string.Empty) { var companyFiltered_SearchText = companyArray.Where(c => ( c.Name.ToLower().Contains(searchText) || c.ProductsOrServices.ToLower().Contains(searchText)) ).Distinct().ToArray(); if (country == string.Empty) { results.AddRange(companyFiltered_SearchText.Distinct()); } else { results.AddRange(companyFiltered_SearchText.Where(c => c.Country.ToLower() == country.ToLower()).Distinct()); } } else {//ignore searchtext if (country == string.Empty || country.ToLower() == "all countries") { results.AddRange(companyArray); } else { results.AddRange(companyArray.Where(c => c.Country.ToLower() == country.ToLower())); } } var resultsFiltered = new List <CompanyModel>(); //filter results by category if specified if (parentCategory != CategoryHelper.AllCategories) { categoryAndDescendantsList.Add(parentCategory); resultsFiltered = results.Where(r => ProductHelper.DoesHaveProductsInCategory( productArray.Where(p => p.CompanyID == r.RowKey).ToArray(), categoryAndDescendantsList.ToArray(), companyArray, r.RowKey )) .Distinct().ToList(); } else { resultsFiltered = results; } var companyresultArray = resultsFiltered.Select(c => new CompanyViewModel(c, companySubscriptionArray, countryArray, subscriptionProductArray)).ToArray(); int totalPages = 1; if (companyArray.Count() != 0) { totalPages = companyresultArray.Count() / productsPerPage; } var pagedResultArray = companyresultArray.OrderBy(c => c.CompanyData.Name).Skip(productsPerPage * (page - 1)).Take(productsPerPage).ToArray(); return(PartialView(new CompanySearchResultViewModel(pagedResultArray, productsPerPage, page, parentCategory, totalPages, companyresultArray.Count()))); }
public FileResult SalesReportReseller(string userid = "") { string userRowKey = string.Empty; if (userid == string.Empty) { var user = Membership.GetUser(); userRowKey = (user.ProviderUserKey as string); } else { userRowKey = userid; } var chamber = new CompanyRepository().GetByRowKey(userRowKey); var historyList = new List <TransactionHistoryModel>(); //get companies var allCompanies = CompanyHelper.GetAllCompaniesFromCache(); //get subscriptions var allSubscriptions = CompanySubscriptionHelper.GetAllCompanySubscriptionsFromCache(); //get transactions var allTransactions = new TransactionRepository().GetAll().ToArray(); //get all products var allProducts = new ProductRepository().GetAll().ToArray(); //query for list of subscriptions for members var allHistoryTier1 = allSubscriptions.Where(s => s.Chamber1 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray(); var allHistoryTier2 = allSubscriptions.Where(s => s.Chamber2 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray(); var allHistoryTier3 = allSubscriptions.Where(s => s.Chamber3 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray(); var allHistoryTier4 = allSubscriptions.Where(s => s.Chamber4 == chamber.RowKey).OrderBy(s => s.StartDateTime).ToArray(); //add tier 1 history historyList.AddRange( allHistoryTier1.Select(h => new TransactionHistoryModel( h.RowKey, allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name, allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount, allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName, h.StartDateTime, GetTierCommission("1"), chamber.Name)) ); //add tier 2 history historyList.AddRange( allHistoryTier2.Select(h => new TransactionHistoryModel( h.RowKey, allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name, allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount, allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName, h.StartDateTime, GetTierCommission("2"), chamber.Name)) ); //add tier 3 history historyList.AddRange( allHistoryTier3.Select(h => new TransactionHistoryModel( h.RowKey, allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name, allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount, allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName, h.StartDateTime, GetTierCommission("3"), chamber.Name)) ); //add tier 4 history historyList.AddRange( allHistoryTier4.Select(h => new TransactionHistoryModel( h.RowKey, allCompanies.Where(c => c.RowKey == h.CompanyRowKey).SingleOrDefault().Name, allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount, allProducts.Where(p => p.RowKey == h.ProductID).SingleOrDefault().ProductName, h.StartDateTime, GetTierCommission("4") * allTransactions.Where(t => t.RowKey == h.TransactionID).SingleOrDefault().Amount,//todo: optimize chamber.Name)) ); var orderedHistoryNoTotalsList = historyList.OrderBy(h => h.TransactionTimeStamp).ToList(); var orderedHistoryWithTotalsList = new List <TransactionHistoryModel>(); double runningTotal = 0; orderedHistoryNoTotalsList.ForEach(h => { h.ChamberRunningTotal = runningTotal + h.Commission; orderedHistoryWithTotalsList.Add(h); }); //generate csv StringBuilder csvStringBuilder = new StringBuilder(); CsvConfig <TransactionHistoryModel> .OmitHeaders = false; orderedHistoryNoTotalsList.ForEach(oh => { var csv = CsvSerializer.SerializeToString <TransactionHistoryModel>(oh); csvStringBuilder.Append(csv); CsvConfig <TransactionHistoryModel> .OmitHeaders = true; }); return(File(ASCIIEncoding.ASCII.GetBytes(csvStringBuilder.ToString()), "text/csv", "sales.csv")); }
public PartialViewResult GetSearchResultsAsPartialView(string country, int page = 1, int productsPerPage = 25, string categoryID = "#00000000-0000-0000-0000-000000000000", string searchText = "") { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var allCategories = CategoryHelper.GetAllCategoriesFromCache().ToArray(); var allCompanies = CompanyHelper.GetAllCompaniesFromCache().ToArray(); var allSubscriptions = CompanySubscriptionHelper.GetAllCompanySubscriptionsFromCache().ToArray(); var allCountries = new CountryRepository().GetAll().ToArray(); var allSubscriptionProducts = new SubscriptionProductRepository().GetAll().ToArray(); CategoryModel parentCategory = null; var cleanCategoryID = categoryID.Replace("#", string.Empty); //get parent category of sub categories if ((categoryID != null)) { parentCategory = (from category in allCategories where category.RowKey.Equals(cleanCategoryID) select category).SingleOrDefault();//will return null for all cateogries } //check if root category was selected if (parentCategory == null) { parentCategory = CategoryHelper.AllCategories; } //var childCategoryArray = new CategoryModel[0]; var childCategoryArray = new List <CategoryModel>().ToArray(); if (parentCategory != CategoryHelper.AllCategories) { childCategoryArray = (from child in allCategories where child.ParentID == cleanCategoryID select child).ToArray(); } else { childCategoryArray = (from child in allCategories where child.ParentID == "0" select child).ToArray(); } var categoryAndDescendantsList = CategoryHelper.GetAllDescendantsFlattened(cleanCategoryID, allCategories, childCategoryArray).ToList(); categoryAndDescendantsList.Add(parentCategory); var categoryAndDescendantsArray = categoryAndDescendantsList.ToArray(); int resultsTotal; int productsDatabaseTotal; var results = ProductHelper.ProductSearch(categoryAndDescendantsArray, searchText, country, page, productsPerPage, allCompanies.ToArray(), null, out resultsTotal, out productsDatabaseTotal); List <ProductSearchResultModel> productSearchResults = new List <ProductSearchResultModel>(); results.ToList().ForEach(productModel =>//TODO: Search on country criteria TODO: Cache company details for this loop and avoid getting all at start { var company = allCompanies.Where(f => f.RowKey == (productModel.CompanyID)).SingleOrDefault(); if (company != null)//if company details have not been supplied - exclude products from the search results { //get countryname and flagurl string countryName = "Unknown"; string countryCode = "00"; if (company.Country != null) { var countryModel = allCountries.Where(c => c.Name.ToLower().Trim() == company.Country.ToLower().Trim()).SingleOrDefault(); if (countryModel != null) { countryCode = countryModel.Iso2DigitCode; countryName = countryModel.Name; } //country found so set name and code } //get subscription status int companyLevel = 0; var companySubscription = allSubscriptions.Where(s => s.CompanyRowKey == company.RowKey).SingleOrDefault(); if (companySubscription != null) { if (!(companySubscription.StartDateTime.AddYears(1) >= DateTime.UtcNow)) { companySubscription = null;//subscription is expired so make null } else { var companySubscriptionProduct = allSubscriptionProducts.Where(sp => sp.ID == companySubscription.ProductID).SingleOrDefault(); if (companySubscriptionProduct != null) { companyLevel = companySubscriptionProduct.Level; } } } var isVerified = company.IsVerified; var isChamberCertified = company.IsChamberCertified; var isGreenCertified = company.IsGreenCertified; productSearchResults.Add(new ProductSearchResultModel { CompanyName = company.Name, Product = productModel, BusinessType = company.BusinessType, IsChamberCertified = isChamberCertified, IsGreenCertified = isGreenCertified, IsVerified = isVerified, Country = countryName, FlagUrl = Settings.Default.FlagUrlPath.ToLower().Trim().Replace("%countrycode%", countryCode).ToLower(), CompanySubscriptionLevel = companyLevel, CompanyID = company.RowKey }); } }); if (productSearchResults.Count() == 0)//set current page to zero if there are no results { page = 0; } var totalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(resultsTotal) / Convert.ToDouble(productsPerPage))); var searchResultViewModel = new ProductSearchResultViewModel(productSearchResults.ToArray(), productsPerPage, page, parentCategory, totalPages, resultsTotal); stopWatch.Stop(); if (Settings.Default.IsDiagnosticsModeEnabled.ToLower() == "true") { searchResultViewModel.SearchDiagnosticInformation = "[" + DateTime.UtcNow.ToLongTimeString() + " UTC Searched " + productsDatabaseTotal.ToString() + " Products in " + stopWatch.ElapsedMilliseconds + "ms]"; } return(PartialView(searchResultViewModel)); }