// GET: ShoppingCarts/Details/5 public async Task <IActionResult> Details(Guid?id) { var sessioncart = HttpContext.Session.GetString("ShoppingCartId"); int shipTypeDefault = 1; //Type 1 = kleines Paket decimal shipDefaultPrice = 0.0M; int countryDefault = 1; //Country 1 Deutschland int periodDefault = 1; if (id == null) { return(NotFound()); } var shoppingCart = await _context.ShoppingCarts.SingleOrDefaultAsync(m => m.ID == id); if (shoppingCart == null) { return(NotFound()); } if (shoppingCart.CustomerId != Guid.Empty) { var shipping = await _context.ShippingAddresses.SingleOrDefaultAsync(c => c.CustomerID == shoppingCart.CustomerId && c.IsMainAddress); if (shipping == null) { return(RedirectToAction("CustomerIndex", "ShippingAddresses", new { id = shoppingCart.CustomerId })); } countryDefault = shipping.CountryID; } decimal total = 0.0M; var lines = _context.ShoppingCartLines.Where(l => l.ShoppingCartID.Equals(shoppingCart.ID)); List <CartLineViewModel> vmcLines = new List <CartLineViewModel>(); foreach (var item in lines) { string path = string.Empty; try { path = _context.ProductImages.Where(i => i.ProductID.Equals(item.ProductID) && i.IsMainImage).SingleOrDefault().ImageUrl; } catch (Exception) { path = "noImage.svg"; } var product = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault(); if (periodDefault < product.ShippingPeriod) { periodDefault = product.ShippingPeriod; } var productShipPrice = await _context.ShippingPrices.SingleAsync(s => s.ShippingPriceTypeId == product.ShippingPriceType && s.CountryId == countryDefault); if (shipDefaultPrice < productShipPrice.Price) { shipDefaultPrice = productShipPrice.Price; shipTypeDefault = productShipPrice.ShippingPriceTypeId; } decimal baseprice = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault().Price; decimal pPrice = 0.0M; if (baseprice != 0.0M) { pPrice = baseprice * item.Quantity; } if (string.IsNullOrEmpty(path)) { path = "noImage.svg"; } string unit = new UnitHelper(_context, factory).GetUnitName(product.BasesUnitID); string sekunit = new UnitHelper(_context, factory).GetUnitName(product.SecondBaseUnit); CartLineViewModel cvml = new CartLineViewModel() { ID = item.ID, CartID = item.ShoppingCartID, ImgPath = path, Position = item.Position, PosPrice = pPrice, Quantity = item.Quantity, ProductID = item.ProductID, Unit = unit, UnitID = item.UnitID, ProductName = product.Name, ProductNo = product.ProductNumber.ToString(), ShortDescription = product.ShortDescription, MinimumPurchaseQuantity = Math.Round(product.MinimumPurchaseQuantity, 2), AvailableQuantity = Math.Round(product.AvailableQuantity, 2), ShoppingCartID = shoppingCart.ID, SellBasePrice = Math.Round(item.SellBasePrice, 2), SellSekPrice = Math.Round(product.SecondBasePrice, 2), SekUnit = sekunit, SlugUrl = $"{item.ProductID}-{product.ProductNumber}-{FriendlyUrlHelper.ReplaceUmlaute(product.Name)}" }; vmcLines.Add(cvml); total = total + pPrice; } ShippingPeriod shippingPeriod = await _context.ShpippingPeriods.SingleAsync(s => s.ShippingPeriodID == periodDefault); total = total + shipDefaultPrice; shipDefaultPrice = Math.Round(shipDefaultPrice, 2); var shippreise = await new ShippingPricesHelpers(_context).GetShippingPricesViewModels(shipTypeDefault); CartViewModel vm = new CartViewModel() { ID = shoppingCart.ID, Number = shoppingCart.Number, OrderId = shoppingCart.OrderId, Lines = vmcLines, Total = total, DefaultCountry = countryDefault, ShipPrices = shippreise, ShippingPeriodName = shippingPeriod.Decription }; cartHelper.CheckAndRemove(); return(View(vm)); }
public async Task <IActionResult> Kategorie([FromQuery] string categoryId, [FromQuery] string categorySubId, [FromQuery] string categoryDetailId) { cartHelper.CheckAndRemove(); string titel = string.Empty; string metadescription = string.Empty; string metakeywords = string.Empty; string categorieDescription = string.Empty; int catId = 0; int catSubId = 0; int catDetId = 0; if (categoryId != null) { string[] catsplit = categoryId.Split("-"); catId = int.Parse(catsplit[0]); } if (categorySubId != null) { string[] catSubSplit = categorySubId.Split("-"); catSubId = int.Parse(catSubSplit[0]); } if (categoryDetailId != null) { string[] catDetSplit = categoryDetailId.Split("-"); catDetId = int.Parse(catDetSplit[0]); } var products = await _context.Products.Include(p => p.ImageList).Include(ca => ca.CategoryAssignments).OrderByDescending(p => p.ProductID).ToListAsync(); List <Product> filterProducts = new List <Product>(); List <ProductThumbnailsViewModel> thubnails = new List <ProductThumbnailsViewModel>(); var categoryAssignments = new List <CategoryAssignment>(); if (catId > 0) { var category = await _context.Categories.Where(c => c.ID == catId).SingleAsync(); titel = category.Name; metadescription = category.SeoDescription; metakeywords = category.SeoKeywords; categorieDescription = category.HtmlDescription; if (catSubId > 0) { var categorySub = await _context.CategorySubs.Where(c => c.ID == catSubId).SingleAsync(); titel += $"-{categorySub.Name}"; metadescription = categorySub.SeoDescription; metakeywords = categorySub.SeoKeywords; categorieDescription = categorySub.HtmlDescription; if (catDetId > 0) { var categoryDetail = await _context.CategoryDetails.Where(c => c.ID == catDetId).SingleAsync(); titel += $"-{categoryDetail.Name}"; metadescription = categoryDetail.SeoDescription; metakeywords = categoryDetail.SeoKeywords; categorieDescription = categoryDetail.HtmlDescription; categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId && ca.CategorySubID == catSubId && ca.CategoryDetailID == catDetId).ToListAsync(); } else { categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId && ca.CategorySubID == catSubId).ToListAsync(); } } else { categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId).ToListAsync(); } if (categoryAssignments.Count > 0) { foreach (CategoryAssignment item in categoryAssignments) { var product = products.Where(p => p.ProductID == item.ProductID && p.MinimumPurchaseQuantity <= p.AvailableQuantity && p.IsActive).FirstOrDefault(); if (product != null) { if (!filterProducts.Contains(product)) { filterProducts.Add(product); } } } } } foreach (Product item in filterProducts) { List <string> urls = new List <string>(); string baseUnit = string.Empty; string secondPriceUnit = string.Empty; ProductThumbnailsViewModel vmProduct = new ProductThumbnailsViewModel(); baseUnit = new UnitHelper(_context, factory).GetUnitName(item.BasesUnitID); if (item.SecondBasePrice != 0.0M && item.SecondBaseUnit != 0) { string strUnit = new UnitHelper(_context, factory).GetUnitName(item.SecondBaseUnit); secondPriceUnit = Math.Round(item.SecondBasePrice, 2).ToString() + " €/" + strUnit; } try { vmProduct.ProductID = item.ProductID; vmProduct.ProductNumber = item.ProductNumber; vmProduct.Price = item.Price; vmProduct.AvailableQuantity = item.AvailableQuantity; vmProduct.BasesUnit = baseUnit; vmProduct.BasesUnitID = item.BasesUnitID; vmProduct.Description = item.Description; vmProduct.MinimumPurchaseQuantity = item.MinimumPurchaseQuantity; vmProduct.Name = item.Name; vmProduct.ShippingTime = new ShippingPeriodHelper(_context).GetDescription(item.ShippingPeriod); vmProduct.Size = new SizeHelper(_context).GetName(item.Size); vmProduct.ShortDescription = item.ShortDescription; vmProduct.SecondPriceUnit = secondPriceUnit; vmProduct.SlugUrl = $"{item.ProductID}-{item.ProductNumber}-{FriendlyUrlHelper.ReplaceUmlaute(item.Name)}"; } catch (Exception ex) { Console.WriteLine(ex); } foreach (ProductImage img in item.ImageList) { if (img.IsMainImage) { vmProduct.MainImageUrl = img.ImageUrl; } urls.Add(img.ImageUrl); } if (string.IsNullOrEmpty(vmProduct.MainImageUrl)) { if (urls.Count > 0) { vmProduct.MainImageUrl = urls.First(); } else { vmProduct.MainImageUrl = "noImage.svg"; } } vmProduct.ImageUrls = urls; thubnails.Add(vmProduct); } ViewData["CategorieDescription"] = categorieDescription; ViewData["Title"] = titel; if (!string.IsNullOrWhiteSpace(metadescription)) { metaService.AddMetadata("description", metadescription); } if (!string.IsNullOrWhiteSpace(metakeywords)) { metaService.AddMetadata("keywords", metakeywords); } thubnails.Shuffle(); return(View(thubnails)); }
public async Task <IViewComponentResult> InvokeAsync() { List <NavItemViewModel> navItems = new List <NavItemViewModel>(); try { var catagories = await _context.Categories.ToListAsync(); foreach (Category category in catagories) { var subs = _context.CategorySubs.Where(s => s.CategoryID == category.ID).ToList(); var nav = new NavItemViewModel { Id = category.ID, Name = category.Name, PerentId = 0, SlugUrl = $"{category.ID}-{FriendlyUrlHelper.ReplaceUmlaute(category.Name)}" }; if (subs != null) { nav.Childs = new List <NavItemViewModel>(); foreach (CategorySub categorysub in subs) { var details = _context.CategoryDetails.Where(d => d.CategorySubID == categorysub.ID).ToList(); var navsub = new NavItemViewModel { Id = categorysub.ID, Name = categorysub.Name, PerentId = categorysub.CategoryID, SlugUrl = $"{categorysub.ID}-{FriendlyUrlHelper.ReplaceUmlaute(categorysub.Name)}" }; if (details != null) { navsub.Childs = new List <NavItemViewModel>(); foreach (CategoryDetail categorydetail in details) { var navdetail = new NavItemViewModel { Id = categorydetail.ID, Name = categorydetail.Name, PerentId = categorydetail.CategorySubID, Childs = null, SlugUrl = $"{categorydetail.ID}-{FriendlyUrlHelper.ReplaceUmlaute(categorydetail.Name)}" }; _logger.LogDebug($"NavigationViewComponent.InvokeAsync -> add detail category: {navdetail.Name}"); navsub.Childs.Add(navdetail); } } _logger.LogDebug($"NavigationViewComponent.InvokeAsync -> add sub category: {navsub.Name}"); nav.Childs.Add(navsub); } } _logger.LogDebug($"NavigationViewComponent.InvokeAsync -> add category: {nav.Name}"); navItems.Add(nav); } } catch (Exception e) { _logger.LogError(e, "Error on Invoke navigation!!!", null); } return(View(navItems)); }