public JsonResult CreatePurchase(PurchaseVM O) { //ProviderName contiene el id del proveedor bool status = false; Purchase purchase = new Purchase(); var proid = Int32.Parse(O.ProviderName); if (ModelState.IsValid) { purchase.PurchaseDate = O.PurchaseDate; purchase.Comments = O.Comments; purchase.PurchaseTotal = O.PurchaseTotal; purchase.IdProvider = proid; db.Purchases.Add(purchase); db.SaveChanges(); foreach (var i in O.PurchaseLines) { PurchaseLine purchaseline = new PurchaseLine(); purchaseline.IdProduct = i.IdProduct; purchaseline.LinePrice = i.LinePrice; purchaseline.LineQuantity = i.LineQuantity; purchaseline.LineTotal = i.LineTotal; purchaseline.IdPurchase = purchase.IdPurchase; db.PurchaseLines.Add(purchaseline); db.SaveChanges(); Product prod = new Product(); prod = db.Products.Find(i.IdProduct); prod.Stock = prod.Stock + i.LineQuantity; if (prod.Cost != i.LinePrice) { prod.UploadDate = purchase.PurchaseDate; } prod.ParcialStock = prod.ParcialStock + i.LineQuantity; prod.Cost = i.LinePrice; db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } status = true; } else { status = false; } return(new JsonResult { Data = new { status = status } }); }
public JsonResult CreateSale(SaleVM O) { //CustomerName contiene el id del cliente bool status = false; Sale sale = new Sale(); var cusid = Int32.Parse(O.CustomerName); if (ModelState.IsValid) { sale.SaleDate = O.SaleDate; sale.SaleAddress = O.SaleAddress; sale.Comments = O.Comments; sale.SaleTotal = O.SaleTotal; sale.IdCustomer = cusid; db.Sales.Add(sale); db.SaveChanges(); foreach (var i in O.SaleLines) { SaleLine saleline = new SaleLine(); saleline.IdProduct = i.IdProduct; saleline.LinePrice = i.LinePrice; saleline.LineDiscount = i.LineDiscount; saleline.LineQuantity = i.LineQuantity; saleline.LineTotal = i.LineTotal; saleline.IdSale = sale.IdSale; db.SaleLines.Add(saleline); db.SaveChanges(); Product prod = new Product(); prod = db.Products.Find(i.IdProduct); prod.ParcialStock = prod.ParcialStock - i.LineQuantity; db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } status = true; } else { status = false; } return(new JsonResult { Data = new { status = status } }); }
public ActionResult Edit([Bind(Include = "CustomerID,CustomerName,Address,Phone")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(PartialView(customer)); }
public ActionResult Edit([Bind(Include = "IdCategory,CategoryName,CategoryDescription")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "IdTrademark,TrademarkName,TrademarkDescription")] Trademark trademark) { if (ModelState.IsValid) { db.Entry(trademark).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trademark)); }
public ActionResult Edit([Bind(Include = "IdCustomer,CustomerName,AddressCustomer,PhoneCustomer,EmailCustomer,CuitCuil")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "IdProvider,ProviderName,ProviderAddress,ProviderPhone,ProviderEmail")] Provider provider) { if (ModelState.IsValid) { db.Entry(provider).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public ActionResult Edit([Bind(Include = "PurchaseID,DatePurchase,UploadDate,ProviderID,Quantity")] Purchase purchase) { if (ModelState.IsValid) { db.Entry(purchase).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProviderID = new SelectList(db.Providers, "ProviderID", "ProviderName", purchase.ProviderID); return(View(purchase)); }
public ActionResult Edit([Bind(Include = "IdSale,SaleDate,Discount,Comments,SaleTotal,IdCustomer")] Sale sale) { if (ModelState.IsValid) { db.Entry(sale).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdCustomer = new SelectList(db.Customers, "IdCustomer", "CustomerName", sale.IdCustomer); return(View(sale)); }
public ActionResult Edit([Bind(Include = "IdPurchase,PurchaseDate,Comments,PurchaseTotal,IdProvider")] Purchase purchase) { if (ModelState.IsValid) { db.Entry(purchase).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdProvider = new SelectList(db.Providers, "IdProvider", "ProviderName", purchase.IdProvider); return(View(purchase)); }
public ActionResult Edit([Bind(Include = "IdProduct,ProductDescription,Cost,WholeSalePrice,PublicPrice,UploadDate,Stock,Minimum,State,Image,idCategory")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idCategory = new SelectList(db.Categories, "IdCategory", "CategoryName", product.idCategory); return(View(product)); }
public ActionResult Edit([Bind(Include = "IdBill,SaleDate,SaleAddress,Discount,Comments,SubTotal,LinesTotal,SaleTotal,IdCustomer")] Bill bill) { if (ModelState.IsValid) { db.Entry(bill).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdCustomer = new SelectList(db.Customers, "IdCustomer", "CustomerName", bill.IdCustomer); return(View(bill)); }
public ActionResult Edit([Bind(Include = "SaleID,SaleDate,UploadDate,CustomerID,Quantity")] Sale sale) { if (ModelState.IsValid) { db.Entry(sale).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CustomerName", sale.CustomerID); return(View(sale)); }
public ActionResult Edit([Bind(Include = "ProductID,Description,PurchasePrice,SalePrice,LastPurchase,UploadDate,Stock,minimum,State,CategoryID")] Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID); return(View(product)); }
public ActionResult Edit([Bind(Include = "IdSaleLine,IdProduct,LinePrice,LineDiscount,LineQuantity,LineTotal,IdSale")] SaleLine saleLine) { if (ModelState.IsValid) { db.Entry(saleLine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdProduct = new SelectList(db.Products, "IdProduct", "ProductDescription", saleLine.IdProduct); ViewBag.IdSale = new SelectList(db.Sales, "IdSale", "SaleAddress", saleLine.IdSale); return(View(saleLine)); }
public ActionResult Edit([Bind(Include = "IdPurchaseLine,IdProduct,LinePrice,LineQuantity,LineTotal,IdPurchase")] PurchaseLine purchaseLine) { if (ModelState.IsValid) { db.Entry(purchaseLine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdProduct = new SelectList(db.Products, "IdProduct", "ProductDescription", purchaseLine.IdProduct); ViewBag.IdPurchase = new SelectList(db.Purchases, "IdPurchase", "Comments", purchaseLine.IdPurchase); return(View(purchaseLine)); }
public ActionResult DeactivateConfirmation(int?idProd) { Product prod = new Product(); prod = db.Products.Find(idProd); if (ModelState.IsValid) { if (prod.ProductState) { prod.ProductState = false; } else { prod.ProductState = true; } db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public JsonResult FinalizeSale(string misale) { var saleid = Int32.Parse(misale); AlfredoContext db = new AlfredoContext(); Sale saledata = db.Sales.ToList().Find(u => u.IdSale == saleid); foreach (var item in saledata.SaleLines) { Product prod = new Product(); prod = db.Products.Find(item.IdProduct); prod.Stock = prod.Stock - item.LineQuantity; db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } saledata.SaleState = SaleState.Finalizada; db.Entry(saledata).State = EntityState.Modified; db.SaveChanges(); var midato = "Ok"; return(Json(midato, JsonRequestBehavior.AllowGet)); }
public ActionResult DeactivateConfirmation(int?idProd) { Product prod = new Product(); prod = db.Products.Find(idProd); if (ModelState.IsValid) { if (prod.ProductState == true) { prod.ProductState = false; ViewBag.Success = "El Producto se ha desactivado correctamente"; } else { prod.ProductState = true; ViewBag.Success = "El Producto se ha activado correctamente"; } db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public JsonResult RemoveStock(SaleVM O) { //CustomerName contiene el id del cliente bool status = false; foreach (var i in O.SaleLines) { Product prod = new Product(); prod = db.Products.Find(i.IdProduct); prod.ParcialStock = prod.ParcialStock - i.LineQuantity; prod.Stock = prod.Stock - i.LineQuantity; db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } status = true; return(new JsonResult { Data = new { status = status } }); }
public JsonResult CreateSale(SaleVM O) { //CustomerName contiene el id del cliente bool status = false; bool final = false; if (O.SaleState == "1") { final = true; } Sale sale = new Sale(); Bill bill = new Bill(); var cusid = Int32.Parse(O.CustomerName); if (ModelState.IsValid) { if (final) { sale.SaleState = SaleState.Finalizada; } else { sale.SaleState = SaleState.Pendiente; } bill.SaleTotal = O.SaleTotal; bill.Comments = O.Comments; bill.SaleDate = O.SaleDate; bill.SaleAddress = O.SaleAddress; bill.LinesTotal = O.SaleTotal; if (cusid != 0) { bill.IdCustomer = cusid; } db.Bills.Add(bill); db.SaveChanges(); sale.SaleDate = O.SaleDate; sale.SaleAddress = O.SaleAddress; sale.Comments = O.Comments; sale.SaleTotal = O.SaleTotal; sale.LinesTotal = O.SaleTotal; sale.IdBill = bill.IdBill; if (cusid != 0) { sale.IdCustomer = cusid; } db.Sales.Add(sale); db.SaveChanges(); foreach (var i in O.SaleLines) { BillLine billline = new BillLine(); billline.IdProduct = i.IdProduct; billline.LinePrice = i.LinePrice; billline.LineDiscount = i.LineDiscount; billline.LineQuantity = i.LineQuantity; billline.LineTotal = i.LineTotal; billline.IdBill = bill.IdBill; db.BillLines.Add(billline); db.SaveChanges(); SaleLine saleline = new SaleLine(); saleline.IdProduct = i.IdProduct; saleline.LinePrice = i.LinePrice; saleline.LineDiscount = i.LineDiscount; saleline.LineQuantity = i.LineQuantity; saleline.LineTotal = i.LineTotal; saleline.IdSale = sale.IdSale; db.SaleLines.Add(saleline); db.SaveChanges(); Product prod = new Product(); prod = db.Products.Find(i.IdProduct); if (final) { prod.Stock = prod.Stock - i.LineQuantity; } prod.ParcialStock = prod.ParcialStock - i.LineQuantity; db.Entry(prod).State = EntityState.Modified; db.SaveChanges(); } status = true; } else { status = false; } return(new JsonResult { Data = new { status = status } }); }