public CustomerItemCacheDisplay GetCustomerItemCache(Guid customerKey, ItemCacheType itemCacheType) { if (itemCacheType != ItemCacheType.Basket && itemCacheType != ItemCacheType.Wishlist) { var notSupported = new NotSupportedException("Basket and Wishlist are the only supported item caches"); LogHelper.Error <CustomerApiController>("Unsupported item cache type", notSupported); throw notSupported; } var customer = _customerService.GetAnyByKey(customerKey); if (customer == null) { throw new NullReferenceException("customer for customer key was null"); } if (itemCacheType == ItemCacheType.Wishlist && customer.IsAnonymous) { var invalid = new InvalidOperationException( "Wishlists are not supported with anonymous customers. The customer key passed returned an anonymous customer."); LogHelper.Error <CustomerApiController>("Could not retrieve customer wish list", invalid); throw invalid; } return(itemCacheType == ItemCacheType.Basket ? ((Basket)customer.Basket()).ItemCache.ToCustomerItemCacheDisplay() : ((WishList)((Customer)customer).WishList()).ItemCache.ToCustomerItemCacheDisplay()); }
/// <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; }
/// <summary> /// Inserts an address record in the merchBasket table and returns an <see cref="IItemCache"/> object representation /// </summary> public IItemCache MakeExistingItemCache(ICustomerBase customer, ItemCacheType itemCacheType) { var itemCache = MockCustomerItemCacheDataMaker.ConsumerItemCacheForInserting(customer, itemCacheType); ItemCacheService.Save(itemCache); return(itemCache); }
/// <summary> /// The count. /// </summary> /// <param name="itemCacheType"> /// The item cache type. /// </param> /// <param name="customerType"> /// The customer type. /// </param> /// <returns> /// The count of item caches. /// </returns> public int Count(ItemCacheType itemCacheType, CustomerType customerType) { var dtMin = DateTime.MinValue.SqlDateTimeMinValueAsDateTimeMinValue(); var dtMax = DateTime.MaxValue.SqlDateTimeMaxValueAsSqlDateTimeMaxValue(); return(Count(itemCacheType, customerType, dtMin, dtMax)); }
public static IItemCache ConsumerItemCacheForInserting(ICustomerBase customer, ItemCacheType itemCacheType) { return new ItemCache(customer.EntityKey, itemCacheType) { EntityKey = customer.EntityKey }; }
/// <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)); } }
public void Can_Create_And_Retrieve_A_CustomerItemCache() { //// Arrange const ItemCacheType itemCacheType = ItemCacheType.Basket; //// Act var itemCache = _itemCacheService.GetItemCacheWithKey(_anonymous, itemCacheType); //// Assert Assert.NotNull(itemCache); Assert.IsTrue(itemCache.HasIdentity); Assert.IsTrue(itemCache.Items.IsEmpty); }
public static IItemCache AnonymousBasket(IAnonymousCustomer anonymous, ItemCacheType itemCacheType) { var itemCache = new ItemCache(anonymous.Key, itemCacheType) { Key = Guid.NewGuid(), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; itemCache.ResetDirtyProperties(); return(itemCache); }
public static IItemCache AnonymousBasket(IAnonymousCustomer anonymous, ItemCacheType itemCacheType) { var itemCache = new ItemCache(anonymous.Key, itemCacheType) { Key = Guid.NewGuid(), CreateDate = DateTime.Now, UpdateDate = DateTime.Now }; itemCache.ResetDirtyProperties(); return itemCache; }
public void Calling_Create_Returns_An_Item_If_Exists_Rather_Than_Creating_A_New_One() { //// Arrange const ItemCacheType itemCacheType = ItemCacheType.Basket; var existing = _itemCacheService.GetItemCacheWithKey(_anonymous, itemCacheType); Assert.NotNull(existing); //// Act var secondAttempt = _itemCacheService.GetItemCacheWithKey(_anonymous, itemCacheType); //// Assert Assert.NotNull(secondAttempt); Assert.IsTrue(existing.Key == secondAttempt.Key); }
/// <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); }
/// <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> /// 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="itemCacheType"> /// The item Cache Type. /// </param> /// <returns> /// The <see cref="IItemCache"/>. /// </returns> public IItemCache GetItemCacheByCustomer(ICustomerBase customer, ItemCacheType itemCacheType) { var typeKey = EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey; return(GetItemCacheByCustomer(customer, typeKey)); }
public static IItemCache ConsumerItemCacheForInserting(ICustomerBase customer, ItemCacheType itemCacheType) { return(new ItemCache(customer.EntityKey, itemCacheType) { EntityKey = customer.EntityKey }); }
/// <summary> /// Initializes a new instance of the <see cref="ItemCache"/> class. /// </summary> /// <param name="entityKey"> /// The entity key. /// </param> /// <param name="itemCacheType"> /// The item cache type. /// </param> /// <param name="items"> /// The items. /// </param> public ItemCache(Guid entityKey, ItemCacheType itemCacheType, LineItemCollection items) : this(entityKey, EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey, items) { }
public ItemCache(Guid entityKey, ItemCacheType itemCacheType, LineItemCollection items) : this(entityKey, EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey, items) { }
/// <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> /// <returns> /// The <see cref="IItemCache"/>. /// </returns> public IItemCache GetItemCacheWithKey(ICustomerBase customer, ItemCacheType itemCacheType) { return(GetItemCacheWithKey(customer, itemCacheType, Guid.NewGuid())); }
/// <summary> /// Creates a basket for a consumer with a given type /// </summary> public IItemCache GetItemCacheWithKey(ICustomerBase customer, ItemCacheType itemCacheType) { return GetItemCacheWithKey(customer, itemCacheType, Guid.NewGuid()); }
/// <summary> /// The count. /// </summary> /// <param name="itemCacheType"> /// The item cache type. /// </param> /// <param name="customerType"> /// The customer type. /// </param> /// <returns> /// The count of item caches. /// </returns> public int Count(ItemCacheType itemCacheType, CustomerType customerType) { var dtMin = DateTime.MinValue.SqlDateTimeMinValueAsDateTimeMinValue(); var dtMax = DateTime.MaxValue.SqlDateTimeMaxValueAsSqlDateTimeMaxValue(); return Count(itemCacheType, customerType, dtMin, dtMax); }
/// <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> public IItemCache GetItemCacheByCustomer(ICustomerBase customer, ItemCacheType itemCacheType) { var typeKey = EnumTypeFieldConverter.ItemItemCache.GetTypeField(itemCacheType).TypeKey; return GetItemCacheByCustomer(customer, typeKey); }
public CustomerItemCacheDisplay GetCustomerItemCache(Guid customerKey, ItemCacheType itemCacheType) { if (itemCacheType != ItemCacheType.Basket && itemCacheType != ItemCacheType.Wishlist) { var notSupported = new NotSupportedException("Basket and Wishlist are the only supported item caches"); LogHelper.Error<CustomerApiController>("Unsupported item cache type", notSupported); throw notSupported; } var customer = _customerService.GetAnyByKey(customerKey); if (customer == null) throw new NullReferenceException("customer for customer key was null"); if (itemCacheType == ItemCacheType.Wishlist && customer.IsAnonymous) { var invalid = new InvalidOperationException( "Wishlists are not supported with anonymous customers. The customer key passed returned an anonymous customer."); LogHelper.Error<CustomerApiController>("Could not retrieve customer wish list", invalid); throw invalid; } return itemCacheType == ItemCacheType.Basket ? ((Basket)customer.Basket()).ItemCache.ToCustomerItemCacheDisplay() : ((WishList)((Customer)customer).WishList()).ItemCache.ToCustomerItemCacheDisplay(); }
/// <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> /// 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> /// Inserts an address record in the merchBasket table and returns an <see cref="IItemCache"/> object representation /// </summary> public IItemCache MakeExistingItemCache(ICustomerBase customer, ItemCacheType itemCacheType) { var itemCache = MockCustomerItemCacheDataMaker.ConsumerItemCacheForInserting(customer, itemCacheType); ItemCacheService.Save(itemCache); return itemCache; }