Beispiel #1
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;
        }
Beispiel #2
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;
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeContext.Session.Save(order);

                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext, storeContext);
                    cart.CreateOrder(order);

                    return RedirectToAction("Complete",
                        new { id = order.OrderId });
                }

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
Beispiel #4
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;
        }
        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;
        }
Beispiel #6
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;
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try 
            {
                if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();

                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return RedirectToAction("Complete", new  { id = order.OrderId });
                }
            
            }
            catch
            {
                return View(order);
            }
        }
Beispiel #8
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            string promoCode = values["PromoCode"];
            if (!String.IsNullOrEmpty(promoCode) && !string.Equals(promoCode, PromoCode, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("", "Promo code is not valid.");
                //Invalid - redisplay with errors
                return View(order);
            }

            string userName = User.Identity.Name;
            var cart = ShoppingCart.GetCart(this.HttpContext);

            order.Username = userName;
            order.OrderDate = DateTime.Now;

            //Save Order
            _entities.Orders.Add(order);
            _entities.SaveChanges();

            //Process the order
            cart.CreateOrder(order);

            return RedirectToAction("Complete",
                   new { id = order.OrderId });
        }
 public ActionResult Edit(Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(order);
 }
        public ActionResult Create(Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(order);
        }
Beispiel #11
0
        public void AddressAndPaymentAsync(FormCollection values)
        {
            AsyncManager.OutstandingOperations.Increment();
            var worker = new BackgroundWorker();
            var order = new Order();
            bool success = true;

            TryUpdateModel(order);

            string promoCode = values["PromoCode"];
            if (!String.IsNullOrEmpty(promoCode) && !string.Equals(promoCode, PromoCode, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("", "Promo code is not valid.");
                success = false;
            }

            string userName = User.Identity.Name;
            var cart = ShoppingCart.GetCart(this.HttpContext);

            worker.DoWork += (sender, args) =>
            {
                if (!success)
                    return;

                try
                {
                    order.Username = userName;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    _entities.Orders.Add(order);
                    _entities.SaveChanges();

                    //Process the order
                    cart.CreateOrder(order);
                    success = true;
                }
                catch
                {
                    success = false;
                }
            };

            worker.RunWorkerCompleted += (o, e) =>
            {
                AsyncManager.Parameters["order"] = order;
                AsyncManager.Parameters["success"] = success;
                AsyncManager.OutstandingOperations.Decrement();
            };

            worker.RunWorkerAsync(null);
        }
Beispiel #12
0
 public void CreateOrder(Order order)
 {
     order.Lines = new List<Order.OrderLine>(
         Lines.Select(line => new Order.OrderLine
         {
             Album = new Order.OrderLine.OrderAlbum
             {
                 Id = line.Album.Id,
                 Title = line.Album.Title
             },
             Price = line.Price,
             Quantity = line.Quantity
         }));
     Lines.Clear();
 }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();

                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    //Add SMS notification here
                    if (order.SendSmsNotifications)
                    {
                        var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
                        client.SendSmsMessage(
                                ConfigurationManager.AppSettings["PhoneNumber"],
                                order.Phone,
                                string.Format("Thank you for ordering.  You can check the status anytime by replying to this with the text 'status {0}'", order.OrderId)
                            );
                    }

                    return RedirectToAction("Complete",
                        new { id = order.OrderId });
                }

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
        public static Order CreateShippingInfo()
        {
            var shippingInfo = new Order
            {
                FirstName = "Homer",
                LastName = "Simpson",
                Address = "742 Evergreen Terrace",
                City = "Springfield",
                State = "Kentucky",
                PostalCode = "123456",
                Country = "United States",
                Phone = "2341231241",
                Email = "*****@*****.**"
            };

            return shippingInfo;
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            try
            {
                // Updat the model
                UpdateModel(order);

                if (string.Equals(values["PromoCode"],
                    PromoCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        // Promo Code supplied
                        order.Username = User.Identity.Name;
                        order.OrderDate = DateTime.Now;

                        // Save Order
                        storeDB.Orders.Add(order);
                        storeDB.SaveChanges();

                        // Process the order
                        var cart = ShoppingCart.GetCart(this);
                        cart.CreateOrder(order);

                        return RedirectToAction("Complete", new { id = order.OrderId });
                    }
                    else
                    {
                        throw new Exception("Model State is not valid!");
                    }
                }
            }
            catch
            {
                // Invalid -- redisplay with errors
                return View(order);
            }
        }
Beispiel #16
0
        public ActionResult Create(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

                if (string.Equals(values["PromoCode"], PromoCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    db.Orders.Add(order);

                    //Process the order
                    var cart = ShoppingCart.GetCart(db, this.HttpContext);
                    cart.CreateOrder(order);

                    //add a note
                    order.Notes = new List<OrderNote>();
                    order.Transactions = new List<Transaction>();
                    order.Notes.Add(new OrderNote { Note = "Preparing Order", CreatedOn = DateTime.Now});

                    //auth the charge...
                    order.Transactions.Add(new Transaction { Processor = "coupon", Authorization = PromoCode, Amount = cart.GetTotal(), CreatedOn = DateTime.Now, Discount = 0, OrderId = order.OrderId });
                    order.Notes.Add(new OrderNote { Note = "Transaction Authorized by Coupon: " + PromoCode, CreatedOn = DateTime.Now});

                    //send a thank you note via email
                    order.Notes.Add(new OrderNote { Note = "Thank You Invoice Email Sent", CreatedOn = DateTime.Now});

                    //set the status as paid. Simplistic, but will work for now
                    order.Status = "paid";
                    //flush it since we need the new id
                    db.SaveChanges();
                    //save it down
                    return RedirectToAction("Details",
                        new { id = order.OrderId });
                }
        }
Beispiel #17
0
        public void Handle(IPlaceOrderCommand message)
        {
            MusicStoreEntities storeDB = new MusicStoreEntities();

            var order = new MvcMusicStore.Models.Order();

            order.Username  = message.UserId;
            order.OrderDate = DateTime.Now;
            order.OrderId   = message.OrderId;

            // Save Order
            storeDB.AddToOrders(order);
            storeDB.SaveChanges();

            //Process the order
            var cart = new ShoppingCart(message.CartId);

            cart.CreateOrder(order);

            this.Bus.Publish <IOrderAcceptedEvent>(o => o.OrderId = order.OrderId);
        }
        public async Task<ActionResult> AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            if (ModelState.IsValid 
                && string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase))
            {
                order.Username = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                _storeContext.Orders.Add(order);

                await ShoppingCart.GetCart(_storeContext, this).CreateOrder(order);

                await _storeContext.SaveChangesAsync();

                return RedirectToAction("Complete", new { id = order.OrderId });
            }

            return View(order);
        }
Beispiel #19
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode, 
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    return View(order);
                }

                order.Username = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                //Process the order
                var cart = ShoppingCartFinder.FindShoppingCart();
                cart.CreateOrder(order);

                var soldAlbums = session.Load<Album>(order.Lines.Select(x=>x.Album.Id).ToArray());
                foreach (var soldAlbum in soldAlbums)
                {
                    soldAlbum.CountSold++;
                }

                session.Store(order);
                session.SaveChanges();

                return RedirectToAction("Complete", 
                                        new { id = order.Id });
            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
        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;
        }
Beispiel #21
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;
            return 0;
        }
        public ActionResult EditOrder(int id, Order order)
        {
            if (ModelState.IsValid)
            {
                var o = db.Orders.Find(id);
                o.Status = order.Status;

                //Add SMS Notification Here

                db.SaveChanges();
                return RedirectToAction("Orders");
            }

            return View(order);
        }
Beispiel #23
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }
Beispiel #24
0
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 /// <param name="orderDate">Initial value of the OrderDate property.</param>
 /// <param name="total">Initial value of the Total property.</param>
 public static Order CreateOrder(global::System.Int32 orderId, global::System.DateTime orderDate, global::System.Decimal total)
 {
     Order order = new Order();
     order.OrderId = orderId;
     order.OrderDate = orderDate;
     order.Total = total;
     return order;
 }
Beispiel #25
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;
        }
Beispiel #26
0
 public int CreateOrder(Order order)
 {
     var cartItems = GetCartItems();
     return CreateOrder(order, cartItems);
 }
Beispiel #27
0
        public async Task<int> CreateOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = await _storeContext.Carts
                .Where(c => c.CartId == _cartId)
                .Include(c => c.Album)
                .ToListAsync();

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

                orderTotal += item.Count * item.Album.Price;
            }

            order.Total = orderTotal;

            await EmptyCart();

            return order.OrderId;
        }
Beispiel #28
0
        public ActionResult AddressAndPaymentCompleted(Order order, bool success)
        {
            if (success)
                return RedirectToAction("Complete",
                   new { id = order.OrderId });

            //Invalid - redisplay with errors
            return View(order);
        }
Beispiel #29
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;
        }