public IActionResult CheckOut(CustomerViewModel viewModel) { try { if (!ModelState.IsValid) { _logger.LogInformation("Invalid Model State while trying to check out returning checkout view"); return(View(viewModel)); } var customer = _customerRepo.GetCustomerByFirstAndLastName(viewModel.FirstName, viewModel.LastName); if (customer == null) { ViewData["NoCustomer"] = true; return(View(viewModel)); } decimal cartTotal = 0; foreach (var kvp in _shoppingCart.GetCart()) { decimal price = _productRepo.GetProductById(kvp.Key).Price; cartTotal += price * kvp.Value; } Order order = new Order(_shoppingCart.StoreId, customer.CustomerId, DateTime.Now, cartTotal, _shoppingCart.GetCart()); bool srSuccess = _storeRepo.PlaceOrder(_shoppingCart.StoreId, _shoppingCart.GetCart()); bool orSuccess = _orderRepo.AddNewOrder(order); _shoppingCart.EmptyCart(); _logger.LogInformation("Order placed successfully returning to cart"); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "There was a problem Logging In"); _logger.LogWarning("Error Logging in Customer"); return(View(viewModel)); } }