public async Task <TransactionMonthGroup> GetTransactionMonthGroup(TransactionMonthGroupFilter filter) { // Filter theo thang va nam de list transaction day group theo thang do TransactionDayGroupFilter transactionDayGroupFilter = new TransactionDayGroupFilter { Month = filter.Month, Year = filter.Year, WalletName = filter.WalletName, UserId = filter.UserId }; List <TransactionDayGroup> transactionDayGroups = await ListTransactionDayGroup(transactionDayGroupFilter); // Tinh toan voi outflow < 0 va inflow > 0 decimal inflow = 0; decimal outflow = 0; transactionDayGroups.ForEach(tdg => { inflow += tdg.Inflow; outflow += tdg.Outflow; }); // Tra ve transaction month group return(new TransactionMonthGroup { Outflow = outflow, Inflow = inflow, InOutRate = inflow + outflow, Month = filter.Month, Year = filter.Year, TransactionDayGroups = transactionDayGroups }); }
public async Task <TransactionMonthGroupResponseDTO> GetTransactionMonthGroup([FromBody] TransactionMonthGroupRequestDTO transactionMonthGroupRequestDTO) { // Tao filter cho MonthGroup TransactionMonthGroupFilter filter = new TransactionMonthGroupFilter { Month = transactionMonthGroupRequestDTO.Month, Year = transactionMonthGroupRequestDTO.Year, WalletName = transactionMonthGroupRequestDTO.WalletName, UserId = currentUserId }; // Get MonthGroup tu filter TransactionMonthGroup res = await transactionService.GetTransactionMonthGroup(filter); // Tao List DayGroupDTO de gan vao trong ket qua List <TransactionDayGroupDTO> transactionDayGroupDTOs = new List <TransactionDayGroupDTO>(); // Voi moi DayGroupDTO thi gan list transactionDTO res.TransactionDayGroups.ToList().ForEach(tdg => { // Tao list transactionDTO List <TransactionDTO> transactionDTOs = new List <TransactionDTO>(); tdg.Transactions.ToList().ForEach(t => transactionDTOs.Add(new TransactionDTO { WalletName = t.WalletName, Date = t.Date, Errors = t.Errors, Amount = t.Amount, CategoryName = t.CategoryName, Note = t.Note })); // Gan list transactionDTO vao DayGroupDTO transactionDayGroupDTOs.Add(new TransactionDayGroupDTO { Errors = tdg.Errors, Date = tdg.Date, Inflow = tdg.Inflow, Outflow = tdg.Outflow, Transactions = transactionDTOs }); }); // Tra ket qua MonthGroupDTO return(new TransactionMonthGroupResponseDTO { TransactionDayGroups = transactionDayGroupDTOs, InOutRate = res.InOutRate, Inflow = res.Inflow, Outflow = res.Outflow, Month = res.Month, Year = res.Year, Errors = res.Errors }); }