public virtual ShoppingCart[] GetByIds(string[] cartIds, string responseGroup = null)
        {
            var retVal = new List <ShoppingCart>();

            using (var repository = _repositoryFactory())
            {
                //Disable DBContext change tracking for better performance
                repository.DisableChangesTracking();

                var cartEntities = repository.GetShoppingCartsByIds(cartIds);
                foreach (var cartEntity in cartEntities)
                {
                    var cart = cartEntity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance());
                    //Calculate totals only for full responseGroup
                    if (responseGroup == null)
                    {
                        _totalsCalculator.CalculateTotals(cart);
                    }
                    retVal.Add(cart);
                }
            }

            _dynamicPropertyService.LoadDynamicPropertyValues(retVal.ToArray <IHasDynamicProperties>());

            return(retVal.ToArray());
        }
예제 #2
0
        public virtual async Task <IEnumerable <ShoppingCart> > GetByIdsAsync(string[] cartIds, string responseGroup = null)
        {
            var retVal   = new List <ShoppingCart>();
            var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", cartIds), responseGroup);

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                using (var repository = _repositoryFactory())
                {
                    //Disable DBContext change tracking for better performance
                    repository.DisableChangesTracking();

                    var cartEntities = await repository.GetShoppingCartsByIdsAsync(cartIds, responseGroup);
                    foreach (var cartEntity in cartEntities)
                    {
                        var cart = cartEntity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance());
                        //Calculate totals only for full responseGroup
                        if (responseGroup == null)
                        {
                            _totalsCalculator.CalculateTotals(cart);
                        }
                        retVal.Add(cart);
                        cacheEntry.AddExpirationToken(CartCacheRegion.CreateChangeToken(cart));
                    }
                }

                await _dynamicPropertyService.LoadDynamicPropertyValuesAsync(retVal.ToArray <IHasDynamicProperties>());

                return retVal;
            }));
        }
예제 #3
0
 public IHttpActionResult RecalculateTotals(ShoppingCart cart)
 {
     _cartTotalsCalculator.CalculateTotals(cart);
     return(Ok(cart));
 }