public Analytic TotalByOnus(Analytic analytics) { var dictionary = new Dictionary<string, decimal>(); var collection = _database.GetCollection<Earning>(EARNING_COLLECTION); var earnings = collection.FindAllAs<Earning>().SetSortOrder(SortBy.Ascending("Date")); var matchEarnings = earnings.Where(e => e.Date.CompareTo(analytics.End) <= 0 && e.Date.CompareTo(analytics.Start) >= 0); foreach(var earning in matchEarnings) { foreach(var onus in earning.Onuses) { if(dictionary.ContainsKey(onus.ItemId)) { dictionary[onus.ItemId] = dictionary[onus.ItemId] + onus.Amount; } else { dictionary.Add(onus.ItemId, onus.Amount); } } } analytics.SumByOnus = dictionary; return analytics; }
public Analytic SumByOnus(Analytic analytics) { var sums = _mongoContext.TotalByOnus(analytics); var items = _mongoContext.GetItems(); var dictionary = new Dictionary<string, decimal>(); foreach(var sum in sums.SumByOnus) { var match = items.FirstOrDefault(a => a.Id == sum.Key); dictionary.Add(match.Name, sum.Value); } analytics.SumByOnus = dictionary; return analytics; }