Beispiel #1
0
        //Deletes an order. Returns true if it succeeds.
        public bool Delete(OrderDTO orderDto)
        {
            var order = _orderRepository
                        .Set()
                        .FirstOrDefault(o => o.OrderID == orderDto.OrderID);

            var orderDetailServices = new OrderDetailServices();

            if (order.Customer != null)
            {
                if ((order.Customer.Country != "Mexico") && (order.Customer.Country != "France"))
                {
                    orderDetailServices.DeleteByOrderID(order.OrderID);

                    _orderRepository.Remove(order);
                    _orderRepository.SaveChanges();
                    return(true);
                }
            }
            else
            {
                orderDetailServices.DeleteByOrderID(order.OrderID);

                _orderRepository.Remove(order);
                _orderRepository.SaveChanges();
                return(true);
            }


            return(false);
        }
Beispiel #2
0
        public ProductDTO2 GetBestSellingProduct(string country)
        {
            var productServices     = new ProductServices();
            var orderDetailServices = new OrderDetailServices();

            var productList     = productServices.GetAllProducts();
            var orderDetailList = orderDetailServices.GetAllOrderDetails();


            var orderGroup = _orderRepository.Set().GroupBy(o => o.Customer.Country);

            var ordersInCountry = new List <Order>();

            foreach (var group in orderGroup)
            {
                foreach (var order in group)
                {
                    if (group.Key == country)
                    {
                        ordersInCountry.Add(order);
                    }
                }
            }

            foreach (var o in ordersInCountry)
            {
                foreach (var od in o.Order_Details)
                {
                    foreach (var p in productList)
                    {
                        if (p.ProductID == od.ProductID)
                        {
                            p.TotalQuantity += od.Quantity;
                        }
                    }
                }
            }

            decimal currentValue;
            decimal maxValue = 0;

            ProductDTO2 BestSellingProduct = null;

            foreach (var p in productList)
            {
                currentValue = p.TotalQuantity;
                if (currentValue > maxValue)
                {
                    maxValue           = currentValue;
                    BestSellingProduct = p;
                }
            }

            return(BestSellingProduct);
        }
        public decimal TotalMoneySpent(string id)
        {
            var customer = _customerRepository
                           .Set()
                           .FirstOrDefault(c => c.CustomerID == id);

            if (customer == null)
            {
                return(0);
            }

            var orderDetailServices = new OrderDetailServices();

            decimal grandTotal = 0;

            foreach (var o in customer.Orders)
            {
                grandTotal += orderDetailServices.Total(o.OrderID);
            }

            return(grandTotal);
        }