Exemplo n.º 1
0
 public Order getOrder(int? id)
 {
     if(id == 0)
     {
         var order = new Order();
         order.OrderId = 0;
         return order;
     }
     else
     {
         var ord = new Order()
         {
             OrderId = 1,
             Address = "Los",
             City = "Angeles",
             FirstName = "Hellloooo",
             LastName = "Bellooooo",
             Email = "*****@*****.**",
             OrderDate = DateTime.Now,
             Phone = "123456",
             PostalCode = "123",
             Total = 1234,
             UserId = "1",
             Username = "******"
         };
         return ord;
     }
 }
Exemplo n.º 2
0
        public int CreateOrder(Order order, ShoppingCart cart)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems(cart);

            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    ProductId = item.ProductId,
                    OrderId = order.OrderId,
                    ProductPrice = item.Product.Price,
                    Quantity = item.Count
                };

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

                storeDB.OrderDetails.Add(orderDetail);

            }

            order.Total = orderTotal;

            order.OrderDetails = storeDB.OrderDetails.Where(o => o.OrderId == order.OrderId).ToList();

            storeDB.SaveChanges();

            EmptyCart(cart);

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

            try
            {
                if(string.Equals(values["Promotion_Code_Box"], string.Empty) == true)
                {
                    order.Username = User.Identity.Name;
                    order.UserId = User.Identity.GetUserId();
                    order.OrderDate = DateTime.Now;

                    db.addOrder(order);

                    var cart = cartBLL.GetCart(this.HttpContext);
                    var tot = cartBLL.getTotalBefore(order, cart);
                    cartBLL.CreateOrder(order, cart);

                    order.Total = tot;
                    db.editOrder(order);
                    order.OrderDetails = order.OrderDetails;
                    db.save();

                    return RedirectToAction("Complete", new { id = order.OrderId });
                }
                else if (string.Equals(values["Promotion_Code_Box"], PromotionCode,
                    StringComparison.OrdinalIgnoreCase) == false)
                {
                    ViewBag.Wrong = " Wrong Promotion Code. Please write a valid promotion code, or leave this field empty.";
                    return View(order);
                }
                else
                {
                    order.Username = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    db.addOrder(order);

                    db.save();

                    var cart = cartBLL.GetCart(this.HttpContext);
                    var tot = cartBLL.getTotalBefore(order, cart);
                    cartBLL.CreateOrder(order, cart);

                    order.Total = tot / 2;
                    db.editOrder(order);
                    db.save();

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

                return View(order);
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(Order order)
        {
            if (ModelState.IsValid)
            {
                db.addOrder(order);
                return RedirectToAction("Index");
            }

            return View(order);
        }
Exemplo n.º 5
0
 public bool editOrder(Order order)
 {
     if(order != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 6
0
 public int CreateOrder(Order order, ShoppingCart cart)
 {
     if (order != null && cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }
Exemplo n.º 7
0
 public bool addOrder(Order order)
 {
     var db = new ProductContext();
     if(order != null)
     {
         db.Orders.Add(order);
         db.SaveChanges();
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
 public bool editOrder(Order order)
 {
     if(order != null)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 9
0
 public IEnumerable<Order> getOrderHistory(string id)
 {
     if(!id.Equals(String.Empty))
     {
         var oh = new List<Order>();
         var ord = new Order()
         {
             OrderId = 1,
             Address = "Los",
             City = "Angeles",
             FirstName = "Hellloooo",
             LastName = "Bellooooo",
             Email = "*****@*****.**",
             OrderDate = DateTime.Now,
             Phone = "123456",
             PostalCode = "123",
             Total = 1234,
             UserId = "1",
             Username = "******"
         };
         oh.Add(ord);
         oh.Add(ord);
         return oh;
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 10
0
 public bool editOrder(Order order)
 {
     return db.editOrder(order);
 }
Exemplo n.º 11
0
 public bool addOrder(Order order)
 {
     var db = new OrderDAL();
     return db.addOrder(order);
 }
Exemplo n.º 12
0
 public decimal getTotalBefore(Order order, ShoppingCart cart)
 {
     return temp.getTotalBefore(order, cart);
 }
Exemplo n.º 13
0
 public int CreateOrder(Order order, ShoppingCart cart)
 {
     return temp.CreateOrder(order, cart);
 }
Exemplo n.º 14
0
        public decimal getTotalBefore(Order order, ShoppingCart cart)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems(cart);

            foreach (var item in cartItems)
            {
                orderTotal += (item.Count * item.Product.Price);
            }

            return orderTotal;
        }
Exemplo n.º 15
0
 public decimal getTotalBefore(Order order, ShoppingCart cart)
 {
     if (order != null && cart != null)
     {
         return 1;
     }
     else
     {
         return -1;
     }
 }