public bool deleteData(int id) { var query1 = from r in DB.Carts where r.UserID == id select r; foreach (var q in query1) { var query2 = DB.Products.Where(p => p.productId == q.ProductID).FirstOrDefault(); query2.ProductStock = query2.ProductStock - q.Quantity; DB.SaveChanges(); orderHistory model = new orderHistory { ProductID = q.ProductID, productName = q.ProductName, quantity = q.Quantity, productImage = q.ProductImage, productPrice = q.Total, UserID = q.UserID }; DB.orderHistories.Add(model); DB.Entry(q).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } DB.SaveChanges(); return(true); }
public async Task <IActionResult> PutorderHistory([FromRoute] int id, [FromBody] orderHistory orderHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != orderHistory.ID) { return(BadRequest()); } _context.Entry(orderHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!orderHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult DeleteConfirmed(int id) { orderHistory orderHistory = db.orderHistory.Find(id); db.orderHistory.Remove(orderHistory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,orderID,bookID,quantity,date")] orderHistory orderHistory) { if (ModelState.IsValid) { db.Entry(orderHistory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.bookID = new SelectList(db.book, "bookID", "bookName", orderHistory.bookID); ViewBag.orderID = new SelectList(db.order, "orderID", "orderID", orderHistory.orderID); return(View(orderHistory)); }
public async Task <IActionResult> PostorderHistory([FromBody] orderHistory orderHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.orderHistories.Add(orderHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetorderHistory", new { id = orderHistory.ID }, orderHistory)); }
// GET: orderHistories/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } orderHistory orderHistory = db.orderHistory.Find(id); if (orderHistory == null) { return(HttpNotFound()); } return(View(orderHistory)); }
// GET: orderHistories/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } orderHistory orderHistory = db.orderHistory.Find(id); if (orderHistory == null) { return(HttpNotFound()); } ViewBag.bookID = new SelectList(db.book, "bookID", "bookName", orderHistory.bookID); ViewBag.orderID = new SelectList(db.order, "orderID", "orderID", orderHistory.orderID); return(View(orderHistory)); }