public async Task <IActionResult> Create([Bind("NumberBill,Date,Subtotal,Iva,Total,SupplierID")] BillPurchase billPurchase) { if (ModelState.IsValid) { _context.Add(billPurchase); await _context.SaveChangesAsync(); //Save Detail var rows = Request.Form["list_detalle"].ToString().Split(',').ToList(); foreach (string number in rows) { var idProduct = Convert.ToInt64(Request.Form["id" + number].ToString()); var product = _context.Product.Where(p => p.ID == idProduct).SingleOrDefault(); product.Stock = product.Stock + Convert.ToInt32(Request.Form["ca" + number].ToString()); _context.Product.Update(product); _context.SaveChanges(); //Next Feature: Add description //Save DetailMovement Table var objectDetailMovement = new DetailMovement(); objectDetailMovement.ProductID = product.ID; objectDetailMovement.Type = 0; // entry product objectDetailMovement.Amount = Convert.ToInt32(Request.Form["ca" + number].ToString()); objectDetailMovement.UnitPrice = Convert.ToDecimal(Request.Form["pu" + number].ToString().Replace(".", ",")); objectDetailMovement.Stock = product.Stock; _context.DetailMovement.Add(objectDetailMovement); _context.SaveChanges(); //Fixme: Update Cost Price if (objectDetailMovement.UnitPrice > product.CostPrice) { product.CostPrice = objectDetailMovement.UnitPrice; _context.Product.Update(product); _context.SaveChanges(); } //Save DetailBillPurchase var objectDetailBillPurchase = new DetailBillPurchase(); objectDetailBillPurchase.BillPurchaseID = billPurchase.ID; objectDetailBillPurchase.DetailMovementID = objectDetailMovement.ID; _context.DetailBillPurchase.Add(objectDetailBillPurchase); _context.SaveChanges(); System.Diagnostics.Debug.WriteLine("IDDetailMovement: ", objectDetailMovement.ID); //System.Diagnostics.Debug.WriteLine("Nombre: "+Request.Form["no"+number].ToString()); } //System.Diagnostics.Debug.WriteLine("REQUEST: " + rows.Count); return(RedirectToAction("Index")); } ViewData["SupplierID"] = new SelectList(_context.Supplier, "ID", "ID", billPurchase.SupplierID); return(View(billPurchase)); }
public ActionResult Create([Bind(Include = "ID,Description")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create([Bind(Include = "ID,Name,Due,Paid")] Bill bill) { if (ModelState.IsValid) { db.Bills.Add(bill); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bill)); }
public ActionResult Create([Bind(Include = "ID,BillAmount,BillName,BillInformation,BillDueDay,IsMandatoryBill,IsSavingsAccount,BillPaid")] Bill bill) { if (ModelState.IsValid) { db.Bills.Add(bill); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bill)); }
public void CreatePost([FromForm] NewBillTypeDetails billData) { _context.BillTypes.Add(billData.Type); foreach (var billPart in billData.PriceParts) { billPart.Type = billData.Type; _context.BillPriceParts.Add(billPart); } _context.SaveChanges(); Redirect("/BillMeasures"); }
public static async void Initialize() { using (var db = new BillContext()) { await db.Database.EnsureCreatedAsync(); db.Bills.Add(new Bill() { Name = "Rent" }); db.SaveChanges(); } }
public ClsBill AddBill(ClsBill item) { ClsBill bill = null; if (item == null) { throw new NullReferenceException(); } else { bill = new ClsBill() { BillId = item.BillId, BillOwner = item.BillOwner, FurnitureName = item.FurnitureName, BillAmount = item.BillAmount }; _context.Bills.Add(bill); _context.SaveChanges(); } return(item); }