public ActionResult SalesCreate(Sales sales) { DefaultLoad(); try { bool isSave; foreach (var salesDetails in sales.SalesDetailses) { var product = _db.Products.FirstOrDefault(p => p.Id == salesDetails.ProductId); product.AvailableQuantity = product.AvailableQuantity - (double)salesDetails.Quantity; //productManager.UpdateProduct(product); _db.Entry(product).State = EntityState.Modified; _db.SaveChanges(); } isSave = salesManager.SaveSales(sales); if (isSave) { ViewBag.SMsg = "Save Successfully !!"; } else { ViewBag.FMsg = "Save Failed !!"; } } catch (Exception e) { ViewBag.FMsg = e.Message; } ViewBag.ProductDropdownList = new SelectList(_db.Products, "Id", "Name"); ViewBag.CustomerDropdownList = new SelectList(_db.Customers, "Id", "Name", sales.CustomerId); return(View()); }
public ActionResult PurchaseCreate(Purchase purchase) { DefaultLoad(); try { bool isSave; foreach (var purchasedetails in purchase.PurchaseDetailses) { var product = _db.Products.FirstOrDefault(p => p.Id == purchasedetails.ProductId); product.AvailableQuantity = product.AvailableQuantity + (double) purchasedetails.Quantity; product.Price = (double) purchasedetails.NewMRP; //productManager.UpdateProduct(product); _db.Entry(product).State = EntityState.Modified; _db.SaveChanges(); } isSave = purchaseManager.SavePurchase(purchase); if (isSave) { ViewBag.SMsg = "Save Successfully !!"; } else { ViewBag.FMsg = "Save Failed !!"; } } catch (Exception e) { ViewBag.FMsg = e.Message; } ViewBag.ProductDropdownList = new SelectList(_db.Products, "Id", "Name"); ViewBag.SupplierDropdownList = new SelectList(_db.Suppliers, "Id", "Name", purchase.SupplierId); return View(); }
public bool UpdateCategory(Category category) { bool isSave = false; _db.Entry(category).State = EntityState.Modified; int add = _db.SaveChanges(); if (add > 0) { isSave = true; } else { isSave = false; } return(isSave); }
public bool UpdateProduct(Product product) { bool isSave = false; _db.Entry(product).State = EntityState.Modified; int add = _db.SaveChanges(); if (add > 0) { isSave = true; } else { isSave = false; } return(isSave); }
public bool UpdateSupplier(Supplier supplier) { bool isSave = false; _db.Entry(supplier).State = EntityState.Modified; int add = _db.SaveChanges(); if (add > 0) { isSave = true; } else { isSave = false; } return(isSave); }