/// <summary> /// Save a new payment or update an existin one. /// </summary> /// <param name="paymentVm">item to save</param> public void Save(PaymentViewModel paymentVm) { paymentVm.IsCleared = paymentVm.ClearPaymentNow; //delete recurring payment if isRecurring is no longer set. if (paymentVm.IsRecurring) { recurringDataAccess.Delete(paymentVm.RecurringPayment); paymentVm.RecurringPayment.Id = 0; } if (paymentVm.Id == 0) { data.Add(paymentVm); dataAccess.Add(paymentVm.GetPayment()); } else { dataAccess.Update(paymentVm.GetPayment()); } }
/// <summary> /// Deletes the passed payment and removes the item from cache /// </summary> /// <param name="paymentVmToDelete">Payment to delete.</param> public void Delete(PaymentViewModel paymentVmToDelete) { var payments = Data.Where(x => x.Id == paymentVmToDelete.Id).ToList(); foreach (var payment in payments) { data.Remove(payment); dataAccess.Delete(paymentVmToDelete.GetPayment()); // If this accountToDelete was the last finacial accountToDelete for the linked recurring accountToDelete // delete the db entry for the recurring accountToDelete. DeleteRecurringPaymentIfLastAssociated(payment); } }