public IActionResult AddLunchOrder(IndexViewModel model) { if (ModelState.IsValid) { _logger.LogDebug("ModelState is valid"); try { _lunchService.AddLunchOrder(new Guid(HttpContext.User.FindFirst("Id").Value), (Guid)model.LocationId, (DateTime)model.Date); ViewData["FormSuccess"] = "Din bestilling er oprettet..."; } catch (InvalidLunchOrderDateException) { ViewData["FormError"] = "Din bestilling skal foretages mindst 2 dage før ønskede frokost dato..."; } catch (Exception) { ViewData["FormError"] = "Din bestilling er ikke oprettet..."; } } model.LocationSelectListItems = IndexViewModel.GetLocationListItems(_locationRepository.ListAll()); model.LunchOrders = _lunchOrderRepository.ListAllByUserId(new Guid(HttpContext.User.FindFirst("Id").Value)); return(View("Index", model)); }
public IActionResult Index() { var model = new IndexViewModel() { LocationSelectListItems = IndexViewModel.GetLocationListItems(_locationRepository.ListAll()), LunchOrders = _lunchOrderRepository.ListAllByUserId(new Guid(HttpContext.User.FindFirst("Id").Value)) }; return(View(model)); }