/// <summary> /// Gets a Basket by its unique id - primary key /// </summary> /// <param name="key">Id for the Basket</param> /// <returns><see cref="IItemCache"/></returns> public IItemCache GetByKey(Guid key) { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { return(repository.Get(key)); } }
/// <summary> /// Gets a collection of all item caches. /// </summary> /// <returns> /// The <see cref="IEnumerable{IItemCache}"/>. /// </returns> public IEnumerable <IItemCache> GetAll() { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { return(repository.GetAll()); } }
/// <summary> /// Gets a list of Basket give a list of unique keys /// </summary> /// <param name="keys">List of unique keys</param> /// <returns>The collection of <see cref="IItemCache"/></returns> public IEnumerable <IItemCache> GetByKeys(IEnumerable <Guid> keys) { using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { return(repository.GetAll(keys.ToArray())); } }
/// <summary> /// Deletes a collection <see cref="IItemCache"/> objects /// </summary> /// <param name="itemCaches">Collection of <see cref="IItemCache"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IEnumerable <IItemCache> itemCaches, bool raiseEvents = true) { var caches = itemCaches as IItemCache[] ?? itemCaches.ToArray(); if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IItemCache>(caches), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateItemCacheRepository(uow)) { foreach (var basket in caches) { repository.Delete(basket); } uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IItemCache>(caches), this); } }
/// <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> /// 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> /// 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)); } }
/// <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> /// Deletes a single <see cref="IItemCache"/> object /// </summary> /// <param name="itemCache">The <see cref="IItemCache"/> to delete</param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> public void Delete(IItemCache itemCache, bool raiseEvents = true) { if (raiseEvents) { Deleting.RaiseEvent(new DeleteEventArgs <IItemCache>(itemCache), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateItemCacheRepository(uow)) { repository.Delete(itemCache); uow.Commit(); } } if (raiseEvents) { Deleted.RaiseEvent(new DeleteEventArgs <IItemCache>(itemCache), this); } }
/// <summary> /// Gets a page of <see cref="IItemCache"/> /// </summary> /// <param name="itemCacheType"> /// The item cache type. /// </param> /// <param name="startDate"> /// The start Date. /// </param> /// <param name="endDate"> /// The end Date. /// </param> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by field. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{IItemCache}"/>. /// </returns> public Page <IItemCache> GetCustomerItemCachePage( ItemCacheType itemCacheType, DateTime startDate, DateTime endDate, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { // this is the only valid sort field if (sortBy != "lastActivityDate") { sortBy = string.Empty; } var itemCacheTfKey = EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey; using (var repository = RepositoryFactory.CreateItemCacheRepository(UowProvider.GetUnitOfWork())) { return(repository.GetCustomerItemCachePage(itemCacheTfKey, startDate, endDate, page, itemsPerPage, sortBy, sortDirection)); } }
/// <summary> /// Creates a basket for a consumer with a given type /// </summary> /// <param name="customer"> /// The customer. /// </param> /// <param name="itemCacheType"> /// The item Cache Type. /// </param> /// <param name="versionKey"> /// The version Key. /// </param> /// <returns> /// The <see cref="IItemCache"/>. /// </returns> public IItemCache GetItemCacheWithKey(ICustomerBase customer, ItemCacheType itemCacheType, Guid versionKey) { Mandate.ParameterCondition(Guid.Empty != versionKey, "versionKey"); // determine if the consumer already has a item cache of this type, if so return it. var itemCache = GetItemCacheByCustomer(customer, itemCacheType); if (itemCache != null) { return(itemCache); } itemCache = new ItemCache(customer.Key, itemCacheType) { VersionKey = versionKey }; if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IItemCache>(itemCache), this)) { // registry.WasCancelled = true; return(itemCache); } itemCache.EntityKey = customer.Key; using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateItemCacheRepository(uow)) { repository.AddOrUpdate(itemCache); uow.Commit(); } } Created.RaiseEvent(new Events.NewEventArgs <IItemCache>(itemCache), this); return(itemCache); }