public ResumeMonth GetResume(int year, int month) { ResumeMonth resumeMonth = new ResumeMonth(year, month); using (OutlayAPIManager API_Manager = new OutlayAPIManager()) { List <TransactionDTO> monthTransaction = API_Manager.GetTransaction(year, month); if (monthTransaction != null) { double totalAdjust = monthTransaction.Where(x => x.DetailTransaction.Type == OutlayDataHelper.OutlayTypesEnum.ADJUST.ToString()) .Select(x => x.Amount) .Sum(); double totalSpenses = monthTransaction.Where(x => x.DetailTransaction.Type == OutlayDataHelper.OutlayTypesEnum.SPENDING.ToString()) .Select(x => x.Amount) .Sum(); double totalIncoming = monthTransaction.Where(x => x.DetailTransaction.Type == OutlayDataHelper.OutlayTypesEnum.INCOMING.ToString()) .Select(x => x.Amount) .Sum(); var groupingCode = monthTransaction.GroupBy(x => x.DetailTransaction.Code) .ToDictionary(key => key.Key, value => value.Sum(x => x.Amount)); resumeMonth.Spenses = totalSpenses; resumeMonth.Incoming = totalIncoming; resumeMonth.Adjust = totalAdjust; resumeMonth.GroupCodeTransactions = groupingCode; } } return(resumeMonth); }
private void LoadResumeFromSelectedFormMDI(object sender, EventArgs e) { if (sender is CalendarTransaction calendar) { int year = calendar.year; int month = calendar.month; TransactionManager transactionManager = new TransactionManager(); ResumeMonth resume = transactionManager.GetResume(year, month); this.textBoxYear.Text = resume.Date.Year.ToString(); this.textBoxMonth.Text = resume.Date.Month.ToString(); this.textBoxIncoming.Text = Normalizer.SpainFormatAmount(resume.Incoming); this.textBoxExpenses.Text = Normalizer.SpainFormatAmount(resume.Spenses); double savingAmount = Math.Round(resume.Incoming - resume.Spenses, 2); this.textBoxSaving.Text = Normalizer.SpainFormatAmount(savingAmount); this.textBoxSaving.BackColor = (savingAmount > 0) ? Color.GreenYellow : Color.Red; double totalAmount = transactionManager.GetTotalAmount(); this.textBoxTotalAmount.Text = Normalizer.SpainFormatAmount(totalAmount); } }