/// <summary> /// Gets a list of customer give a list of unique keys /// </summary> /// <param name="keys">List of unique keys</param> /// <returns>A collection of <see cref="ICustomer"/></returns> public IEnumerable <ICustomer> GetByKeys(IEnumerable <Guid> keys) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.GetAll(keys.ToArray())); } }
/// <summary> /// Initializes a new instance of the <see cref="EntityCollectionService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> internal EntityCollectionService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) { Mandate.ParameterNotNull(provider, "provider"); Mandate.ParameterNotNull(repositoryFactory, "repositoryFactory"); _uowProvider = provider; _repositoryFactory = repositoryFactory; }
/// <summary> /// Deletes a collection <see cref="ICustomer"/> objects /// </summary> /// <param name="customers">Collection of <see cref="ICustomer"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <ICustomer> customers, bool raiseEvents = true) { var customerArray = customers as ICustomer[] ?? customers.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <ICustomer>(customerArray), this); } foreach (var customer in customerArray) { DeleteInvoicesAndPayments(customer); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerRepository(uow)) { foreach (var customer in customerArray) { repository.Delete(customer); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <ICustomer>(customerArray), this); } }
/// <summary> /// Gets a customer by its unique id /// </summary> /// <param name="key">GUID key for the customer</param> /// <returns><see cref="ICustomer"/></returns> public override ICustomer GetByKey(Guid key) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.Get(key)); } }
/// <summary> /// Creates a customer and saves the record to the database /// </summary> /// <param name="loginName"> /// The login Name. /// </param> /// <param name="firstName"> /// The first name of the customer /// </param> /// <param name="lastName"> /// The last name of the customer /// </param> /// <param name="email"> /// the email address of the customer /// </param> /// <returns> /// <see cref="ICustomer"/> /// </returns> public ICustomer CreateCustomerWithKey(string loginName, string firstName, string lastName, string email) { Mandate.ParameterNotNullOrEmpty(loginName, "loginName"); var customer = new Customer(loginName) { FirstName = firstName, LastName = lastName, Email = email }; if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this)) { customer.WasCancelled = true; return(customer); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerRepository(uow)) { repository.AddOrUpdate(customer); uow.Commit(); } } SaveAddresses(customer); Created.RaiseEvent(new Events.NewEventArgs <ICustomer>(customer), this); return(customer); }
/// <summary> /// Saves a collection of <see cref="ICustomer"/> objects. /// </summary> /// <param name="customers">Collection of <see cref="ICustomer"/> to save</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Save(IEnumerable <ICustomer> customers, bool raiseEvents = true) { var customerArray = customers as ICustomer[] ?? customers.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <ICustomer>(customerArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateCustomerRepository(uow)) { foreach (var customer in customerArray) { repository.AddOrUpdate(customer); } uow.Commit(); } } foreach (var customer in customerArray) { SaveAddresses(customer); } if (raiseEvents) { Saved.RaiseEvent(new SaveEventArgs <ICustomer>(customerArray), this); } }
/// <summary> /// For testing. /// </summary> /// <returns> /// The collection of all customers. /// </returns> internal IEnumerable <ICustomer> GetAll() { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.GetAll()); } }
/// <summary> /// Gets a count of items returned by a query /// </summary> /// <param name="query"> /// The query. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> internal override int Count(IQuery <ICustomer> query) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.Count(query)); } }
/// <summary> /// Returns true if the entity exists in the at least one of the static collections. /// </summary> /// <param name="entityKey"> /// The entity key. /// </param> /// <param name="collectionKeys"> /// The collection keys. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool ExistsInCollection(Guid entityKey, IEnumerable <Guid> collectionKeys) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.ExistsInCollection(entityKey, collectionKeys.ToArray())); } }
/// <summary> /// Determines if an customer exists in a collection. /// </summary> /// <param name="entityKey"> /// The customer key. /// </param> /// <param name="collectionKey"> /// The collection key. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool ExistsInCollection(Guid entityKey, Guid collectionKey) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { return(repository.ExistsInCollection(entityKey, collectionKey)); } }
/// <summary> /// The remove invoice from collection. /// </summary> /// <param name="entityKey"> /// The customer key. /// </param> /// <param name="collectionKey"> /// The collection key. /// </param> public void RemoveFromCollection(Guid entityKey, Guid collectionKey) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { repository.RemoveFromCollection(entityKey, collectionKey); } }
/// <summary> /// Initializes a new instance of the <see cref="OfferSettingsService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> public OfferSettingsService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) { Mandate.ParameterNotNull(provider, "provider"); Mandate.ParameterNotNull(repositoryFactory, "repositoryFactory"); _uowProvider = provider; _repositoryFactory = repositoryFactory; }
/// <inheritdoc/> public IEnumerable <IItemCache> GetEntityItemCaches(Guid entityKey, Guid itemCacheTfKey) { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { var query = Query <IItemCache> .Builder.Where(x => x.EntityKey == entityKey && x.ItemCacheTfKey == itemCacheTfKey); return(repository.GetByQuery(query)); } }
/// <summary> /// Gets the count of of item caches for a customer type for a given date range. /// </summary> /// <param name="itemCacheType"> /// The item cache type. /// </param> /// <param name="customerType"> /// The customer type. /// </param> /// <param name="startDate"> /// The start Date. /// </param> /// <param name="endDate"> /// The end Date. /// </param> /// <returns> /// The count of item caches. /// </returns> public int Count(ItemCacheType itemCacheType, CustomerType customerType, DateTime startDate, DateTime endDate) { var tfkey = EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey; using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { return(repository.Count(tfkey, customerType, startDate, endDate)); } }
/// <summary> /// Returns the customer item cache of a given type. This method will not create an item cache if the cache does not exist. /// </summary> /// <param name="customer"> /// The customer. /// </param> /// <param name="itemCacheTfKey"> /// The item Cache type field Key. /// </param> /// <returns> /// The <see cref="IItemCache"/>. /// </returns> public IItemCache GetItemCacheByCustomer(ICustomerBase customer, Guid itemCacheTfKey) { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { var query = Query <IItemCache> .Builder.Where(x => x.EntityKey == customer.Key && x.ItemCacheTfKey == itemCacheTfKey); return(repository.GetByQuery(query).FirstOrDefault()); } }
/// <summary> /// Gets a page of <see cref="ICustomer"/> /// </summary> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{Icustomer}"/>. /// </returns> public override Page <ICustomer> GetPage(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { var query = Persistence.Querying.Query <ICustomer> .Builder.Where(x => x.Key != Guid.Empty); return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection)); } }
/// <summary> /// Gets a <see cref="OfferSettings"/> by the offer code value. /// </summary> /// <param name="offerCode"> /// The offer code. /// </param> /// <returns> /// The <see cref="IOfferSettings"/>. /// </returns> public IOfferSettings GetByOfferCode(string offerCode) { using (var repository = RepositoryFactory.CreateOfferSettingsRepository(UowProvider.GetUnitOfWork())) { var query = Query <IOfferSettings> .Builder.Where(x => x.OfferCode == offerCode); return(repository.GetByQuery(query).FirstOrDefault()); } }
/// <summary> /// Ensures the option is safe to delete. /// </summary> /// <param name="option"> /// The option. /// </param> /// <returns> /// A value indicating whether or not the option can be deleted. /// </returns> private bool EnsureSafeOptionDelete(IProductOption option) { using (var repository = RepositoryFactory.CreateProductOptionRepository(UowProvider.GetUnitOfWork())) { var count = repository.GetSharedProductOptionCount(option.Key); return(option.Shared ? count == 0 : count == 1); } }
/// <summary> /// Returns a page of <see cref="IOfferSettings"/>. /// </summary> /// <param name="page"> /// The page number. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{IOfferSettings}"/>. /// </returns> public Page <IOfferSettings> GetPage(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { using (var repository = RepositoryFactory.CreateOfferSettingsRepository(UowProvider.GetUnitOfWork())) { var query = Query <IOfferSettings> .Builder.Where(x => x.Key != Guid.Empty); return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection)); } }
/// <summary> /// The get by provider key. /// </summary> /// <param name="providerKey"> /// The provider key. /// </param> /// <returns> /// The <see cref="IEnumerable{IEntityCollection}"/>. /// </returns> public IEnumerable <IEntityCollection> GetByProviderKey(Guid providerKey) { using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork())) { var query = Query <IEntityCollection> .Builder.Where(x => x.ProviderKey == providerKey); return(repository.GetByQuery(query)); } }
/// <summary> /// The get root level entity collections. /// </summary> /// <param name="entityTfKey"> /// The entity type field key. /// </param> /// <param name="providerKey"> /// The provider Key. /// </param> /// <returns> /// The <see cref="IEnumerable{IEntityCollection}"/>. /// </returns> public IEnumerable <IEntityCollection> GetRootLevelEntityCollections(Guid entityTfKey, Guid providerKey) { using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork())) { var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == null && x.EntityTfKey == entityTfKey && x.ProviderKey == providerKey); return(repository.GetByQuery(query)); } }
/// <summary> /// The exists in collection. /// </summary> /// <param name="parentKey"> /// The parent key. /// </param> /// <param name="collectionKey"> /// The collection key. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool ExistsInCollection(Guid?parentKey, Guid collectionKey) { using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork())) { var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == parentKey && x.Key == collectionKey); return(repository.Count(query) > 0); } }
/// <summary> /// Returns a collection of item caches for the consumer /// </summary> /// <param name="customer"> /// The customer. /// </param> /// <returns> /// The <see cref="IEnumerable{IItemCache}"/>. /// </returns> public IEnumerable <IItemCache> GetItemCacheByCustomer(ICustomerBase customer) { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { var query = Query <IItemCache> .Builder.Where(x => x.EntityKey == customer.Key); return(repository.GetByQuery(query)); } }
/// <summary> /// The child entity collection count. /// </summary> /// <param name="collectionKey"> /// The collection key. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int ChildEntityCollectionCount(Guid collectionKey) { using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork())) { var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == collectionKey); return(repository.Count(query)); } }
/// <summary> /// Gets the count of collections managed by a provider /// </summary> /// <param name="providerKey">The provider key</param> /// <returns> /// The count of collections managed by a provider /// </returns> public int CollectionCountManagedByProvider(Guid providerKey) { using (var repostitory = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork())) { var query = Query <IEntityCollection> .Builder.Where(x => x.ProviderKey == providerKey); return(repostitory.Count(query)); } }
/// <summary> /// Gets the total customer count. /// </summary> /// <returns> /// The <see cref="int"/>. /// </returns> public int CustomerCount() { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { var query = Persistence.Querying.Query <ICustomer> .Builder.Where(x => x.Key != Guid.Empty); return(repository.Count(query)); } }
/// <summary> /// The get by login name. /// </summary> /// <param name="loginName"> /// The login name. /// </param> /// <returns> /// The <see cref="ICustomer"/>. /// </returns> public ICustomer GetByLoginName(string loginName) { using (var repository = RepositoryFactory.CreateCustomerRepository(UowProvider.GetUnitOfWork())) { var query = Persistence.Querying.Query <ICustomer> .Builder.Where(x => x.LoginName == loginName); return(repository.GetByQuery(query).FirstOrDefault()); } }
/// <summary> /// Checks if the offer code is unique. /// </summary> /// <param name="offerCode"> /// The offer code. /// </param> /// <returns> /// A valid indicating whether or not the offer code is unique. /// </returns> public bool OfferCodeIsUnique(string offerCode) { using (var repository = RepositoryFactory.CreateOfferSettingsRepository(UowProvider.GetUnitOfWork())) { var query = Query <IOfferSettings> .Builder.Where(x => x.OfferCode == offerCode); var result = repository.GetByQuery(query); return(!result.Any()); } }
/// <summary> /// Gets a collection of active <see cref="IOfferSettings"/>. /// </summary> /// <param name="excludeExpired"> /// The exclude Expired. /// </param> /// <returns> /// The <see cref="IEnumerable{IOfferSettings"/>. /// </returns> public IEnumerable <IOfferSettings> GetAllActive(bool excludeExpired = true) { using (var repository = RepositoryFactory.CreateOfferSettingsRepository(UowProvider.GetUnitOfWork())) { var query = excludeExpired ? Query <IOfferSettings> .Builder.Where(x => x.Active && x.OfferEndsDate <= DateTime.Now) : Query <IOfferSettings> .Builder.Where(x => x.Active); return(repository.GetByQuery(query)); } }
/// <summary> /// Gets a collection of <see cref="IOfferSettings"/> for a given offer provider. /// </summary> /// <param name="offerProviderKey"> /// The offer provider key. /// </param> /// <param name="activeOnly"> /// Optional value indicating whether or not to only return active Offers settings marked as active /// </param> /// <returns> /// The <see cref="IEnumerable{IOfferSettings}"/>. /// </returns> public IEnumerable <IOfferSettings> GetByOfferProviderKey(Guid offerProviderKey, bool activeOnly = true) { using (var repository = RepositoryFactory.CreateOfferSettingsRepository(UowProvider.GetUnitOfWork())) { var query = activeOnly ? Query <IOfferSettings> .Builder.Where(x => x.OfferProviderKey == offerProviderKey && x.Active) : Query <IOfferSettings> .Builder.Where(x => x.OfferProviderKey == offerProviderKey); return(repository.GetByQuery(query)); } }
/// <summary> /// Initializes a new instance of the <see cref="CustomerService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="anonymousCustomerService"> /// The anonymous Customer Service. /// </param> /// <param name="customerAddressService"> /// The customer Address Service. /// </param> /// <param name="invoiceService"> /// The invoice Service. /// </param> /// <param name="paymentService"> /// The payment Service. /// </param> public CustomerService( IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IAnonymousCustomerService anonymousCustomerService, ICustomerAddressService customerAddressService, IInvoiceService invoiceService, IPaymentService paymentService) : this(provider, repositoryFactory, logger, new TransientMessageFactory(), anonymousCustomerService, customerAddressService, invoiceService, paymentService) { }
/// <summary> /// Initializes a new instance of the <see cref="ProductOptionService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="eventMessagesFactory"> /// The event messages factory. /// </param> public ProductOptionService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory) : base(provider, repositoryFactory, logger, eventMessagesFactory) { }
/// <summary> /// Initializes a new instance of the <see cref="OfferSettingsService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> public OfferSettingsService(RepositoryFactory repositoryFactory, ILogger logger) : this(new PetaPocoUnitOfWorkProvider(logger), repositoryFactory, logger) { }
/// <summary> /// Initializes a new instance of the <see cref="OfferSettingsService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> public OfferSettingsService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : this(provider, repositoryFactory, logger, new TransientMessageFactory()) { }
/// <summary> /// Initializes a new instance of the <see cref="EntityCollectionService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> internal EntityCollectionService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : this(provider, repositoryFactory, logger, new TransientMessageFactory()) { }
/// <summary> /// Initializes a new instance of the <see cref="OfferSettingsService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="eventMessagesFactory"> /// The event messages factory. /// </param> public OfferSettingsService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory) : base(provider, repositoryFactory, logger, eventMessagesFactory) { }
/// <summary> /// Initializes a new instance of the <see cref="EntityCollectionService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> internal EntityCollectionService(RepositoryFactory repositoryFactory, ILogger logger) : this(new PetaPocoUnitOfWorkProvider(logger), repositoryFactory, logger) { }
/// <summary> /// Initializes a new instance of the <see cref="ProductOptionService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> public ProductOptionService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : this(provider, repositoryFactory, logger, new TransientMessageFactory()) { }
/// <summary> /// Initializes a new instance of the <see cref="ItemCacheService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> public ItemCacheService(RepositoryFactory repositoryFactory, ILogger logger) : this(new PetaPocoUnitOfWorkProvider(logger), repositoryFactory, logger) { }
/// <summary> /// Initializes a new instance of the <see cref="EntityCollectionService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> internal EntityCollectionService(RepositoryFactory repositoryFactory) : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) { }
/// <summary> /// Initializes a new instance of the <see cref="EntityCollectionService"/> class. /// </summary> /// <param name="provider"> /// The provider. /// </param> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="eventMessagesFactory"> /// The event messages factory. /// </param> internal EntityCollectionService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory) : base(provider, repositoryFactory, logger, eventMessagesFactory) { }
/// <summary> /// Initializes a new instance of the <see cref="ProductOptionService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> /// <param name="logger"> /// The logger. /// </param> public ProductOptionService(RepositoryFactory repositoryFactory, ILogger logger) : this(new PetaPocoUnitOfWorkProvider(logger), repositoryFactory, logger) { }
/// <summary> /// Initializes a new instance of the <see cref="OfferSettingsService"/> class. /// </summary> /// <param name="repositoryFactory"> /// The repository factory. /// </param> public OfferSettingsService(RepositoryFactory repositoryFactory) : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) { }