/// <summary> /// Saves an <see cref="IAppliedPayment"/> /// </summary> /// <param name="appliedPayment">The <see cref="IAppliedPayment"/> to be saved</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IAppliedPayment appliedPayment, bool raiseEvents = true) { if (raiseEvents) { if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IAppliedPayment>(appliedPayment), this)) { ((AppliedPayment)appliedPayment).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateAppliedPaymentRepository(uow)) { repository.AddOrUpdate(appliedPayment); uow.Commit(); } } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <IAppliedPayment>(appliedPayment), this); } }
/// <summary> /// Returns a <see cref="IAppliedPayment"/> by it's unique 'key' /// </summary> /// <param name="key">The unique 'key' of the <see cref="IAppliedPayment"/></param> /// <returns>An <see cref="IAppliedPayment"/></returns> public IAppliedPayment GetByKey(Guid key) { using (var repository = RepositoryFactory.CreateAppliedPaymentRepository(UowProvider.GetUnitOfWork())) { return(repository.Get(key)); } }
/// <summary> /// Deletes a collection of <see cref="IAppliedPayment"/> /// </summary> /// <param name="appliedPayments">The collection of <see cref="IAppliedPayment"/>s to be deleted</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IAppliedPayment> appliedPayments, bool raiseEvents = true) { var payemntsArray = appliedPayments as IAppliedPayment[] ?? appliedPayments.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IAppliedPayment>(payemntsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateAppliedPaymentRepository(uow)) { foreach (var appliedPayment in payemntsArray) { repository.Delete(appliedPayment); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IAppliedPayment>(payemntsArray), this); } }
/// <summary> /// Gets a collection of <see cref="IAppliedPayment"/>s by the invoice key /// </summary> /// <param name="invoiceKey">The invoice key</param> /// <returns>A collection <see cref="IAppliedPayment"/></returns> public IEnumerable <IAppliedPayment> GetAppliedPaymentsByInvoiceKey(Guid invoiceKey) { using (var repository = RepositoryFactory.CreateAppliedPaymentRepository(UowProvider.GetUnitOfWork())) { var query = Query <IAppliedPayment> .Builder.Where(x => x.InvoiceKey == invoiceKey); return(repository.GetByQuery(query)); } }
internal IAppliedPayment CreateAppliedPaymentWithKey(Guid paymentKey, Guid invoiceKey, Guid appliedPaymentTfKey, string description, decimal amount, bool raiseEvents = true) { Mandate.ParameterCondition(!Guid.Empty.Equals(paymentKey), "paymentKey"); Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey"); Mandate.ParameterCondition(!Guid.Empty.Equals(appliedPaymentTfKey), "appliedPaymentTfKey"); var appliedPayment = new AppliedPayment(paymentKey, invoiceKey, appliedPaymentTfKey) { Description = description, Amount = amount, Exported = false }; if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAppliedPayment>(appliedPayment), this)) { appliedPayment.WasCancelled = true; return(appliedPayment); } } using (new WriteLock(Locker)) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateAppliedPaymentRepository(uow)) { repository.AddOrUpdate(appliedPayment); uow.Commit(); } } if (raiseEvents) { Created.RaiseEvent(new Events.NewEventArgs <IAppliedPayment>(appliedPayment), this); } return(appliedPayment); }