public async Task <IActionResult> StoreHistory(int?id) { /// <summary> /// The store order history page /// </summary> if (id == null) { return(NotFound()); } int thisLocId = (int)id; if (!UtilMethods.LogInCheck(_cache)) { return(Redirect("/Login")); } var thisLocation = await _context.Locations .FirstOrDefaultAsync(m => m.LocationId == thisLocId); if (thisLocation == null) { return(NotFound()); } var foundOrderItems = from thisTableItem in _context.OrderItems where thisTableItem.LocationId == thisLocation.LocationId select thisTableItem; List <OrderItem> theseOrderItems = foundOrderItems.ToList <OrderItem>(); List <OrderItemViewModel> theseOrderItemViewModels = new List <OrderItemViewModel>(); foreach (OrderItem thisOrderItem in theseOrderItems) { Customer thisCustomer = await _context.Customers .FirstOrDefaultAsync(m => m.CustomerId == thisOrderItem.CustomerId); OrderItemViewModel thisOrderItemViewModel = UtilMethods.BuildOrderItemViewModelFromCustOrder(thisCustomer, thisOrderItem, _context); theseOrderItemViewModels.Add(thisOrderItemViewModel); } ViewData["storeaddress"] = thisLocation.LocationAddress; ViewData["cartcount"] = UtilMethods.GetCartCount(_cache); return(View(theseOrderItemViewModels)); }
public IActionResult History() { /// <summary> /// User order history page /// </summary> if (!UtilMethods.LogInCheck(_cache)) { return(Redirect("/Login")); } Customer thisCustomer = (Customer)_cache.Get("thisCustomer"); var foundOrderItems = _context.OrderItems.Where(m => m.CustomerId == thisCustomer.CustomerId); List <OrderItem> theseOrderItems = foundOrderItems.ToList <OrderItem>(); List <OrderItemViewModel> theseOrderItemViewModels = new List <OrderItemViewModel>(); foreach (OrderItem thisOrderItem in theseOrderItems) { OrderItemViewModel thisOrderItemViewModel = UtilMethods.BuildOrderItemViewModelFromCustOrder(thisCustomer, thisOrderItem, _context); theseOrderItemViewModels.Add(thisOrderItemViewModel); } ViewData["userName"] = $"{thisCustomer.FirstName} {thisCustomer.LastName}"; ViewData["cartcount"] = UtilMethods.GetCartCount(_cache); return(View(theseOrderItemViewModels)); }