/// <summary>
        /// Adds an ingredient to the database
        /// </summary>
        /// <param name="ingredient">The ingredient ID we are adding or editing</param>
        /// <returns>The new or edited ingredient</returns>
        public tblIngredient AddIngredient(tblIngredient ingredient)
        {
            try
            {
                using (PizzaPanDBEntities context = new PizzaPanDBEntities())
                {
                    tblIngredient newIngredient = new tblIngredient
                    {
                        IngredientName  = ingredient.IngredientName,
                        IngredientPrice = ingredient.IngredientPrice,
                    };

                    context.tblIngredients.Add(newIngredient);
                    context.SaveChanges();
                    ingredient.IngredientID = newIngredient.IngredientID;

                    return(ingredient);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Adds a pizza ingredient to the database
        /// </summary>
        /// <param name="pizza">The pizza ingredient we are adding or editing</param>
        /// <returns>The new or pizza ingredient</returns>
        public tblPizzaIngredient AddPizzaIngredient(tblPizzaIngredient pizza)
        {
            try
            {
                using (PizzaPanDBEntities context = new PizzaPanDBEntities())
                {
                    tblPizzaIngredient newPizza = new tblPizzaIngredient
                    {
                        PizzaID      = pizza.PizzaID,
                        IngredientID = pizza.IngredientID,
                    };

                    context.tblPizzaIngredients.Add(newPizza);
                    context.SaveChanges();
                    pizza.PizzaIngredientID = newPizza.PizzaIngredientID;

                    return(pizza);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
 /// <summary>
 /// Get all data about pizza from the database
 /// </summary>
 /// <returns>The list of all pizzas</returns>
 public List <tblPizza> GetAllPizzas()
 {
     try
     {
         using (PizzaPanDBEntities context = new PizzaPanDBEntities())
         {
             List <tblPizza> list = new List <tblPizza>();
             list = (from x in context.tblPizzas select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
        /// <summary>
        /// Adds a pizza to the database
        /// </summary>
        /// <param name="pizza">The pizza ID we are adding or editing</param>
        /// <returns>The new or pizza ingredient</returns>
        public tblPizza AddPizza(tblPizza pizza)
        {
            try
            {
                using (PizzaPanDBEntities context = new PizzaPanDBEntities())
                {
                    tblPizza newPizza = new tblPizza
                    {
                        PizzaSize = pizza.PizzaSize
                    };

                    context.tblPizzas.Add(newPizza);
                    context.SaveChanges();
                    pizza.PizzaID = newPizza.PizzaID;

                    return(pizza);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }