public bool SubmitUserOrder(PizzaOrder newOrder) { try{ // submit order object into db _dbConnection.OrderTable.Add(new OrderTable { UserId = newOrder.UserID, LocationId = newOrder.OrderShopLocationID, OrderTotalCost = newOrder.GetTotalOrderCost(), PizzaCount = newOrder.GetTotalPizzaCount() }); _dbConnection.SaveChanges(); }catch (System.Exception ex) { return(false); } try{ int currentOrderID = _dbConnection.OrderTable.ToList() [_dbConnection.OrderTable.ToList().Count - 1].OrderId; // submit pizzas to db and link to order foreach (var pizza in newOrder.OrderItems) { int CurrentPizzaID = PizzaRecipesDataRetriever.GetInstance().AddPizzaToDB(pizza); _dbConnection.PizzasInOrder.Add(new PizzasInOrder { OrderId = currentOrderID, PizzaId = CurrentPizzaID }); _dbConnection.SaveChanges(); } }catch (System.Exception ex) { return(false); } return(true); }
public int AddPizzaToDB(IPizza pizza) { int pizzaID = 0; _dbConnection.PizzaTable.Add(new PizzaTable { PizzaCost = System.Convert.ToDecimal(pizza.CalculateCost()), PizzaDescription = pizza.GetDescription(), }); _dbConnection.SaveChanges(); pizzaID = _dbConnection.PizzaTable.ToList() [_dbConnection.PizzaTable.ToList().Count - 1].PizzaId; return(pizzaID); }
public bool SignUp(User newCustomer) { // submit user obj to db try{ _dbConnection.UserTable.Add(new UserTable { UserEmail = newCustomer.EmailAddress, Username = newCustomer.Username, UserPassword = newCustomer.Password }); _dbConnection.SaveChanges(); return(true); } catch (System.Exception ex) { return(false); } }