Ejemplo n.º 1
0
        public OrderModel GetOrder(int orderId)
        {
            using (var db = new TankshopDbContext())
            {
                var dbOrder = db.Orders.Find(orderId);
                if (dbOrder == null)
                    return null;

                var order = new OrderModel()
                {
                    CustomerId = dbOrder.CustomerId,
                    OrderId = dbOrder.OrderId,
                    Orderlines = db.Orderlines.Where(l => l.OrderId == dbOrder.OrderId).Select(l => new OrderlineModel()
                    {
                        OrderlineId = l.OrderlineId,
                        OrderId = l.OrderId,
                        ProductId = l.ProductId,
                        Count = l.Count,
                        ProductName = l.Product.Name,
                        ProductPrice = l.Product.Price

                    }).ToList(),
                    Date = dbOrder.Date
                };

                return order;
            }
        }
Ejemplo n.º 2
0
        public OrderRepoStub()
        {
            // DomainModels
            orderlineModel = new OrderlineModel()
            {
                Count = 1,
                OrderId = 1,
                OrderlineId = 1,
                ProductId = 1
            };

            orderlineModels = new List<OrderlineModel>();
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);

            orderModel = new OrderModel()
            {
                CustomerId = 1,
                Date = new DateTime(2015, 1, 1),
                OrderId = 1,
                Orderlines = orderlineModels
            };

            orderModels = new List<OrderModel>();
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
        }
Ejemplo n.º 3
0
        public CustomerControllerTest()
        {
            orderlineModel = new OrderlineModel()
            {
                Count = 1,
                OrderId = 1,
                OrderlineId = 1,
                ProductId = 1,
                ProductName = "Tank",
                ProductPrice = 500000
            };

            orderlineModels = new List<OrderlineModel>();
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);

            orderModel = new OrderModel()
            {
                CustomerId = 1,
                Date = new DateTime(2015, 1, 1),
                OrderId = 1,
                Orderlines = orderlineModels
            };

            orderModels = new List<OrderModel>();
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);

            customerModel = new CustomerModel()
            {
                CustomerId = 1,
                Email = "*****@*****.**",
                Firstname = "Ole",
                Lastname = "Olsen",
                Address = "Persveien 5",
                Zipcode = "0123",
                City = "Oslo",
                Orders = orderModels
            };

            userEmail = "*****@*****.**";
            anotherUserEmail = "*****@*****.**";
            adminEmail = "admin";
        }
Ejemplo n.º 4
0
        public OrderControllerTest()
        {
            orderlineModel = new OrderlineModel()
            {
                Count = 1,
                OrderId = 1,
                OrderlineId = 1,
                ProductId = 1
            };

            orderlineModels = new List<OrderlineModel>();
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);

            orderModel = new OrderModel()
            {
                CustomerId = 1,
                Date = new DateTime(2015, 1, 1),
                OrderId = 1,
                Orderlines = orderlineModels
            };

            orderModels = new List<OrderModel>();
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);

            productModel = new ProductModel
            {
                ProductId = 1,
                ProductName = "tank",
                Price = 150,
                Stock = 5,
                Description = "blows things up",
                CategoryId = 1
            };

            productModels = new List<ProductModel>();
            productModels.Add(productModel);
            productModels.Add(productModel);
            productModels.Add(productModel);
        }
Ejemplo n.º 5
0
 public int PlaceOrder(OrderModel order)
 {
     return _repo.PlaceOrder(order);
 }
Ejemplo n.º 6
0
 public int PlaceOrder(OrderModel order)
 {
     if (order.CustomerId == 0)
         return 0;
     return 1;
 }
Ejemplo n.º 7
0
        public ActionResult PlaceOrder(string returnUrl)
        {
            if (Session["LoggedIn"] != null)
            {
                if ((bool)Session["LoggedIn"])

                {
                    var productBLL = new ProductBLL();
                    var ch = new CookieHandler();

                    var productIdList = ch.GetCartProductIds();
                    var productModelList = productBLL.GetProducts(productIdList);

                    var cart = productModelList.Select(p => new CartItem()
                    {
                        ProductId = p.ProductId,
                        Name = p.ProductName,
                        Count = ch.GetCount(p.ProductId),
                        Price = p.Price
                    }).ToList();

                    var order = new OrderModel();
                    var orderlines = new List<OrderlineModel>();

                    foreach (var item in cart)
                    {
                        orderlines.Add(new OrderlineModel()
                        {
                            Count = item.Count,
                            ProductId = item.ProductId
                        });
                    }
                    order.Orderlines = orderlines;
                    order.CustomerId = new AccountBLL().GetCustomer((String)Session["Email"]).CustomerId;
                    order.Date = DateTime.Now;
                    var OrderId = _orderBLL.PlaceOrder(order);

                    if (OrderId > 0)
                    {
                        ch.EmptyCart();

                        ViewBag.LoggedIn = (bool)Session["LoggedIn"];
                        ViewBag.Reciept = GetReciept(OrderId);

                        return View("GetReciept");
                    }
                }
            }
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 8
0
        public int PlaceOrder(OrderModel order)
        {
            using (var db = new TankshopDbContext())
            {
                try
                {
                    var newOrder = new Nettbutikk.Model.Order()
                    {
                        CustomerId = order.CustomerId,
                        Date = order.Date
                    };

                    foreach (var item in order.Orderlines)
                    {
                        var product = db.Products.Find(item.ProductId);
                        var orderline = new Orderline()
                        {
                            Product = product,
                            Count = item.Count,
                            ProductId = item.ProductId
                        };

                        newOrder.Orderlines.Add(orderline);
                    }

                    db.Orders.Add(newOrder);
                    db.SaveChanges();
                    return newOrder.OrderId;
                }
                catch (Exception)
                {
                    return 0;
                }
            }
        }
Ejemplo n.º 9
0
        public OrderModel GetReciept(int orderId)
        {
            using (var db = new TankshopDbContext())
            {
                var dbOrder = db.Orders.Find(orderId);
                var orderModel = new OrderModel()
                {
                    CustomerId = dbOrder.CustomerId,
                    Date = dbOrder.Date,
                    OrderId = dbOrder.OrderId,
                    Orderlines = dbOrder.Orderlines.Select(l => new OrderlineModel()
                    {
                        Count = l.Count,
                        OrderlineId = l.OrderlineId,
                        ProductId = l.ProductId,
                        ProductName = l.Product.Name,
                        ProductPrice = l.Product.Price
                    }).ToList()
                };

                return orderModel;
            }
        }