// // GET: /StoreManager/Details/5 public async Task <IActionResult> Details( [FromServices] IMemoryCache cache, int id) { var cacheKey = GetCacheKey(id); Album album; if (!cache.TryGetValue(cacheKey, out album)) { album = await MusicStoreService.GetAlbumAsync(id); if (album != null) { if (_appSettings.CacheDbResults) { //Remove it from cache if not retrieved in last 10 minutes. cache.Set( cacheKey, album, new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(10))); } } } if (album == null) { cache.Remove(cacheKey); return(NotFound()); } return(View(album)); }
private async Task <Model.Album> FetchFromStoreAsync() { if (string.IsNullOrEmpty(_name)) { return(await _storeService.GetAlbumAsync(_intId)); } else { return(await _storeService.GetAlbumAsync(_name)); } }
public async Task <int> CreateOrderAsync(Order order) { decimal orderTotal = 0; var cartItems = await GetCartItemsAsync(); order.OrderDetails = new List <OrderDetail>(); List <Album> albumUpdates = new List <Album>(); // Iterate over the items in the cart, adding the order details for each foreach (var item in cartItems) { var album = await _musicStore.GetAlbumAsync(item.AlbumId); album.OrderCount = +item.Count; albumUpdates.Add(album); var orderDetail = new OrderDetail { AlbumId = item.AlbumId, OrderId = order.OrderId, UnitPrice = album.Price, Quantity = item.Count, }; // Set the order total of the shopping cart orderTotal += (item.Count * album.Price); order.OrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; //Add the Order var result = await _orderProcessing.AddOrderAsync(order); // Empty the shopping cart await EmptyCartAsync(); // Update order count in albums foreach (var a in albumUpdates) { await _musicStore.UpdateAlbumAsync(a); } // Return the OrderId as the confirmation number return(result); }