public ActionResult AddProduct(AddProductView addProduct, string time, int SaleID) { #region Check Cache var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { MessageSetter.SetWarning("Sorry , previous transaction is not saved to the database."); if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } } #endregion if (addProduct.Cost < 0) { ModelState.AddModelError("Amount", "Amount can't be negative."); return(DetermineSaleDay(SaleID)); } var useraccExt = new UserAccountsExtension(); var accountOf = useraccExt.GetProductBoughtUser(); var accountBalance = new AccountBalance() { AccountOf = accountOf.UserID, AddBy = userinfo.GetUserID(), Amount = addProduct.Cost, AddedQuantity = addProduct.Quantity, QtyType = addProduct.QuantityType, Dated = DateTime.Now, CategoryProduct = addProduct.CategoryID, IsExpense = true, IsAddedMoney = false, IsBoughtProduct = true, IsVerified = false }; var inventoryEntension = new InventoryExtension(); if (inventoryEntension.InventoryAdd(db, accountBalance)) { db.SaveChanges(); MessageSetter.SetPositive("Product of " + addProduct.Cost + " successfully."); } else { MessageSetter.SetWarning("try again."); } return(DetermineSaleDay(SaleID)); }
public ActionResult Add(AccountBalance accountbalance) { if (User.Identity.IsAuthenticated) { double?sum = db.ViewSummaryAccountBalances.Sum(n => n.Balance); if (sum == null) { sum = 0; } var sum2 = (double)sum; if (sum2 < accountbalance.Amount) { ModelState.AddModelError("Amount", "Sorry your amount exceeds your account balance " + sum2 + "."); } var inventoryExtension = new InventoryExtension(); if (ModelState.IsValid && inventoryExtension.InventoryAdd(db, accountbalance)) { db.SaveChanges(); return(RedirectToAction("List", "AccountBalance")); } } GetDropDowns(); return(View(accountbalance)); }