public IActionResult Details(int id) { var model = m_wineData.Get(id); if (model == null) { // if there is no wine with such id, return back to the index return(RedirectToAction(nameof(Index))); } return(View(model)); }
public IActionResult Details(int id) { var model = m_orderData.GetOrder(id); if (model == null) { // if there is no order with such id, return back to the index return RedirectToAction(nameof(Index)); } // convert wine ids from string back to int var idList = model.OrderedWineIds.Split(',').Select(int.Parse).ToList(); var wineList = new List<Wine>(); foreach(var i in idList) { var w = m_wineData.Get(i); wineList.Add(w); } var viewmodel = new OrderDetailsViewModel(); viewmodel.PurchasedWines = wineList; viewmodel.Order = model; return View(viewmodel); }