Exemplo n.º 1
0
        public IActionResult EditProduct([Required] int productId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var product = _productRepository.Products
                          .Where(p => p.ProductId == productId)
                          .Include(p => p.Currency)
                          .Include(p => p.Category)
                          .Include(p => p.StockProduct).ThenInclude(sp => sp.Stock)
                          .SingleOrDefault();

            if (product == null)
            {
                return(NotFound());
            }

            var model = new UpdateProductViewModel()
            {
                ProductId       = product.ProductId,
                Barcode         = product.Barcode,
                CategoryId      = product.CategoryId,
                CurrencyId      = product.CurrencyId,
                CurrentStocks   = product.StockProduct.Select(sp => sp.Stock).ToList(),
                Price           = product.Price,
                ProductName     = product.ProductName,
                CurrentCurrency = product.Currency,
                CurrentCategory = product.Category
            };

            model = _viewModelHelper.GetUpdateProductViewModel(model);

            return(View(model));
        }