Ejemplo n.º 1
0
        public async Task <IActionResult> CreateAd(ProductAdViewModel productAdViewModel)
        {
            IList <ProductAd> possibleAdImages = null;

            possibleAdImages = await _productService.ListPossibleAdImages(productAdViewModel.SelectedProductId);

            var img = productAdViewModel.ProductAdImage;

            if (productAdViewModel.ProductAdImage != null)
            {
                var adImagePath = await _appEnvironment.UploadImageAsync(productAdViewModel.ProductAdImage, "main carousel", uploadMaxByteSize);

                if (adImagePath != null)
                {
                    ProductAd productAd = new ProductAd
                    {
                        AdImageUrl = adImagePath,
                        Product    = await _productService.FindProductByIdAsync(productAdViewModel.SelectedProductId)
                    };
                    if (possibleAdImages != null && possibleAdImages.Count > 0)
                    {
                        await _appEnvironment.DeleteImageAsync(possibleAdImages[0].AdImageUrl, "main carousel");

                        await _productService.DeleteProductAd(possibleAdImages[0]);
                    }
                    await _productService.CreateProductAd(productAd);
                }
            }
            return(await EditMainCarousel());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteAds(ProductAdViewModel productAdViewModel)
        {
            foreach (var adId in productAdViewModel.IdsOfSelectedAdsToRemove)
            {
                var adToRemove = await _productService.GetProductAdById(adId);

                await _appEnvironment.DeleteImageAsync(adToRemove.AdImageUrl, "main carousel");

                await _productService.DeleteProductAd(adToRemove);
            }
            return(await EditMainCarousel());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> EditMainCarousel()
        {
            ProductAdViewModel productAdViewModel = new ProductAdViewModel();

            ICollection <Product>   products   = null;
            ICollection <ProductAd> productAds = null;

            products = await _productService.GetAllProducts();

            productAds = await _productService.GetProductAds();


            productAdViewModel.ProductSelectList     = new SelectList(products, "Id", "Name");
            productAdViewModel.AdsToRemoveSelectList = new MultiSelectList(productAds, "Id", "Product.Name");

            ViewBag.ProductAds      = productAds;
            ViewBag.UploadMaxMbSize = uploadMaxByteSize / 1048576;

            return(View("EditMainCarousel", productAdViewModel));
        }