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()); }
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; })); }
public IHttpActionResult RecalculateTotals(ShoppingCart cart) { _cartTotalsCalculator.CalculateTotals(cart); return(Ok(cart)); }