Beispiel #1
0
        public async Task <IActionResult> EditStock(UpdateStockViewModel model, bool?getProducts)
        {
            if (!ModelState.IsValid)
            {
                model = _viewModelHelper.GetUpdateStockViewModel(model);
                model.ProductsInStock = _productsRepository.Products.Where(p => model.SelectedProducts.Contains(p.ProductId));
                return(View(model));
            }

            var updateResult = await _stockRepository.UpdateStockAsync(
                stockId : model.StockId,
                stockName : model.StockName,
                address : model.Address,
                products : model.SelectedProducts
                );

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

            if (getProducts == true)
            {
                return(RedirectToAction(nameof(ProductsInStock), new { stockId = model.StockId }));
            }

            return(RedirectToAction(nameof(Stocks)));
        }
 public UpdateStockWindow(UserServices userServices,
                          AlertServices alertServices,
                          MaterialServices materialServices,
                          ProductServices productServices,
                          MaterialsProductServices materialsProductServices,
                          SaleServices saleServices,
                          List <Product> products,
                          List <Material> materials)
 {
     InitializeComponent();
     DataContext = new UpdateStockViewModel(this, userServices, alertServices, materialServices, productServices, materialsProductServices, saleServices, products, materials);
 }
Beispiel #3
0
        public UpdateStockViewModel GetUpdateStockViewModel(UpdateStockViewModel model = null)
        {
            if (model == null)
            {
                model = new UpdateStockViewModel();
            }

            model.Products   = _productRepository.Products;
            model.Currencies = _currencyRepository.Currencies;


            return(model);
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var stock = await _stockApp.GetEntityById((int)id);

            if (stock == null)
            {
                return(NotFound());
            }
            else
            {
                var updateStock = new UpdateStockViewModel
                {
                    ID          = stock.ID,
                    Description = stock.Description
                };
                return(View(updateStock));
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(UpdateStockViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var stock = await _stockApp.GetEntityById(model.ID);

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

                    stock.Description = model.Description;
                    await _stockApp.UpdateStock(stock);
                }
                catch
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }