コード例 #1
0
        public ActionResult MyPage()
        {
            if (!LoginStatus())
            {
                return RedirectToAction("Index", "Home");
            }

            string Email = (string)Session["Email"];
            var Customer = _accountBLL.GetCustomer(Email);
            var customerView = new CustomerView()
            {
                CustomerId= Customer.CustomerId,
                Email = Customer.Email,
                Firstname = Customer.Firstname,
                Lastname = Customer.Lastname,
                Address = Customer.Address,
                Zipcode = Customer.Zipcode,
                City = Customer.City
            };

            var orders = Customer.Orders;
            var customerOrders = new List<OrderView>();

            foreach (var o in orders)
            {
                var order = new OrderView();
                order.Date = o.Date;
                order.OrderId = o.OrderId;
                order.Orderlines = new List<OrderlineView>();

                foreach(var l in o.Orderlines)
                {
                    var orderline = new OrderlineView();
                    orderline.Count = l.Count;
                    orderline.OrderlineId = l.OrderlineId;
                    orderline.Product = new ProductView()
                    {
                        Price = l.ProductPrice,
                        ProductId = l.ProductId,
                        ProductName = l.ProductName
                    };

                    order.Orderlines.Add(orderline);
                }
                customerOrders.Add(order);
            }

            ViewBag.LoggedIn = LoginStatus();
            ViewBag.Customer = customerView;
            ViewBag.CustomerOrders = customerOrders;

            return View();
        }
コード例 #2
0
ファイル: OrderController.cs プロジェクト: maglunde/Tankshop
        public PartialViewResult OrdersPartial(int CustomerId)
        {
            List<OrderModel> orderModels;
            if (CustomerId > 0)
                orderModels = _orderBLL.GetOrders(CustomerId);
            else
                orderModels = _orderBLL.GetAllOrders();

            var orderViews = new List<OrderView>();

            foreach (var o in orderModels)
            {
                var order = new OrderView();
                order.Date = o.Date;
                order.OrderId = o.OrderId;
                order.CustomerId = o.CustomerId;
                order.Orderlines = new List<OrderlineView>();

                foreach (var l in o.Orderlines)
                {
                    var orderline = new OrderlineView();
                    orderline.Count = l.Count;
                    orderline.OrderlineId = l.OrderlineId;
                    orderline.Product = new ProductView()
                    {
                        Price = l.ProductPrice,
                        ProductId = l.ProductId,
                        ProductName = l.ProductName
                    };

                    order.Orderlines.Add(orderline);
                }
                orderViews.Add(order);
            }

            var productModels = _orderBLL.GetAllProducts();
            var productViews = new List<ProductView>();

            foreach (var productModel in productModels)
            {
                var productview = new ProductView()
                {
                    ProductId = productModel.ProductId,
                    ProductName = productModel.ProductName,
                    Description = productModel.Description,
                    Price = productModel.Price,
                    Stock = productModel.Stock,
                    //ImageUrl = productModel.ImageUrl,
                    //CategoryName = productModel.CategoryName
                    CategoryId = productModel.CategoryId
                };
                productViews.Add(productview);
            }

            string Title = CustomerId == 0 ? "Ordreadministrasjon - Alle ordre" : (CustomerId > 0 ? "Ordreadministrasjon - Kunde": "Feil kunde id");

            ViewBag.Orders = orderViews;
            ViewBag.Products = productViews;
            ViewBag.Title = Title;

            return PartialView();
        }
コード例 #3
0
        public void Order_OrderPartial_ListCustomerOrders()
        {
            // Arrange
            var Controller = new OrderController(new OrderBLL(new OrderRepoStub()));

            var expOrderViews = new List<OrderView>();
            var expProductViews = new List<ProductView>();
            var expViewName = "";
            var expTitle = "Ordreadministrasjon - Kunde";

            foreach (var o in orderModels)
            {
                var order = new OrderView();
                order.Date = o.Date;
                order.OrderId = o.OrderId;
                order.CustomerId = o.CustomerId;
                order.Orderlines = new List<OrderlineView>();

                foreach (var l in o.Orderlines)
                {
                    var orderline = new OrderlineView();
                    orderline.Count = l.Count;
                    orderline.OrderlineId = l.OrderlineId;
                    orderline.Product = new ProductView()
                    {
                        Price = l.ProductPrice,
                        ProductId = l.ProductId,
                        ProductName = l.ProductName
                    };

                    order.Orderlines.Add(orderline);
                }
                expOrderViews.Add(order);
            }

            foreach (var productModel in productModels)
            {
                var productview = new ProductView()
                {
                    ProductId = productModel.ProductId,
                    ProductName = productModel.ProductName,
                    Description = productModel.Description,
                    Price = productModel.Price,
                    Stock = productModel.Stock,
                    CategoryId = productModel.CategoryId
                };
                expProductViews.Add(productview);
            }

            // Act
            var result = Controller.OrdersPartial(CUSTOMER_ORDERS);

            var viewBagOrders = result.ViewBag.Orders;
            var viewBagProducts = result.ViewBag.Products;
            var viewBagTitle = result.ViewBag.Title;

            //// Assert
            Assert.AreEqual(expViewName, result.ViewName);

            for (int i = 0; i < viewBagOrders.Count; i++)
            {
                Assert.AreEqual(expOrderViews[i].OrderId, viewBagOrders[i].OrderId);
                Assert.AreEqual(expOrderViews[i].CustomerId, viewBagOrders[i].CustomerId);
                Assert.AreEqual(expOrderViews[i].Date, viewBagOrders[i].Date);
                for (int j = 0; j < expOrderViews[i].Orderlines.Count; j++)
                {
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Count, viewBagOrders[i].Orderlines[j].Count);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].OrderlineId, viewBagOrders[i].Orderlines[j].Count);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.ProductId, viewBagOrders[i].Orderlines[j].Product.ProductId);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.ProductName, viewBagOrders[i].Orderlines[j].Product.ProductName);
                    Assert.AreEqual(expOrderViews[i].Orderlines[j].Product.Price, viewBagOrders[i].Orderlines[j].Product.Price);
                }
            }

            for (int i = 0; i < viewBagProducts.Count; i++)
            {
                Assert.AreEqual(expProductViews[i].ProductId, viewBagProducts[i].ProductId);
                Assert.AreEqual(expProductViews[i].ProductName, viewBagProducts[i].ProductName);
                Assert.AreEqual(expProductViews[i].Price, viewBagProducts[i].Price);
                Assert.AreEqual(expProductViews[i].Description, viewBagProducts[i].Description);
                Assert.AreEqual(expProductViews[i].Stock, viewBagProducts[i].Stock);
                Assert.AreEqual(expProductViews[i].CategoryId, viewBagProducts[i].CategoryId);
            }

            Assert.AreEqual(expTitle, viewBagTitle);
        }