public ServicesController() { context = new DataAccess.Context(); customerServices = new CustomerServices(); employeeServices = new EmployeeServices(); orderServices = new OrderServices(); orderDetailsServices = new OrderDetailsServices(); productServices = new ProductServices(); }
public ServicesController() { this.context = new DataAccess.Context(); this.customerServices = new CustomerServices(); this.employeeServices = new EmployeeServices(); this.orderServices = new OrderServices(); this.orderDetailsServices = new OrderDetailsServices(); this.productServices = new ProductServices(); }
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); }