public async Task <ReportsDto> GetReportsDto(int userId) { var reports = await _dbContext.Reports .Include(r => r.City) .Include(r => r.ReportUnits) .ThenInclude(ru => ru.Unit) .Include(r => r.Army) .ThenInclude(a => a.Player) .Where(r => r.Army.Player.UserId == userId) .OrderByDescending(r => r.Turn) .ToListAsync(); var reportsDto = new ReportsDto { Reports = new List <ReportDto>() }; foreach (Report report in reports) { List <SquadUnitDto> reportedUnits = new List <SquadUnitDto>(); foreach (ReportUnit reportUnit in report.ReportUnits) { SquadUnitDto newSquadUnitDto = new SquadUnitDto { UnitName = reportUnit.Unit.Name, Name = reportUnit.Unit.Type, NumberOfUnits = reportUnit.NumberOfUnits }; reportedUnits.Add(newSquadUnitDto); } ReportDto newReportDto = new ReportDto { Turn = report.Turn, CityName = report.City.Name, ReportedUnits = reportedUnits }; reportsDto.Reports.Add(newReportDto); } return(reportsDto); }
public ActionResult GetStats() { ReportsDto reports = _reportService.GetReports(UserId); return(Ok(reports)); }
public HttpResponseMessage ProfitAndLossQuery(ReportsDto reportsDto) { var fromDate = DateTime.ParseExact(reportsDto.FromDate, "yyyy-MM-dd", null); var toDate = DateTime.ParseExact(reportsDto.ToDate, "yyyy-MM-dd", null); float totalInterestIncome = 0; float totalCOTIncome = 0; float totalInterestExpense = 0; float receivable = 0; var loanDetails = _context.LoanDetails.ToList(); var interestIncomeAccounts = _context.FinancialReports .Where(c => c.CreditAccount.Equals(CBA.INTEREST_INCOME_ACC_NAME) ).ToList(); var COTIncomeAccount = _context.FinancialReports .Where(c => c.CreditAccount.Equals(CBA.COT_INCOME_GL_ACCOUNT)).ToList(); var interestExpenseAccount = _context.FinancialReports .Where(c => c.DebitAccount.Equals(CBA.INTEREST_EXPENSE_GL_ACCOUNT)).ToList(); var interestReceivableAccounts = _context.FinancialReports .Where(c => c.DebitAccount.Equals(CBA.INTEREST_RECEIVABLE_ACC_NAME)).ToList(); if (interestReceivableAccounts != null) { foreach (var interestReceivableAccount in interestReceivableAccounts) { if (interestReceivableAccount.ReportDate.Value.Date > fromDate.Date && interestReceivableAccount.ReportDate.Value.Date < toDate) { receivable = receivable + interestReceivableAccount.DebitAmount; } } } if (interestIncomeAccounts != null) { foreach (var interestIncomeAccount in interestIncomeAccounts) { if (interestIncomeAccount.ReportDate.Value.Date >= fromDate.Date && interestIncomeAccount.ReportDate.Value.Date <= toDate) { var income = interestIncomeAccount.CreditAmount; totalInterestIncome = totalInterestIncome + income; } } } if (COTIncomeAccount != null) { foreach (var account in COTIncomeAccount) { if (account.ReportDate.Value.Date >= fromDate.Date && account.ReportDate.Value.Date <= toDate) { totalCOTIncome = totalCOTIncome + account.CreditAmount; } } } if (interestExpenseAccount != null) { foreach (var account in interestExpenseAccount) { if (account.ReportDate.Value.Date >= fromDate.Date && account.ReportDate.Value.Date <= toDate) { totalInterestExpense = totalInterestExpense + account.DebitAmount; } } } totalInterestIncome = totalInterestIncome - receivable; var incomeAndExpense = new List <string> { CBA.INTEREST_INCOME_ACC_NAME, totalInterestIncome.ToString(CultureInfo.InvariantCulture), CBA.COT_INCOME_GL_ACCOUNT, totalCOTIncome.ToString(CultureInfo.InvariantCulture), CBA.INTEREST_EXPENSE_GL_ACCOUNT, totalInterestExpense.ToString() }; return(Request.CreateResponse(HttpStatusCode.OK, incomeAndExpense)); }