public ActionResult AllocatedProductsBoxEdit(int? productId, string DateAccountability, string amount, int vendorId = 0) { Users LoggedUser = Login.GetLoggedUser(); if (LoggedUser == null) { return View("NoPermission"); } if (LoggedUser.Role == Roles.Vendedor) { return View("NoPermission"); } #region Validation Validation validation = new Validation(); bool error = false; string DataError = null; try { validation.DateNotToday(DateAccountability); } catch (Exception ex) { DataError = ex.Message; error = true; } string AmountError = null; try { validation.Amount(amount); } catch (Exception ex) { AmountError = ex.Message; error = true; } string InventoryError = null; ProductsAllocated productToEdite = ProductsAllocated.TryFind(productId); if (productToEdite.Product.Amount - (int.Parse(amount) - productToEdite.Amount) < 0) { InventoryError = "Item indisponivel no estoque"; error = true; } #endregion Validation if (!error) { productToEdite.Product.Amount = productToEdite.Product.Amount - (int.Parse(amount) - productToEdite.Amount); productToEdite.DateAccountability = DateTime.Parse(DateAccountability); productToEdite.Product.Save(); productToEdite.Amount = int.Parse(amount); productToEdite.Save(); ViewBag.SaveSuccess = "Salvo com Sucesso"; } ViewBag.DataError = DataError; ViewBag.AmountError = AmountError; ViewBag.InventoryError = InventoryError; ViewBag.vendors = Users.Queryable.Where(i => i.UserBoss == LoggedUser).ToList(); ViewBag.vendorId = vendorId; return View("EditAllocatedProducts", new { vendorId = vendorId }); }