public ActionResult Category(int CategoryId) { var categories = _categoryBLL.GetAllCategoryModels().Select(c => new CategoryView() { CategoryId = c.CategoryId, CategoryName = c.CategoryName } ).ToList(); var productModels = _productBLL.GetProductsByCategory(CategoryId).ToList(); var products = new List<ProductView>(); foreach (var product in productModels) { var imageViews = new List<ImageView>(); foreach (var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryId = product.CategoryId, CategoryName = product.CategoryName, Images = imageViews }; products.Add(productView); } ViewBag.Categories = categories; ViewBag.Products = products; ViewBag.LoggedIn = LoginStatus(); ViewBag.CategoryName = _categoryBLL.GetCategoryName(CategoryId) ?? "Epler?"; return View("Index"); }
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(); }
public OrderView GetReciept(int OrderId) { OrderModel reciept = _orderBLL.GetReciept(OrderId); var orderlines = new List<OrderlineView>(); foreach(var item in reciept.Orderlines) { var product = new ProductView() { ProductId = item.ProductId, ProductName = item.ProductName, Price = item.ProductPrice, }; orderlines.Add(new OrderlineView() { OrderlineId = item.OrderlineId, Count = item.Count, Product = product }); } OrderView orderView = new OrderView() { OrderId = reciept.OrderId, Date = reciept.Date, Orderlines = orderlines, }; return orderView ; }
public ActionResult Index() { var categories = _categoryBLL.GetAllCategoryModels().Select(c => new CategoryView() { CategoryId = c.CategoryId, CategoryName = c.CategoryName } ).ToList(); int firstCategoryWithProducts = _categoryBLL.FirstCategoryWithProducts(); var productModels = _productBLL.GetProductsByCategory(firstCategoryWithProducts).ToList(); var products = new List<ProductView>(); foreach (var product in productModels) { var imageViews = new List<ImageView>(); foreach(var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryId = product.CategoryId, CategoryName = product.CategoryName, Images = imageViews }; products.Add(productView); } ViewBag.Categories = categories ?? new List<CategoryView>(); ViewBag.Products = products ?? new List<ProductView>(); ViewBag.LoggedIn = LoginStatus(); ViewBag.CategoryName = _categoryBLL.GetCategoryName(firstCategoryWithProducts); ViewBag.Message = TempData["Message"] != null ? TempData["Message"] : ""; return View(); }
// GET: Product public ActionResult Product(int ProductId, string ReturnUrl) { var product = _productBLL.GetProductModel(ProductId); if (product == null) { return View("~/Views/Shared/Error.cshtml"); } var imageViews = new List<ImageView>(); foreach (var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryId = product.CategoryId, CategoryName = product.CategoryName, Images = imageViews }; ViewBag.Product = productView; ViewBag.ReturnUrl = ReturnUrl; ViewBag.LoggedIn = LoginStatus(); return View(); }
public ActionResult Index() { var productModels = _productBLL.GetAllProductModels(); var products = new List<ProductView>(); foreach (var product in productModels) { var imageViews = new List<ImageView>(); foreach (var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryName = product.CategoryName, Images = imageViews }; products.Add(productView); } ViewBag.Products = products; return View("ListProduct"); }
public ActionResult EditProduct(string ProductId) { List<SelectListItem> categoryIds = new List<SelectListItem>(); var allCategories = _categoryBLL.GetAllCategoryModels(); foreach (var c in allCategories) { string categoryId = Convert.ToString(c.CategoryId); categoryIds.Add(new SelectListItem { Text = c.CategoryName, Value = categoryId }); } ViewBag.CategoryIds = categoryIds; int nProductId; try { nProductId = Convert.ToInt32(ProductId); } catch (Exception e) { LogHandler.WriteToLog(e); ViewBag.Title = "Error"; ViewBag.Message = "Invalid prodct id: " + ProductId; return View("~/Views/Shared/Result.cshtml"); } var product = _productBLL.GetProductModel(nProductId); if (product == null) { ViewBag.Title = "Error"; ViewBag.Message = "Could not find a product with the id: " + ProductId; return View("~/Views/Shared/Result.cshtml"); } var imageViews = new List<ImageView>(); foreach (var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryId = product.CategoryId, CategoryName = product.CategoryName, Images = imageViews }; ViewBag.Product = productView; return View(); }
public ActionResult DeleteProduct(string ProductId) { int nProductId; try { nProductId = Convert.ToInt32(ProductId); } catch (Exception e) { LogHandler.WriteToLog(e); ViewBag.Title = "Error"; ViewBag.Message = "Invalid prodct id: " + ProductId; return View("~/Views/Shared/Result.cshtml"); } var product = _productBLL.GetProductModel(nProductId); if (product == null) { ViewBag.Title = "Error"; ViewBag.Message = "Could not find a product with the id: " + ProductId; return View("~/Views/Shared/Result.cshtml"); } var imageViews = new List<ImageView>(); foreach (var image in product.Images) { var imageView = new ImageView() { ImageId = image.ImageId, ProductId = image.ProductId, ImageUrl = image.ImageUrl }; imageViews.Add(imageView); } var productView = new ProductView() { ProductId = product.ProductId, ProductName = product.ProductName, Description = product.Description, Price = product.Price, Stock = product.Stock, CategoryName = product.CategoryName, Images = imageViews }; ViewBag.Product = productView; return View(); }
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); }