public List<CartItem> GetCartList()
        {
            var ch = new CookieHandler();
            var productIdList = ch.GetCartProductIds();
            var productModelList = Services.Products.GetAll(productIdList);

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

            return cartItemList;
        }
Ejemplo n.º 2
0
        public ActionResult Checkout()
        {
            if (Session["LoggedIn"] != null)
            {
                if ((bool)Session["LoggedIn"])
                {
                    var productBLL = new ProductBLL();
                    var ch = new CookieHandler();

                    var Email = (string)Session["Email"];
                    var pidList = ch.GetCartProductIds();
                    var productModelList = productBLL.GetProducts(pidList);

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

                    var customerModel = new AccountBLL().GetCustomer(Email);
                    var customer = new CustomerView()
                    {
                        Firstname = customerModel.Firstname,
                        Lastname = customerModel.Lastname,
                        Address = customerModel.Address,
                        Zipcode = customerModel.Zipcode,
                        City = customerModel.City,
                        CustomerId = customerModel.CustomerId,
                        Email = customerModel.Email

                    };

                    ViewBag.Cart = cart;
                    ViewBag.Customer = customer;
                    ViewBag.LoggedIn = LoginStatus();
                    TempData["Message"] = "";
                    return View();
                }
            }
            TempData["Message"] = "Logg inn for å betale";
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 3
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");
        }