Example #1
0
        public async Task <CyrrencyDaylyWinDTO> GetTransactionsCurrencyDaylyWins(int day)
        {
            ServiceValidator.DayIsInMonth(day);

            var allTransactionsQuery = await this.dbContext
                                       .Transactions
                                       .Include(tt => tt.TransactionType)
                                       .Include(u => u.User.Wallet.Currency)
                                       .ToListAsync();

            var daylyTotalUsd = allTransactionsQuery
                                .Where(tt => tt.TransactionType.Name == "Win")
                                .Where(td => td.CreatedOn.Value.Month == DateTime.Now.Month &&
                                       td.CreatedOn.Value.Day == day)
                                .Select(t => t.NormalisedAmount).Sum();

            var daylyWinsBGN = allTransactionsQuery
                               .Where(tt => tt.TransactionType.Name == "Win")
                               .Where(c => c.User.Wallet.Currency.Name == "BGN")
                               .Where(td => td.CreatedOn.Value.Month == DateTime.Now.Month &&
                                      td.CreatedOn.Value.Day == day)
                               .Select(t => t.OriginalAmount).Sum();

            var daylyWinsUSD = allTransactionsQuery
                               .Where(tt => tt.TransactionType.Name == "Win")
                               .Where(c => c.User.Wallet.Currency.Name == "USD")
                               .Where(td => td.CreatedOn.Value.Month == DateTime.Now.Month &&
                                      td.CreatedOn.Value.Day == DateTime.Now.Day)
                               .Select(t => t.OriginalAmount).Sum();

            var daylyWinsGBP = allTransactionsQuery
                               .Where(tt => tt.TransactionType.Name == "Win")
                               .Where(c => c.User.Wallet.Currency.Name == "GBP")
                               .Where(td => td.CreatedOn.Value.Month == DateTime.Now.Month &&
                                      td.CreatedOn.Value.Day == day)
                               .Select(t => t.OriginalAmount).Sum();

            var daylyWinsEUR = allTransactionsQuery
                               .Where(tt => tt.TransactionType.Name == "Win")
                               .Where(c => c.User.Wallet.Currency.Name == "EUR")
                               .Where(td => td.CreatedOn.Value.Month == DateTime.Now.Month &&
                                      td.CreatedOn.Value.Day == day)
                               .Select(t => t.OriginalAmount).Sum();

            var resultModel = new CyrrencyDaylyWinDTO()
            {
                DaylyTotalUSD = daylyTotalUsd,
                DaylyWinsBGN  = daylyWinsBGN,
                DaylyWinsEUR  = daylyWinsEUR,
                DaylyWinsGBP  = daylyWinsGBP,
                DaylyWinsUSD  = daylyWinsUSD
            };

            return(resultModel);
        }