public IActionResult AddCart(Cart cart) { try { _cartServices.AddCart(cart); return(CreatedAtAction("AddCart", cart)); } catch (Exception) { return(BadRequest()); } }
public Customer CustomerValidation() { string filepath = "../lacrosseDB/DBFiles/Customer.txt"; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(filepath, rollingInterval: RollingInterval.Day) .CreateLogger(); string email; Customer cust = new Customer(); Console.WriteLine("Enter email"); email = Console.ReadLine(); try { cust = customerServices.GetCustomerByEmail(email); if (cust.email != email) { throw new System.ArgumentException(); } else { customer = cust; Log.Information($"{cust.email} has signed in"); CustMenu custMenu = new CustMenu(customer, context); try { cartServices.DeleteCart(cartServices.GetCartByCustId(customer.Id)); } catch (InvalidOperationException) { } finally { Cart newCart = new Cart(); newCart.custId = customer.Id; cartServices.AddCart(newCart); custMenu.Start(); } } } catch (ArgumentException) { Log.Information($"Customer {cust.email} tried and failed to login."); ValidInvalidServices.InvalidInput(); } catch (InvalidOperationException) { Log.Information($"Customer tried to sign into an account the DNE."); ValidInvalidServices.InvalidInput(); } return(cust); }