Beispiel #1
0
        private Order GetOrderById(int orderId)
        {
            var order = (from o in orderRepository.Query()
                         where o.OrderId == orderId
                         select o).SingleOrDefault();

            return(order);
        }
Beispiel #2
0
        public int CheckCustomerExists(string email, string pass)
        {
            int p = customerRepository.Count();
            int q = customerRepository.Query().Where(x => x.Email == email && x.Parola == pass).Count();

            if (q != 0)
            {
                int id = customerRepository.Query().Where(x => x.Email == email && x.Parola == pass).Select(x => x.CustomerId).FirstOrDefault();
                return(id);
            }
            return(-1);
        }
Beispiel #3
0
        public static int CheckCustomerExists(string email, string pass)
        {
            var data = from c in customerRepository.Query()
                       where c.Email.Equals(email)
                       select c;
            int q = customerRepository.Query().Where(x => x.Email == email && x.Parola == pass).Count();

            if (q != 0)
            {
                int id = customerRepository.Query().Where(x => x.Email == email && x.Parola == pass).Select(x => x.CustomerId).FirstOrDefault();
                return(id);
            }
            return(-1);
        }
Beispiel #4
0
        public List <Product> GetProductsByName(string productName)
        {
            var products = (from p in productRepository.Query()
                            where p.Name.Contains(productName)
                            select p).ToList();

            return(products);
        }
Beispiel #5
0
        public List <Product> GetProductsOfOrder(int orderNumber)
        {
            //Have to run the queries separate as each repository uses a different database context and thus I cannot use join linq queries
            var productIds = (from op in orderProductRepository.Query()
                              where op.OrderId == orderNumber
                              select op.ProductId).ToList();

            var products = (from p in productRepository.Query()
                            where productIds.Contains(p.ProductId)
                            select p).ToList();

            return(products);
        }
Beispiel #6
0
        public void UpdateOrderTotalPrice(int orderId)
        {
            var orderedProducts = (from op in orderProductRepository.Query()
                                   where op.OrderId == orderId
                                   select new { op.ProductId, op.Quantity }).ToList();

            var products = (from p in productRepository.Query()
                            select new { p.ProductId, p.Price }).ToList();

            decimal price = 0;

            foreach (var product in orderedProducts)
            {
                var prod = products.SingleOrDefault(x => x.ProductId == product.ProductId);

                price += prod.Price * product.Quantity;
            }

            Order order = GetOrderById(orderId);

            order.TotalPrice = price;

            orderRepository.Update(order);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            //Testing the OrderService
            EntityIO <Order> orderRepository = new EntityIO <Order>();

            Console.WriteLine(orderRepository.Count());

            Order ord = new Entities.Order();

            ord.OrderDate    = DateTime.Today;
            ord.ShipmentDate = DateTime.Today.AddDays(3);
            ord.CustomerId   = 3;
            ord.TotalPrice   = 0M;

            orderRepository.Insert(ord);

            var order = (from o in orderRepository.Query()
                         where o.OrderId == 5
                         select o).SingleOrDefault();

            Console.WriteLine(String.Format("Order with the id {0} has a total price of {1}, the order was made on {2} and the shipment is estimated on {3}",
                                            order.OrderId,
                                            order.TotalPrice,
                                            order.OrderDate,
                                            order.ShipmentDate));

            //Add the 3 most expensive products to the order (useful, if if there was a 'menu of the day')
            EntityIO <Product> productRepository = new EntityIO <Product>();
            var products = (from p in productRepository.Query()
                            orderby p.Price descending
                            select p).Take(3).ToList();


            EntityIO <OrderProduct> orderProductRepository = new EntityIO <OrderProduct>();

            foreach (var product in products)
            {
                OrderProduct orderProduct = new OrderProduct();

                orderProduct.Quantity  = products.GroupBy(p => product).ToList().Count();
                orderProduct.OrderId   = 5;
                orderProduct.ProductId = product.ProductId;

                orderProductRepository.Insert(orderProduct);
            }


            var orderedProducts = (from op in orderProductRepository.Query()
                                   where op.OrderId == 5
                                   select new { op.ProductId, op.Quantity }).ToList();

            var prroducts = (from p in productRepository.Query()
                             select new { p.ProductId, p.Price }).ToList();

            decimal price = 0;

            foreach (var product in orderedProducts)
            {
                var prod = prroducts.SingleOrDefault(x => x.ProductId == product.ProductId);

                price += prod.Price * product.Quantity;
            }

            Order ordern = (from o in orderRepository.Query()
                            where o.OrderId == 5
                            select o).SingleOrDefault();

            ordern.TotalPrice = price;

            orderRepository.Update(ordern);

            Console.WriteLine(String.Format("Order with the id {0} has a total price of {1}, the order was made on {2} and the shipment is estimated on {3}",
                                            ordern.OrderId,
                                            ordern.TotalPrice,
                                            ordern.OrderDate,
                                            ordern.ShipmentDate));


            Console.ReadLine();

            /*  //Creates order
             * DateTime shipmentDate = DateTime.Today;
             * shipmentDate.AddDays(3);
             *
             * orderClient.CreateOrder(DateTime.Today, shipmentDate, 0, 2);
             *
             * //Add the 3 most expensive products to the order (useful, if if there was a 'menu of the day')
             * var products = productClient.GetTopMostExpensiveProducts(3);
             * //Manual conversion from ProductService.Product to OrderService.Product
             * var orderProducts = new List<OrderService.Product>();
             * foreach(var prod in products)
             * {
             *    var pr = new OrderService.Product();
             *
             *    pr.Name = prod.Name;
             *    pr.Description = prod.Description;
             *    pr.ProductId = prod.ProductId;
             *    pr.Kcal = prod.Kcal;
             *    pr.Price = prod.Price;
             *
             *    orderProducts.Add(pr);
             * }
             * orderClient.AddProductsToOrder(5, orderProducts);
             *
             * Console.WriteLine("The order we have jut placed:");
             * Console.WriteLine(orderClient.DisplayOrder(5));
             */
        }