Exemple #1
0
    public IActionResult ReplenishProduct(ReplenishProductsViewModel replenishProductsViewModel)
    {
        if (!ModelState.IsValid)
        {
            return(View("ProductNotFound", replenishProductsViewModel.ProductId));
        }

        var productToReplenish = _productRepository.GetOne(replenishProductsViewModel.ProductId);

        if (productToReplenish == null)
        {
            return(View("ProductNotFound", replenishProductsViewModel.ProductId));
        }

        var storeToReplenish = _productRepository.GetStoreOfSpecificProduct(productToReplenish.Id);

        if (storeToReplenish == null)
        {
            return(View("ProductNotFound", replenishProductsViewModel.ProductId));
        }

        for (var i = 1; i <= replenishProductsViewModel.QuantityOfProductsToReplenish; i++)
        {
            var product = new Product(Guid.NewGuid(), productToReplenish.Name,
                                      productToReplenish.PriceInUAH,
                                      ProductStatus.OnSale, replenishProductsViewModel.CategoryId);
            _productRepository.AddProductToStore(product, storeToReplenish.Id);
        }

        return(RedirectToAction(IndexAction, DefaultController));
    }
Exemple #2
0
    public IActionResult ReplenishProduct(Guid?id)
    {
        if (id == null)
        {
            return(RedirectToAction(IndexAction, DefaultController));
        }

        var product = _productRepository.GetOne(id.Value);

        if (product == null)
        {
            return(View("ProductNotFound", id.Value));
        }

        var categoryProductsViewModel = new ReplenishProductsViewModel
        {
            Product  = product,
            Category = _categoryRepository.GetOne(product.CategoryId),
            QuantityOfProductsToReplenish = 1
        };

        return(View(categoryProductsViewModel));
    }