示例#1
0
        public void AddProductToOrder(int orderId, int productId, int quantity)
        {
            var orderProduct = new OrderProduct();

            orderProduct.OrderId   = orderId;
            orderProduct.ProductId = productId;
            orderProduct.Quantity  = quantity;

            orderProductRepository.Insert(orderProduct);
            UpdateOrderTotalPrice(orderId);
        }
示例#2
0
 public Customer CreateCustomer(string name, string phone, string address, string email, string password)
 {
     customerRepository.Insert(new Customer {
         Name = name, EmployeeId = 1, Parola = password, Address = address, Email = email, Phone = phone
     });
     return(customerRepository.Query().Where(x => x.Email == email && x.Parola == password).First());
 }
示例#3
0
        public void CreateProduct(string name, string description, decimal price, int kcal)
        {
            Product prod = new Product();

            prod.Name        = name;
            prod.Kcal        = kcal;
            prod.Description = description;
            prod.Price       = price;

            productRepository.Insert(prod);
        }
示例#4
0
        public void CreateOrder(DateTime date, DateTime shipmentDate, decimal totalPrice, int customerId)
        {
            Order order = new Order();

            order.OrderDate    = date;
            order.ShipmentDate = shipmentDate;
            order.TotalPrice   = 0M;
            order.CustomerId   = customerId;

            orderRepository.Insert(order);
        }
示例#5
0
        public int CreateOrder(DateTime date, DateTime shipmentDate, decimal totalPrice, int customerId)
        {
            Order order = new Order();

            order.OrderDate    = date;
            order.ShipmentDate = shipmentDate;
            order.TotalPrice   = 0M;
            order.CustomerId   = customerId;

            orderRepository.Insert(order);

            var ord = GetAllOrders().Last();

            return(ord.OrderId);
        }
示例#6
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));
             */
        }
示例#7
0
 public static void CreateCustomer(string name, string phone, string address, string email, string password)
 {
     customerRepository.Insert(new Customer {
         Name = name, Parola = password, Address = address, Email = email, Phone = phone
     });
 }