/// <inheritdoc /> public async Task <IEnumerable <RecurringPayment> > GetPaymentsToRecur() { var recurringPayments = recurringPaymentRepository .GetMany(x => x.IsEndless || x.EndDate >= DateTime.Now.Date) .Include(x => x.RelatedPayments) .Where(x => x.ChargedAccount != null) .ToList(); var payments = new List <Payment>(); foreach (var recurringPayment in recurringPayments) { // Delete Recurring Payments without assosciated payments. // This can be removed in later versions, since this will be based on old data. if (!recurringPayment.RelatedPayments.Any()) { recurringPaymentRepository.Delete(recurringPayment); continue; } payments.Add(new Payment( await paymentRepository.GetById( recurringPayment.RelatedPayments.OrderByDescending(y => y.Date).First().Id))); } return(payments .Where(RecurringPaymentHelper.CheckIfRepeatable) .Select(x => new RecurringPayment(x.Data.RecurringPayment)) .ToList()); }
public bool SavePayment(Payment payment) { if (!payment.IsRecurring && payment.RecurringPaymentId != 0) { recurringPaymentRepository.Delete(payment.RecurringPayment); payment.RecurringPaymentId = 0; } bool handledRecuringPayment; handledRecuringPayment = payment.RecurringPayment == null || recurringPaymentRepository.Save(payment.RecurringPayment); if (payment.RecurringPayment != null) { payment.RecurringPaymentId = payment.RecurringPayment.Id; } var saveWasSuccessful = handledRecuringPayment && paymentRepository.Save(payment); return(saveWasSuccessful); }