Inheritance: System.Data.Objects.DataClasses.EntityObject
Esempio n. 1
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();

            //Iterate the items in the cart, adding Order Details for each
            foreach (var cartItem in cartItems)
            {
                var orderDetails = new OrderDetail
                {
                    AlbumId = cartItem.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = cartItem.Album.Price
                };

                storeDB.OrderDetails.AddObject(orderDetails);

                orderTotal += (cartItem.Count * cartItem.Album.Price);
            }

            //Save the order
            storeDB.SaveChanges();

            //Empty the shopping cart
            EmptyCart();

            //Return the OrderId as a confirmation number
            return order.OrderId;
        }
Esempio n. 2
0
 public int CreateOrder(Order order)
 {
     decimal orderTotal = 0;
     var cartItems = GetCartItems();
     // Iterate over the items in the cart, adding the order details for each
     foreach (var item in cartItems)
     {
         var orderDetail = new OrderDetail
         {
             AlbumId = item.AlbumId,
             OrderId = order.OrderId,
             UnitPrice = item.Album.Price,
             Quantity = item.Count
         };
         // Set the order total of the shopping cart
         orderTotal += (item.Count * item.Album.Price);
         storeDB.OrderDetails.Add(orderDetail);
     }
     // Set the order's total to the orderTotal count
     order.Total = orderTotal;
     // Save the order
     storeDB.SaveChanges();
     // Empty the shopping cart
     EmptyCart();
     // Return the OrderId as the confirmation number
     return order.OrderId;
 }
Esempio n. 3
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();
            //add order details for each item in cart
            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Album.Price,
                    Quantity = item.Count
                };
                //set the order total of the shopping cart
                orderTotal += (item.Count * item.Album.Price);

                storeDB.OrderDetails.Add(orderDetail);
            }
            // set the order's total to the orderTotal count
            order.Total = orderTotal;

            //save the order and finish up
            storeDB.SaveChanges();
            EmptyCart();
            return order.OrderId;
        }
Esempio n. 4
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            foreach (var item in GetCartItems())
            {
                var orderDetail = new OrderDetail
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Album.Price,
                    Quantity = item.Count
                };

                orderTotal += (item.Count * item.Album.Price);

                storeDB.OrderDetails.Add(orderDetail);
            }

            order.Total = orderTotal;

            storeDB.SaveChanges();

            EmptyCart();

            return order.OrderId;
        }
        public ActionResult Edit(OrderDetail item)
        {
            if (ModelState.IsValid)
            {
                db.Entry(item).State = EntityState.Modified;
                var order = db.Orders.Find(item.OrderId);
                order.Notes.Add(new OrderNote { Note = "Order item " + item.Sku + " changed by " + User.Identity.Name });
                return RedirectToAction("edit", "orders", new { id = order.OrderId });
            }

            return View(item);
        }
 public ActionResult Create(OrderDetail item)
 {
     if (ModelState.IsValid)
     {
         db.OrderDetails.Add(item);
         return RedirectToAction("Index");
     }
     else
     {
         return View();
     }       
 }
        public ActionResult Create(OrderDetail orderdetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderdetail);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AlbumId = new SelectList(db.Albums, "AlbumId", "Title", orderdetail.AlbumId);
            ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "Username", orderdetail.OrderId);
            return View(orderdetail);
        }
        private void CreateOrder(Order order, List<Cart> cartItems)
        {
            decimal orderTotal = 0;

            foreach (var item in cartItems)
            {
                var album = storeDB.Albums.Find(item.AlbumId);

                var orderDetail = new OrderDetail
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = album.Price,
                    Quantity = item.Count,
                };

                orderTotal += (item.Count * album.Price);

                storeDB.OrderDetails.Add(orderDetail);
            }

            order.Total = orderTotal;
        }
Esempio n. 9
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderDetails EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderDetails(OrderDetail orderDetail)
 {
     base.AddObject("OrderDetails", orderDetail);
 }
Esempio n. 10
0
 /// <summary>
 /// Create a new OrderDetail object.
 /// </summary>
 /// <param name="orderDetailId">Initial value of the OrderDetailId property.</param>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="albumId">Initial value of the AlbumId property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="unitPrice">Initial value of the UnitPrice property.</param>
 public static OrderDetail CreateOrderDetail(global::System.Int32 orderDetailId, global::System.Int32 orderId, global::System.Int32 albumId, global::System.Int32 quantity, global::System.Decimal unitPrice)
 {
     OrderDetail orderDetail = new OrderDetail();
     orderDetail.OrderDetailId = orderDetailId;
     orderDetail.OrderId = orderId;
     orderDetail.AlbumId = albumId;
     orderDetail.Quantity = quantity;
     orderDetail.UnitPrice = unitPrice;
     return orderDetail;
 }
 public ActionResult Edit(OrderDetail orderdetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderdetail).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.AlbumId = new SelectList(db.Albums, "AlbumId", "Title", orderdetail.AlbumId);
     ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "Username", orderdetail.OrderId);
     return View(orderdetail);
 }
Esempio n. 12
0
        public int CreateOrder(Order order, List<Cart> cartItems)
        {
            decimal orderTotal = 0;

            // Iterate over the items in the cart, adding the order details for each
            foreach (var item in cartItems) {
                var album = _db.Albums.Find(item.AlbumId);

                var orderDetail = new OrderDetail
                {
                    AlbumId = item.AlbumId,
                    OrderId = order.OrderId,
                    UnitPrice = album.Price,
                    Quantity = item.Count,
                };

                // Set the order total of the shopping cart
                orderTotal += (item.Count * album.Price);

                _db.OrderDetails.Add(orderDetail);
            }

            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Empty the shopping cart
            EmptyCart();

            // Return the OrderId as the confirmation number
            return order.OrderId;
        }
Esempio n. 13
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();

            // Iterate over the items in the cart, adding the order details for each
            foreach (var item in cartItems)
            {
                var album = _db.Albums.Find(item.AlbumId);
                
                var orderDetail = new OrderDetail
                {
                    Sku = album.Title.ToLower().Replace(" ","-"),
                    Name = album.Title,
                    Discount =0,
                    UnitPrice = album.Price,
                    Quantity = item.Count,
                    
                };

                // Set the order total of the shopping cart
                orderTotal += (orderDetail.LineTotal);

                _db.OrderDetails.Add(orderDetail);

            }

            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Empty the shopping cart
            EmptyCart();

            // Return the OrderId as the confirmation number
            return order.OrderId;
        }
Esempio n. 14
0
        public int CreateOrder(Order order)
        {
            using (var tx = storeContext.Session.BeginTransaction())
            {
                var cartItems = GetCartItems();

                //Iterate the items in the cart, adding Order Details for each
                foreach (var cartItem in cartItems)
                {
                    var orderDetail = new OrderDetail
                                          {
                                              Album = cartItem.Album,
                                              Order = order,
                                              UnitPrice = cartItem.Album.Price
                                          };

                    order.OrderDetails.Add(orderDetail);
                }

                //Save the order
                storeContext.Session.Save(order);
                tx.Commit();
            }

            //Empty the shopping cart
            EmptyCart();

            //Return the OrderId as a confirmation number
            return order.OrderId;
        }