public async Task <Domain.Dtos.UserBalanceAudit> GetUserBalanceAndHistory(string userId) { var balanceHistoryQuery = _documentStore.GetItems <UserBalanceAudit>(x => x.Type == DocumentDbType.UserBalanceAudit && x.UserId == userId).AsDocumentQuery(); var balanceHistoryQueryResponse = await balanceHistoryQuery.ExecuteNextAsync <UserBalanceAudit>(); var balanceHistory = balanceHistoryQueryResponse.FirstOrDefault(); var balanceHistoryDto = new Domain.Dtos.UserBalanceAudit(); if (balanceHistory == null) { return(balanceHistoryDto); } balanceHistory.Audits = balanceHistory.Audits.OrderByDescending(x => x.Date).ToList(); balanceHistoryDto = _mapper.Map <UserBalanceAudit, Domain.Dtos.UserBalanceAudit>(balanceHistory); var userQuery = _documentStore.GetItems <ApplicationUser>(x => x.UserId == userId).AsDocumentQuery(); var userQueryResponse = await userQuery.ExecuteNextAsync <ApplicationUser>(); var user = userQueryResponse.FirstOrDefault(); if (user != null) { balanceHistoryDto.Balance = user.Balance; } return(balanceHistoryDto); }
public async Task<Domain.Dtos.UserBalanceAudit> GetUserBalanceAndHistory(string userId) { var balanceHistoryQuery = _documentStore.GetItems<UserBalanceAudit>(x => x.Type == DocumentDbType.UserBalanceAudit && x.UserId == userId).AsDocumentQuery(); var balanceHistoryQueryResponse = await balanceHistoryQuery.ExecuteNextAsync<UserBalanceAudit>(); var balanceHistory = balanceHistoryQueryResponse.FirstOrDefault(); var balanceHistoryDto = new Domain.Dtos.UserBalanceAudit(); if (balanceHistory == null) return balanceHistoryDto; balanceHistory.Audits = balanceHistory.Audits.OrderByDescending(x => x.Date).ToList(); balanceHistoryDto = _mapper.Map<UserBalanceAudit, Domain.Dtos.UserBalanceAudit>(balanceHistory); var userQuery = _documentStore.GetItems<ApplicationUser>(x => x.Id == userId).AsDocumentQuery(); var userQueryResponse = await userQuery.ExecuteNextAsync<ApplicationUser>(); var user = userQueryResponse.FirstOrDefault(); if (user != null) { balanceHistoryDto.Balance = user.Balance; } return balanceHistoryDto; }