Exemple #1
0
        public async Task <IActionResult> Create(int itemOfProductId, ItemExport itemExport)
        {
            var itemOfProduct = await _repository.GetItemOfProduct(itemOfProductId);

            if (itemOfProduct == null)
            {
                ViewBag.ErrorMessage = "لايوجد   بيانات";
                return(View("NotFound"));
            }
            if (await _repository.CheckIfImportsEqualExport(itemOfProductId, itemExport.Qty))
            {
                ViewBag.ItemOfProductId   = itemOfProduct.Id;
                ViewBag.ItemOfProductName = itemOfProduct.Name;
                return(View(itemExport).WithDanger("danger", "الكمية غير كافية"));
            }

            if (ModelState.IsValid)
            {
                _repository.Add <ItemExport>(itemExport);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.ItemOfProductId   = itemOfProduct.Id;
            ViewBag.ItemOfProductName = itemOfProduct.Name;
            return(View(itemExport));
        }