public bool addToCart(int newProd, int inQuantity)
        {
            var ProductList = (List<ProductModel>)Session[PRODUCT_LIST];
            var cart = ((OrderModel)Session[SHOPPING_CART]);
            if (cart == null)
                cart = new OrderModel();
            if (ProductList == null)
                ProductList = new List<ProductModel>();

            foreach (var productInList in cart.products)
            {
                if (productInList.productID == newProd)
                {
                    productInList.quantity += inQuantity;
                    calculateTotal();
                    return true;                                                       // Product already exists in cart.
                }
            }
            foreach (var product in ProductList)
            {
                if (product.productID == newProd)
                {
                    product.quantity = inQuantity;
                    cart.products.Add(product);
                    calculateTotal();
                    return true;
                }

            }

            return false;
        }
 public void AllOrdersTest()
 {
     //Arrange
     var controller = new AdminOrderController(new OrderBLL(new OrderDALStub()), new LoggingBLL(new LoggingDALStub()));
     var list = new List<OrderModel>();
     var orderModel = new OrderModel();
     orderModel.customerID = 1;
     orderModel.orderNr = 1;
     orderModel.total = 100;
     list.Add(orderModel);
     list.Add(orderModel);
     list.Add(orderModel);
     list.Add(orderModel);
     //Act
     var result = (ViewResult)controller.AllOrders();
     var resultList = (List<OrderModel>)result.Model;
     //Assert
     Assert.AreEqual(result.ViewName, "");
     Assert.AreEqual(resultList.Count, list.Count);
     for (int i = 0; i < resultList.Count; i++)
     {
         Assert.AreEqual(resultList[i].customerID, list[i].customerID);
         Assert.AreEqual(resultList[i].orderNr, list[i].orderNr);
         Assert.AreEqual(resultList[i].total, list[i].total);
     }
 }
 public bool saveOrder(OrderModel orderModel)
 {
     if (orderModel == null)
         return false;
     Session[SHOPPING_CART] = null;
     _loggingBLL.logToDatabase("Kunde: " + orderModel.customerID + " bestilte ny ordre som ble lagt til i databasen.");
     _loggingBLL.logToUser("Bestilte en ny ordre.", (CustomerModel)Session[CUSTOMER]);
     return _orderBLL.add(orderModel);
 }
 public OrderModel find(int nr)
 {
     if (nr < 0)
         return null;
     var orderModel = new OrderModel();
     orderModel.customerID = 1;
     orderModel.orderNr = 1;
     orderModel.total = 100;
     return orderModel;
 }
Beispiel #5
0
        public List<OrderModel> allOrders()
        {
            var orderList = new List<OrderModel>();
            using (var db = new CustomerContext())
            {
                try
                {
                    var orders = (from o in db.Orders select o).ToList();
                    var orderModel = new OrderModel();

                    foreach (var o in orders) // finner alle ordre
                        orderList.Add(createOrderModel(o));
                    return orderList;
                }
                catch (Exception ex)
                {
                    _logging.logToDatabase(ex);
                }
            }
            return null;
        }
Beispiel #6
0
        /*Legger Orders og ProductOrders inn i databasen. CustomerID og pruductID-ene må være med i modellen*/
        public bool add(OrderModel orderModel)
        {
            using (var db = new CustomerContext())
            {
                try
                {
                    var customer = db.Customers.Find(orderModel.customerID);
                    if (customer == null)//tester om ordren tilhører en eksisterende kunde
                        return false;
                    var order = new Orders();
                    order.Customers = customer;
                    db.Orders.Add(order);
                    db.SaveChanges();
                    orderModel.orderNr = order.orderNr;//lagrer ordrenummeret i modellen for senere bruk
                    return addProductOrders(orderModel);//legger til produkt ordrene

                }
                catch (Exception ex)
                {
                    _logging.logToDatabase(ex);
                }
                return false;
            }
        }
Beispiel #7
0
 /*Legger Orders og ProductOrders inn i databasen. CustomerID og pruductID-ene må være med i modellen*/
 public bool add(OrderModel orderModel)
 {
     return _orderDAL.add(orderModel);
 }
 public void createCart()
 {
     if (Session[SHOPPING_CART] == null)                                    // Already created?
         Session[SHOPPING_CART] = new OrderModel();                          // This is the cart. It will be initialized by the createCart() method.
 }
 public bool add(OrderModel orderModel)
 {
     if (orderModel.customerID > 0)
         return true;
     return false;
 }
Beispiel #10
0
 public static OrderModel createOrder()
 {
     var order = new OrderModel();
     var product = createAfterDinnerBlend();
     product.productID = 1;
     order.products.Add(product);
     foreach (var p in order.products)
         p.quantity = 2;
     order.total=20000;
     return order;
 }
Beispiel #11
0
        private OrderModel createOrderModel(Orders order)
        {
            var orderModel = new OrderModel();
            using (var db = new CustomerContext())
            {
                if (order == null)//tester om orderen finnes
                    return null;
                try
                {
                    orderModel.orderNr = order.orderNr;
                    orderModel.customerID = order.personID;

                    var productOrders = (from p in db.ProductOrders
                                         where p.orderNr == order.orderNr
                                         select p).ToList();
                    orderModel.total = 0;
                    var productDAL = new ProductDAL();
                    foreach (var o in productOrders)//legger produktene til i order modellen
                    {
                        var productModel = productDAL.find(o.products.productID);
                        productModel.quantity = o.quantity;
                        orderModel.products.Add(productModel);
                        orderModel.total += o.price;
                    }
                    return orderModel;
                }
                catch (Exception ex)
                {
                    _logging.logToDatabase(ex);
                }
            }
            return null;
        }
Beispiel #12
0
 /*Legger ProductOrders inn i databasen. OrderNr og pruductID-ene må være med i modellen*/
 private bool addProductOrders(OrderModel orderModel)
 {
     using (var db = new CustomerContext())
         {
         try
         {
             var order = db.Orders.Find(orderModel.orderNr);
             if (order == null)//tester om ordren eksisterer
                 return false;
             var productDAL = new ProductDAL();
             foreach (var p in orderModel.products)//Opretter ProductOrders fra modellen
             {
                 p.stock -= p.quantity;
                 productDAL.updateQuantity(p);
                 var productOrder = new ProductOrders();
                 productOrder.orders = order;
                 productOrder.price = p.price;
                 productOrder.products = db.Products.Find(p.productID);
                 productOrder.quantity = p.quantity;
                 productOrder.price = p.price * p.quantity;
                 db.ProductOrders.Add(productOrder);
             }
             db.SaveChanges();
             return true;
             }
         catch (Exception ex)
         {
             _logging.logToDatabase(ex);
         }
         return false;
     }
 }
Beispiel #13
0
 //Henter ut en OrderModel fra en ordre med ordreNr lik nr
 public OrderModel find(int nr)
 {
     var orderModel = new OrderModel();
     using (var db = new CustomerContext())
     {
         try
         {
             var order = (from o in db.Orders
                          where o.orderNr == nr
                          select o).FirstOrDefault();
             return createOrderModel(order);
         }
         catch (Exception ex)
         {
             _logging.logToDatabase(ex);
         }
     }
     return null;
 }