public Order GetOrder(int orderId) { var dbOrder = db.Orders.Find(orderId); if (dbOrder == null) return null; var order = new Order() { CustomerId = dbOrder.CustomerId, OrderId = dbOrder.OrderId, Orderlines = db.Orderlines.Where(l => l.OrderId == dbOrder.OrderId).Select(l => new Orderline() { 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; }
public void order_is_equal() { //Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new OrderController(new OrderBLL(new OrderDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true }; var order = new Order() { id = 298423, customerid = 1, orderdate = DateTime.Now }; //Act var actrow = (ViewResult)controller.ListOrders(null, null, null); var result = (IPagedList<OrderViewModel>)actrow.Model; //Assert Assert.AreEqual(actrow.ViewName, "" ); Assert.AreEqual(result[0].id, order.id); Assert.AreEqual(result[0].customerid, order.customerid); }
public int getSum(Order o) { var sum = 0; foreach (var item in o.orderLine ) { sum += item.quantity * item.product.price; } return sum; }
public int getNumItems(Order o) { var num = 0; foreach(var item in o.orderLine) { num += item.quantity; } return num; }
public CustomerRepoStub() { orderlineModel = new Orderline() { Count = 1, OrderId = 1, OrderlineId = 1, ProductId = 1, ProductName = "Tank", ProductPrice = 500000 }; orderlineModels = new List<Orderline>(); orderlineModels.Add(orderlineModel); orderlineModels.Add(orderlineModel); orderlineModels.Add(orderlineModel); orderModel = new Order() { CustomerId = 1, Date = new DateTime(2015, 1, 1), OrderId = 1, Orderlines = orderlineModels }; orderModels = new List<Order>(); orderModels.Add(orderModel); orderModels.Add(orderModel); orderModels.Add(orderModel); customerModel = new Customer() { CustomerId = 1, Email = "*****@*****.**", Firstname = "Ole", Lastname = "Olsen", Address = "Persveien 5", Postal = new Postal { Zipcode = "0123", City = "Oslo" }, Orders = orderModels }; }
public int PlaceOrder(Order order) { return _repo.PlaceOrder(order); }
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; } } }
public List<Order> getAllOrdersbyCust(int id) { List<Order> list = new List<Order>(); var order = new Order() { id = 298423, customerid = 1, orderdate = DateTime.Now }; var order1 = new Order() { id = 298424, customerid = 2, orderdate = DateTime.Now }; var order2 = new Order() { id = 298425, customerid = 3, orderdate = DateTime.Now }; list.Add(order); list.Add(order1); list.Add(order2); return list; }
public List<Order> getAllOrders(int? id) { List<Order> list = new List<Order>(); if (id == 298423) { var order = new Order() { id = 298423, customerid = 1, orderdate = DateTime.Now }; list.Add(order); return list; } var order0 = new Order() { id = 298423, customerid = 1, orderdate = DateTime.Now }; var order1 = new Order() { id = 298424, customerid = 2, orderdate = DateTime.Now }; var order2 = new Order() { id = 298425, customerid = 4, orderdate = DateTime.Now }; var order3 = new Order() { id = 298426, customerid = 5, orderdate = DateTime.Now }; var order4 = new Order() { id = 298427, customerid = 6, orderdate = DateTime.Now }; var order5 = new Order() { id = 298428, customerid = 7, orderdate = DateTime.Now }; list.Add(order0); list.Add(order1); list.Add(order2); list.Add(order3); list.Add(order4); list.Add(order5); return list; }
public Order GetReciept(int orderId) { var dbOrder = db.Orders.Find(orderId); var orderModel = new Order() { CustomerId = dbOrder.CustomerId, Date = dbOrder.Date, OrderId = dbOrder.OrderId, Orderlines = dbOrder.Orderlines.Select(l => new Orderline() { Count = l.Count, OrderlineId = l.OrderlineId, ProductId = l.ProductId, ProductName = l.Product.Name, ProductPrice = l.Product.Price }).ToList() }; return orderModel; }
public int PlaceOrder(Order order) { try { var newOrder = new 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; } }
public void order_listOrderLines_is_not_null() { // Arrange TestControllerBuilder builder = new TestControllerBuilder(); var controller = new OrderController(new OrderBLL(new OrderDALStub())); builder.InitializeController(controller); builder.HttpContext.Session["loggedInUser"] = new Customer() { admin = true }; var order = new Order() { id = 298423, customerid = 1, orderdate = DateTime.Now }; // Act var actrow = (ViewResult)controller.ListOrderLines(298423, null, null, null); var result = (IPagedList<OrderLineViewModel>)actrow.Model; // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IPagedList<OrderLineViewModel>)); Assert.AreEqual(result[0].orderId , order.id ); Assert.IsTrue(result[0].id <= result[1].id); }