public async Task <IActionResult> getAllStores() { _logger.LogInformation("Getting all stores"); // Code that gets all the stores. var stores = await _storesRepository.GetAllStores(); return(Ok(stores)); }
public async Task <IActionResult> GetRegionOverview(string region) { var sales = await GetAllSalesFromCacheAsync(); var stores = await _storesRepository.GetAllStores(); var storesOverview = from store in stores where store.Region == region select store; var saleLists = new List <SaleByRegion>(); foreach (var sale in sales) { foreach (var item in storesOverview) { if (sale.Store_id == item.Id) { saleLists.Add(new SaleByRegion() { Store_id = sale.Store_id, Bouquet_id = sale.Bouquet_id, Amount = sale.Amount }); } } } var overview = from saleList in saleLists group saleList by saleList.Store_id into SaleOverview select new { Store_id = SaleOverview.Key, TotalAmountSold = SaleOverview.Sum(x => x.Amount), }; overview = overview.OrderByDescending(overview => overview.TotalAmountSold); return(Ok(overview)); }