Exemple #1
0
        public async Task <IActionResult> Index()
        {
            ViewBag.AttributeCategories = _attributeService.GetAllAttributes();

            ManageAttributesViewModel mavm = new ManageAttributesViewModel()
            {
                AttributeSelectList            = new SelectList(_attributeService.GetAllAttributes(), "Id", "Name"),
                AttributeyMultiSelectList      = new MultiSelectList(_attributeService.GetAllAttributes(), "Id", "Name"),
                AttributeValuesMultiSelectList = new MultiSelectList((from av in _attributeService.GetAllAttributeValues()
                                                                      select new
                {
                    av.Id,
                    AttributeInCategory = _attributeService.FindAttributeById(av.AttributeId).Name + "/" + av.Name
                }),
                                                                     "Id",
                                                                     "AttributeInCategory"
                                                                     ),
                ProductMultiSelectList = new MultiSelectList(await _productService.GetAllProducts(), "Id", "Name"),
                LinksMultiList         = new MultiSelectList((from pav in _attributeService.GetAllProductAttributeValues()
                                                              select new
                {
                    pav.Id,
                    Association = _attributeService.FindAttributeValueById(pav.AttributeValueId).Name + " -> " +
                                  _productService.FindProductById(pav.ProductId).Name
                }),
                                                             "Id",
                                                             "Association"
                                                             )
            };

            return(View(mavm));
        }
Exemple #2
0
        public async Task <IActionResult> ProductPage(int id)
        {
            //Product temp = await _context.Product.FirstOrDefaultAsync(p => p.Id == id);
            Product temp = await _productService.FindProductByIdAsync(id);

            List <Product> products = new List <Product>();

            products.Add(temp);
            ViewBag.Product = temp;

            String[] primaryImage = await _productService.GetAllImages(products, true);

            ViewData["primary_image"] = primaryImage[0];

            String[] secondaryImages = await _productService.GetAllImages(products, false);

            //List<ProductImage> secondaryImages = _context.ProductImage.Where(pi => !pi.IsPrimary && pi.Product.Id == temp.Id).ToList();
            ViewBag.SecondaryImages = secondaryImages;


            ProductDiscount discount = await _productService.GetDiscountByProductId(id);

            if (discount != null)
            {
                if (discount.Ends > DateTime.Now)
                {
                    ViewBag.Discount = discount;
                }
                else
                {
                    await _productService.DeleteDiscount(discount);
                }
            }

            ICollection <AttributeValue> attributes = await _attributeService.GetProductAttributeValues(id);

            ICollection <Models.Attribute> attributeCategories = new List <Models.Attribute>();

            foreach (AttributeValue attr in attributes)
            {
                Models.Attribute attrCategory = _attributeService.FindAttributeById(attr.AttributeId);
                if (!attributeCategories.Contains(attrCategory))
                {
                    attributeCategories.Add(attrCategory);
                }
            }
            ViewBag.Attributes          = attributes;
            ViewBag.AttributeCategories = attributeCategories;

            return(View(await _productService.GetAllPropertiesByProductIdAsync(id)));
        }