Ejemplo n.º 1
0
        public async Task <Price> HandleAsync(GetTotalMonthOutcome query)
        {
            using (ReadModelContext db = dbFactory.Create())
            {
                List <PriceFixed> outcomes = await db.Outcomes
                                             .WhereUserKey(query.UserKey)
                                             .Where(o => o.When.Month == query.Month.Month && o.When.Year == query.Month.Year)
                                             .Select(o => new PriceFixed(new Price(o.Amount, o.Currency), o.When))
                                             .ToListAsync();

                return(SumPriceInDefaultCurrency(query.UserKey, outcomes));
            }
        }
Ejemplo n.º 2
0
        public async Task <Price> HandleAsync(GetTotalMonthOutcome query)
        {
            using (ReadModelContext db = new ReadModelContext())
            {
                List <Price> outcomes = await db.Outcomes
                                        .Where(o => o.When.Month == query.Month.Month && o.When.Year == query.Month.Year)
                                        .Select(o => new Price(o.Amount, o.Currency))
                                        .ToListAsync();

                Price price = priceFactory.Create(0);
                foreach (Price outcome in outcomes)
                {
                    price += outcome;
                }

                return(price);
            }
        }
Ejemplo n.º 3
0
        public async Task <Price> HandleAsync(GetTotalMonthOutcome query)
        {
            using (ReadModelContext db = readModelContextFactory.Create())
            {
                List <PriceFixed> outcomes = await db.Outcomes
                                             .WhereUserKey(query.UserKey)
                                             .Where(o => o.When.Month == query.Month.Month && o.When.Year == query.Month.Year)
                                             .Select(o => new PriceFixed(new Price(o.Amount, o.Currency), o.When))
                                             .ToListAsync();

                Price price = priceConverter.ZeroDefault(query.UserKey);
                foreach (PriceFixed outcome in outcomes)
                {
                    price += priceConverter.ToDefault(query.UserKey, outcome);
                }

                return(price);
            }
        }