public async Task <IActionResult> Index() { List <BeerProductViewModel> beers = new List <BeerProductViewModel>(); try { BeerProductsLogic beerL = new BeerProductsLogic(_configuration.GetConnectionString("DefaultConnection")); var StoredBeersList = await beerL.GetBeerProducts(); foreach (var beer in StoredBeersList) { beers.Add(new BeerProductViewModel() { BrandName = beer.Brand.BrandName, ContainerName = beer.Container.ContainerName, ContainerType = beer.Container.ContainerType, Price = $"${beer.Price.ToString()}", Size = $"{beer.Container.CapacityInOz} fl. oz." }); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return(View(beers)); }
public async Task <IActionResult> Index() { List <BeerProductViewModel> beers = new List <BeerProductViewModel>(); try { BeerProductsLogic beerLogic = new BeerProductsLogic(_configuration.GetConnectionString("DefaultConnection")); var result = await beerLogic.GetThreeRandomBeerProducts(); foreach (var beer in result) { beers.Add(new BeerProductViewModel() { Id = beer.Id, BrandName = beer.Brand.BrandName, ContainerName = beer.Container.ContainerName, ContainerType = beer.Container.ContainerType, Price = beer.Price.ToString("C", CultureInfo.CreateSpecificCulture("en-US")), Size = $"{beer.Container.CapacityInOz} fl. oz." }); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return(View(beers)); }