Esempio n. 1
0
        public IActionResult Index()
        {
            var productImages = _context.ProductImages.Where(i => i.IsMainImage).ToList();
            var urls          = new List <string>();

            metaService.AddMetadata("description", "Verkauf von Eislaufasseoirs, Stoffen und mehr.");
            metaService.AddMetadata("keywords", "Asseoirs,Eiskunstlauf,Stoffe,Webrare,Taschen");

            cartHelper.CheckAndRemove();

            _logger.LogDebug("show home index");

            foreach (var item in productImages)
            {
                urls.Add(item.ImageUrl);
            }
            var model = new HomeViewModel();

            model.ImageUrls = urls;
            return(View(model));
        }
Esempio n. 2
0
        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));
        }