예제 #1
0
파일: Cart.cs 프로젝트: sho4516/AMAZON_POC
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            orderHistory orderHistory = db.orderHistory.Find(id);

            db.orderHistory.Remove(orderHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #4
0
 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));
 }
예제 #5
0
        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));
        }
예제 #6
0
        // 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));
        }
예제 #7
0
        // 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));
        }