public async Task <IImmutableList <CommonMealStatisticOverview> > LoadOverview(DateTime fromDate, DateTime toDate) { fromDate = fromDate.StartOfDay(); toDate = toDate.EndOfDay(); var result = await _statisticsRepository.GetOverviewStatistics(fromDate, toDate); var prices = (await _personRepository.GetAll()) .ToImmutableDictionary(x => x.Id, x => x.IsAdult() ? _commonMealPriceSettings.GetAdultPrice() : _commonMealPriceSettings.GetChildPrice()); foreach (var r in result) { var mealCostPrice = prices[r.PersonId]; r.Cost.MealCostSum = r.AdultGuestsCount * _commonMealPriceSettings.GetAdultPrice() + r.ChildGuestsCount * _commonMealPriceSettings.GetChildPrice() + r.MealCount * mealCostPrice; } return(result); }
// TODO: Separate Load & Crate like in the CommonMealService public async Task <CommonMealShoppingInfo> Load(int mealId) { // Load the common meal, persons and guest regis var meal = await _commonMealRepository.GetById(mealId); // Load the existing expenses var expenses = (await _commonMealExpenseRepository .GetByCommonMealId(mealId)) .ToDictionary(x => x.PersonId, x => x); // Create missing expenses (each chef should have an expense record): var missingExpenses = meal.Chefs .Where(chef => chef.PersonId != null && !expenses.ContainsKey(chef.PersonId.Value)) .Select(chef => CreateDefaultExpense(chef.PersonId.Value, mealId)) .ToImmutableList(); var allExpenses = expenses.Values.Union(missingExpenses).OrderBy(x => x.PersonId).ThenBy(x => x.Id).ToImmutableList(); // Create the shopping info var(adults, children) = await CalcMealInfo(meal.Registrations); var budget = (int)Math.Round((adults.Total * _commonMealPriceSettings.GetAdultPrice()) + (children.Total * _commonMealPriceSettings.GetChildPrice()), 0); return(new CommonMealShoppingInfo { MealId = mealId, Adults = adults, Children = children, Expenses = allExpenses, Budget = budget, }); }