public async Task <ActionResult <Bill> > AddNewBill([FromBody] Bill bill) { dbContext.Add(bill); await dbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetAllBills), new {}, bill)); }
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 async Task <IActionResult> Create([Bind("ID,ROW_ID,SUB_ID,LOCATION_ADDRESS")] PREMISE_DETAILS pREMISE_DETAILS) { if (ModelState.IsValid) { _context.Add(pREMISE_DETAILS); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pREMISE_DETAILS)); }
public async Task <IActionResult> Create([Bind("Id,TypeID,Value,CreatedAt")] BillMeasure billMeasure) { if (ModelState.IsValid) { _context.Add(billMeasure); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TypeID"] = new SelectList(_context.BillTypes, "Id", "Name", billMeasure.TypeID); return(View(billMeasure)); }
public async Task <IActionResult> Create([Bind("Ruc,Name,City,Address,Phone,NameContactPerson,SkypeUserContactPerson")] Supplier supplier) { try { if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } } catch (DbUpdateException ex) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); Console.WriteLine("Error Create Product", ex); } return(View(supplier)); }
public async Task <IActionResult> Create([Bind("Code,Barcode,Name,CostPrice,Utility,SalePrice,Stock,State,CategoryID")] Product product) { try { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["CategoryID"] = new SelectList(_context.Category, "ID", "ID", product.CategoryID); } catch (DbUpdateException ex) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); Console.WriteLine("Error Create Product", ex); } return(View(product)); }