/// <summary> /// Prepare Latest And Feature Products /// </summary> /// <param name="products"></param> /// <returns></returns> private LatestAndFeatureProductsViewModel PrepareLatestAndFeatureProducts(IEnumerable <Product> products) { try { LatestAndFeatureProductsViewModel lpViewModel = new LatestAndFeatureProductsViewModel(); var latestProds = products.OrderBy(p => p.DisplayOrder).ToList(); var featureProductsList = new List <FeatureProductsViewModel>(); var latestProductsList = new List <LatestProductsViewModel>(); for (int i = 0; i < latestProds.Count; i++) { if (i < 20) { FeatureProductsViewModel featureProductsViewModel = new FeatureProductsViewModel { ProductName = latestProds[i].ProductName, Description = latestProds[i].Description, ShortDescription = latestProds[i].ShortDescription, DisplayOrder = latestProds[i].DisplayOrder, CreatedDate = latestProds[i].CreatedDate, UpdatedDate = latestProds[i].UpdatedDate, IsActive = latestProds[i].IsActive, Price = latestProds[i].Price, Quantity = latestProds[i].Quantity, SubCategoryOneId = latestProds[i].SubCategoryOneId }; featureProductsList.Add(featureProductsViewModel); LatestProductsViewModel latestProductsViewModel = new LatestProductsViewModel { ProductName = latestProds[i].ProductName, Description = latestProds[i].Description, ShortDescription = latestProds[i].ShortDescription, DisplayOrder = latestProds[i].DisplayOrder, CreatedDate = latestProds[i].CreatedDate, UpdatedDate = latestProds[i].UpdatedDate, IsActive = latestProds[i].IsActive, Price = latestProds[i].Price, Quantity = latestProds[i].Quantity, SubCategoryOneId = latestProds[i].SubCategoryOneId }; latestProductsList.Add(latestProductsViewModel); } else { break; } } lpViewModel.FeatureProductsVM = new List <FeatureProductsViewModel>(); lpViewModel.FeatureProductsVM = featureProductsList.OrderBy(d => d.DisplayOrder); lpViewModel.LatestProductsVM = new List <LatestProductsViewModel>(); lpViewModel.LatestProductsVM = latestProductsList.OrderByDescending(l => l.CreatedDate); return(lpViewModel); } catch (Exception e) { throw e; } }
private LatestAndFeatureProductsViewModel PrepareLatestAndFeatureProductsByAutoMapper(IEnumerable <Product> products) { LatestAndFeatureProductsViewModel lpViewModel = BindLatestAndFeatureProducts(); IEnumerable <FeatureProductsViewModel> featureProductsList = _mapper.Map <IEnumerable <FeatureProductsViewModel> >(products); IEnumerable <LatestProductsViewModel> latestProductsList = _mapper.Map <IEnumerable <LatestProductsViewModel> >(products); lpViewModel.FeatureProductsVM = new List <FeatureProductsViewModel>(); lpViewModel.FeatureProductsVM = featureProductsList.OrderBy(d => d.DisplayOrder); lpViewModel.LatestProductsVM = new List <LatestProductsViewModel>(); lpViewModel.LatestProductsVM = latestProductsList.OrderByDescending(l => l.CreatedDate); return(lpViewModel); }
private LatestAndFeatureProductsViewModel BindLatestAndFeatureProducts() { try { LatestAndFeatureProductsViewModel latestAndFeatureProductsVM = new LatestAndFeatureProductsViewModel(); latestAndFeatureProductsVM.FeatureProductsVM = new List <FeatureProductsViewModel>(); return(latestAndFeatureProductsVM); } catch (Exception ex) { throw; } }
public async Task <IActionResult> Index() { _logger.LogInformation("Index page invoked from HomeController"); if (HttpContext.User.Identity.IsAuthenticated) { string userData = User.Identity.Name; string authenticationType = HttpContext.User.Identity.AuthenticationType; string roleName = User.Claims. Where(t => t.Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"). Select(a => a.Value).FirstOrDefault(); if (userData != null && userData != "") { if (string.Equals(roleName.ToLower(), SD.AdminEndUser.ToLower(), StringComparison.OrdinalIgnoreCase)) { return(RedirectToAction("Dashboard1", "Dashboards", new { Area = "Admin" })); } else { LatestAndFeatureProductsViewModel latestAndFeatureVM; //var products = SetOrGetAllProductsFromBySubCategoryInCache(); var products = _productService.GetAllProductsFromBySubCategory(); //direct call so bypassing through cache above. latestAndFeatureVM = PrepareLatestAndFeatureProductsByAutoMapper(products); return(View(latestAndFeatureVM)); } } else { LatestAndFeatureProductsViewModel latestAndFeatureVM; var products = _productService.GetAllProductsFromBySubCategory(); //direct call so bypassing through cache above. latestAndFeatureVM = PrepareLatestAndFeatureProductsByAutoMapper(products); return(View(latestAndFeatureVM)); } } else { var shoppingCartCount = await _shoppingCart.GetCartCountAndTotalAmountAsync(); HttpContext.Session.SetInt32("CartCount", shoppingCartCount.ItemCount); LatestAndFeatureProductsViewModel latestAndFeatureVM = null; var products = _productService.GetAllProductsFromBySubCategory(); //direct call so bypassing through cache above. latestAndFeatureVM = PrepareLatestAndFeatureProductsByAutoMapper(products); return(View(latestAndFeatureVM)); } }