public async void _checkRecurringTransaction() { NormalTransactionRepository normalTransactionRepository = new NormalTransactionRepository(); RecurringTransactionRepository recurringTransactionRepository = new RecurringTransactionRepository(); List <RecurringTransaction> recurringTransactionList = recurringTransactionRepository.GetTransactions(UserSession.UserData.Id); foreach (RecurringTransaction recurringTransaction in recurringTransactionList) { int noOfDays = (DateTime.Now - UserSession.UserData.LastAccessDate).Days; DateTime recurringTime = UserSession.UserData.LastAccessDate; TimeSpan timeSpan = new TimeSpan(recurringTransaction.TransactionDate.Hour, recurringTransaction.TransactionDate.Minute, recurringTransaction.TransactionDate.Second); recurringTime = recurringTime.Date + timeSpan; for (int i = 0; i <= noOfDays; i++) { if (recurringTransaction.Status.Equals("Weekly")) { if (recurringTime.DayOfWeek != recurringTransaction.TransactionDate.DayOfWeek) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringTransaction.Status.Equals("Monthly")) { if (recurringTime.Day != recurringTransaction.TransactionDate.Day) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringTransaction.Status.Equals("Yearly")) { string recurringTimeString = recurringTime.ToString("dd/MM"); string createdDateString = recurringTransaction.TransactionDate.ToString("dd/MM"); if (!recurringTimeString.Equals(createdDateString)) { recurringTime = recurringTime.AddDays(1); continue; } } if (recurringTime > UserSession.UserData.LastAccessDate && recurringTime <= DateTime.Now && recurringTime > recurringTransaction.TransactionDate) { _messageStatus = await Task.Run(() => normalTransactionRepository.AddNormalTransaction(new Transaction { Name = recurringTransaction.Name, Amount = recurringTransaction.Amount, Type = recurringTransaction.Type, TransactionDate = recurringTime, Note = recurringTransaction.Note, ContactId = recurringTransaction.ContactId, UserId = recurringTransaction.UserId })); RecurringBackground.ReportProgress(1, "New Transaction has been Added"); } recurringTime = recurringTime.AddDays(1); } } }
private async void _getRecurringTransactions() { RecurringTransactionRepository recurringTransactionRepository = new RecurringTransactionRepository(); List <RecurringTransaction> listOfRecurringTransaction = await Task.Run(() => recurringTransactionRepository.GetTransactions(UserSession.UserData.Id)); TransactionListView.Items.Clear(); foreach (RecurringTransaction recurringTransaction in listOfRecurringTransaction) { ListViewItem listView = new ListViewItem(new string[] { recurringTransaction.Name, recurringTransaction.Type, recurringTransaction.Amount.ToString("£0.00"), recurringTransaction.TransactionDate.ToString() }) { Tag = recurringTransaction }; TransactionListView.Items.Add(listView); } }