private async Task SearchWeekBestClientAsync() { DateTime weekStart = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); DateTime weekEnd = weekStart.AddDays(7).AddSeconds(-1); BestClient bestClient = await AsyncFake.CallAsync(StatisticsBL, x => x.GetBestClientInPeriod(weekStart, weekEnd)); WeekBestClient = bestClient?.Client; WeekBestClientTotal = bestClient?.Amount; }
public BestClient GetBestClientInPeriod(DateTime from, DateTime till) { LoadClients(); // Load clients if needed var weekPurchaseByClient = _clients.Select(client => new { client, total = PurchaseInPeriodFunc(client, from, till) }) .Where(x => x.total.HasValue) .WhereMax(x => x.total.Value); BestClient bestClient = null; if (weekPurchaseByClient != null) { bestClient = new BestClient { Client = weekPurchaseByClient.client, Amount = weekPurchaseByClient.total }; } return(bestClient); }