예제 #1
0
        public IActionResult UpdateItem(AdminProductDto productDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            __adminService.UpdateItem(productDto);
            string id = productDto.Id;
            var    updatedProductDto       = __adminService.GetAdminProduct(id);
            var    updatedProductViewModel = _mapper.Map <BeachTowelShop_App.Areas.Admin.Models.ProductViewModel>(updatedProductDto);

            _cache.Remove("GalleryProductViewModel");
            _cache.Remove("CategoryViewModel");
            if (updatedProductDto != null)
            {
                _cache.Remove($"ProductViewModelList{id}");
                foreach (var item in updatedProductViewModel.CategoryViews)
                {
                    _cache.Remove($"GalleryProductViewModelFiler{item.Id}");
                }
            }

            return(View("Item", updatedProductViewModel));
        }
예제 #2
0
 private void SetProperties(AdminProductDto productDto)
 {
     ProductName       = productDto.ProductName;
     Description       = productDto.Description;
     ProductNameEng    = productDto.ProductNameEng;
     DescriptionEng    = productDto.DescriptionEng;
     ProductNameRu     = productDto.ProductNameRu;
     DescriptionRu     = productDto.DescriptionRu;
     GroupId           = productDto.GroupId;
     ActiveSubstanceId = productDto.SubstanceId;
 }
        public async Task PostProduct(AdminProductDto productDto, string currentFolder, CancellationToken token)
        {
            var newProduct = new Product(productDto);

            if (productDto.Photo != null)
            {
                var imgName = await _photoService.UploadPhoto(productDto.Photo, currentFolder);

                _photoService.ResizeImage(productDto.Photo, Path.Combine(currentFolder, "Thumbs", imgName), 100);
                newProduct.AddOrUpdatePhoto(imgName);
            }
            _productRepository.Create(newProduct);
            await _productRepository.SaveAsync(token);
        }
예제 #4
0
        private bool barcodeIsExist(AdminProductDto adminProduct, IProductService productService)
        {
            if (adminProduct != null && !string.IsNullOrEmpty(adminProduct.Barcode))
            {
                var product = productService.SingleOrDefaultAsNoTrackingAsync(p => p.Barcode == adminProduct.Barcode).Result;

                if (product != null)
                {
                    if (product.Id != adminProduct.Id)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public async Task PutProduct(int id, AdminProductDto productDto, string currentFolder, CancellationToken token)
        {
            var existingProduct = await _productRepository.GetByIdForAdminAsync(id, token);

            var oldFileName = existingProduct.ProductPhoto.FileName;

            _photoService.DeleteFile(oldFileName, currentFolder);

            existingProduct.UpdateProduct(productDto);
            if (productDto.Photo != null)
            {
                var imgName = await _photoService.UploadPhoto(productDto.Photo, currentFolder);

                _photoService.ResizeImage(productDto.Photo, Path.Combine(currentFolder, "Thumbs", imgName), 100);
                existingProduct.AddOrUpdatePhoto(imgName);
            }
            _productRepository.Update(existingProduct);
            await _productRepository.SaveAsync(token);
        }
예제 #6
0
        public IActionResult CreateItem(List <IFormFile> pic, string name, string productDescription, string categories)
        {
            if (categories == null)
            {
                var allProductsDto1       = __adminService.GetAllProductsForAdmin();
                var allProductsViewModel1 = _mapper.Map <List <BeachTowelShop_App.Areas.Admin.Models.ProductViewModel> >(allProductsDto1);
                allProductsViewModel1[0].Error = "fill in a category";
                return(View(allProductsViewModel1));
            }
            var categoriesList  = categories.Trim().Split(";", StringSplitOptions.RemoveEmptyEntries).ToList();
            var categoryDtoList = new List <CategoryDto>();

            for (int i = 0; i < categoriesList.Count; i++)
            {
                var categoryDto = new CategoryDto()
                {
                    Name = categoriesList[i]
                };
                categoryDtoList.Add(categoryDto);
            }
            var picturePathList = new List <PictureDto>();

            CreateImg(pic, name, picturePathList);
            var productDto = new AdminProductDto()
            {
                Name = name, Description = productDescription, CategoryViews = categoryDtoList, PictureList = picturePathList
            };

            __adminService.CreateProduct(productDto);
            var allProductsDto       = __adminService.GetAllProductsForAdmin();
            var allProductsViewModel = _mapper.Map <List <BeachTowelShop_App.Areas.Admin.Models.ProductViewModel> >(allProductsDto);

            _cache.Remove("GalleryProductViewModel");
            _cache.Remove("CategoryViewModel");
            //_cache.Remove("HomePageViewModel");

            _cache.Remove("OrderProductViewModel");



            return(View("UploadItem", allProductsViewModel));
        }
예제 #7
0
        public void UpdateItem(AdminProductDto productDto)
        {
            var product    = _mapper.Map <Product>(productDto);
            var pictures   = _mapper.Map <List <Picture> >(productDto.PictureList);
            var categories = _mapper.Map <List <Category> >(productDto.CategoryViews);
            var prices     = new List <ProductSize>();

            foreach (var item in productDto.SizesPricesList)
            {
                var price = new ProductSize()
                {
                    Price = item.Price, ProductId = productDto.Id, SizeId = item.Id
                };
                prices.Add(price);
            }
            foreach (var picture in pictures)
            {
                _appDbContext.Pictures.Update(picture);
                _appDbContext.SaveChanges();
            }
            foreach (var category in categories)
            {
                var doesCategoryExists = _appDbContext.Categories.Where(a => a.Name == category.Name).FirstOrDefault();
                if (doesCategoryExists == null)
                {
                    _appDbContext.Categories.Update(category);
                    _appDbContext.SaveChanges();
                }
            }
            foreach (var price in prices)
            {
                _appDbContext.ProductSizes.Update(price);
                _appDbContext.SaveChanges();
            }
            _appDbContext.Products.Update(product);
            _appDbContext.SaveChanges();
        }
예제 #8
0
 public async Task Put(int id, [FromForm] AdminProductDto product, CancellationToken token)
 {
     await _productService.PutProduct(id, product, _currentFolderName, token);
 }
예제 #9
0
        public void CreateProduct(AdminProductDto productDto)
        {
            var product = _mapper.Map <Product>(productDto);

            product.Id = Guid.NewGuid().ToString();
            var picture = _mapper.Map <List <Picture> >(productDto.PictureList);

            var categories   = _mapper.Map <List <Category> >(productDto.CategoryViews);
            var id           = _appDbContext.Products.Select(a => a.Id).FirstOrDefault();
            var siezesPrices = GetAllSizesWithPrice(id);
            var sizes        = _mapper.Map <List <Size> >(productDto.SizesPricesList);

            foreach (var pic in picture)
            {
                var doesPicExist = _appDbContext.Pictures.Where(a => a.Path == pic.Path).Any();
                if (!doesPicExist)
                {
                    _appDbContext.Pictures.Add(pic);
                    _appDbContext.SaveChanges();
                }

                var productPicture = new ProductPicture()
                {
                    PictureId = pic.Id, ProductId = product.Id
                };
                product.ProductPictures.Add(productPicture);
            }
            foreach (var size in siezesPrices)
            {
                var sizesAndPrices = new ProductSize()
                {
                    ProductId = product.Id, SizeId = size.Id, Price = size.Price
                };
                product.ProductSizes.Add(sizesAndPrices);
            }
            foreach (var c in categories)
            {
                if (!_appDbContext.Categories.Where(a => a.Name == c.Name).Any())
                {
                    var category = new Category()
                    {
                        Name = c.Name
                    };
                    _appDbContext.Categories.Add(category);
                    _appDbContext.SaveChanges();
                }

                var doesCategoryExistsForProduct = _appDbContext.ProductCategories.Where(a => a.ProductId == id && a.Category.Name == c.Name).Any();
                if (!doesCategoryExistsForProduct)
                {
                    var cId = _appDbContext.Categories.Where(a => a.Name == c.Name).Select(a => a.Id).FirstOrDefault();
                    var pC  = new ProductCategory()
                    {
                        CategoryId = cId, ProductId = product.Id
                    };
                    product.ProductCategories.Add(pC);
                }
            }
            if (siezesPrices.Count == 0)
            {
                var allGenericSizes = _appDbContext.Sizes.ToList();
                foreach (var size in allGenericSizes)
                {
                    var genericSizesWithPrice = new ProductSize {
                        ProductId = product.Id, SizeId = size.Id, Price = size.Price
                    };
                    product.ProductSizes.Add(genericSizesWithPrice);
                }
            }


            _appDbContext.Products.Add(product);
            _appDbContext.SaveChanges();
        }
예제 #10
0
 public void UpdateProduct(AdminProductDto productDto)
 {
     SetProperties(productDto);
     AddOrUpdatePhoto(productDto.PhotoUrl);
 }