public int Update()
        {
            // Create result variable for this method (int)
            int result = 0;

            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // If a specific user is selected, update the user information. Otherwise, throw an exception.
                    tblMeasure Measure = dc.tblMeasures.Where(i => i.ms_Id == this.Id).FirstOrDefault();
                    if (Measure != null)
                    {
                        Measure.ms_Description = this.Description;
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public int Delete(int id)
        {
            // Create result variable for this method (int)
            int result = 0;

            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())

                // If Measure is selected, delete measure from tblMeasures and its Id number. Otherwise, throw exception
                {
                    tblMeasure Measure = dc.tblMeasures.Where(i => i.ms_Id == id).FirstOrDefault();
                    if (Measure != null)
                    {
                        dc.tblMeasures.Remove(Measure);
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public int Insert()
        {
            // Create result variable for this method (int)
            int result = 0;

            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // Create new instance of tblMeasure called Measure
                    tblMeasure measure = new tblMeasure();

                    // Insert new user into tblMeasures by adding new Id number, otherwise throw exception
                    measure.ms_Id = 1;
                    if (dc.tblMeasures.Any())
                    {
                        measure.ms_Id = dc.tblMeasures.Max(i => i.ms_Id) + 1;
                    }
                    this.Id = measure.ms_Id;
                    measure.ms_Description = this.Description;
                    dc.tblMeasures.Add(measure);
                    result = dc.SaveChanges();
                    return(result);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public int Insert()
        {
            // Create result variable for this method (int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // Create new instance of tblIngredient
                    tblIngredient ingredient = new tblIngredient();

                    ingredient.in_Id = 1;
                    if (dc.tblIngredients.Any())
                    {
                        ingredient.in_Id = dc.tblIngredients.Max(i => i.in_Id) + 1;
                    }
                    this.Id = ingredient.in_Id;
                    ingredient.in_Description = this.Description;
                    dc.tblIngredients.Add(ingredient);
                    result = dc.SaveChanges();
                    return(result);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public int Update()
        {
            // Create result variable for this method(int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // If ingredient is selected, update the description. Otherwise, throw an exception.
                    tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == this.Id).FirstOrDefault();
                    if (ingredient != null)
                    {
                        ingredient.in_Description = this.Description;
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 6
0
        public int Update()
        {
            int result = 0;

            try
            {
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    tblRecipe recipe = dc.tblRecipes.Where(r => r.rc_Id == this.Id).FirstOrDefault();
                    if (recipe != null)
                    {
                        recipe.rc_Name        = this.Name;
                        recipe.rc_Description = this.Description;
                        recipe.rc_Directions  = this.Directions;
                        recipe.rc_Image       = ConvertImage(this.Image);
                        recipe.rc_Ingredients = this.Ingredients;
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                return(0);

                throw e;
            }
        }
        public int Delete(int id)
        {
            // Create result variable for this method(int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // If ingredient is selected, delete the ingredient along with the Id associated with it. Otherwise, throw an exception.
                    tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == id).FirstOrDefault();
                    if (ingredient != null)
                    {
                        dc.tblIngredients.Remove(ingredient);
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 8
0
        public int Insert()
        {
            // Declare result variable for this method (int)
            int result = 0;

            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // Create new instance of tblRecipe called recipe
                    tblRecipe recipe = new tblRecipe();

                    recipe.rc_Id = 1;
                    if (dc.tblRecipes.Any())
                    {
                        recipe.rc_Id = dc.tblRecipes.Max(r => r.rc_Id) + 1;
                    }
                    this.Id               = recipe.rc_Id;
                    recipe.rc_Name        = this.Name;
                    recipe.rc_Description = this.Description;
                    recipe.rc_Directions  = this.Directions;
                    recipe.rc_Image       = ConvertImage(this.Image);
                    recipe.us_Id          = this.UserId;
                    recipe.rc_Ingredients = this.Ingredients;
                    dc.tblRecipes.Add(recipe);
                    result = dc.SaveChanges();
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static void Delete(int recipeid, int ingredientid, int measureid)
        {
            try
            {
                // Create new instance of ChefsCornerEntities/ Connection string
                ChefsCornerEntities dc = new ChefsCornerEntities();

                tblRecipeIngredient rin = dc.tblRecipeIngredients.FirstOrDefault(rci => rci.rc_Id == recipeid && rci.in_Id == ingredientid && rci.ms_Id == measureid);
                if (rin != null)
                {
                    dc.tblRecipeIngredients.Remove(rin);
                    dc.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void Delete(int id)
 {
     try
     {
         // Using statement for connection string, and create a new instance of it
         using (ChefsCornerEntities dc = new ChefsCornerEntities())
         {
             // If user with a specific id is selected, delete the user and the Id associated with it. Otherwise, throw an exception.
             tblUser user = dc.tblUsers.Where(u => u.us_Id == id).FirstOrDefault();
             if (user != null)
             {
                 dc.tblUsers.Remove(user);
                 dc.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Insert()
 {
     try
     {
         // Create new instance of ChefsCornerEntities/ Connection string
         using (ChefsCornerEntities dc = new ChefsCornerEntities())
         {
             // Create new instance of tblUser called user
             tblUser user = new tblUser();
             // Insert new user into tblUsers by adding new Id number, otherwise throw exception
             Id = dc.tblUsers.Any() ? dc.tblUsers.Max(u => u.us_Id) + 1 : 1;
             Map(user);
             dc.tblUsers.Add(user);
             dc.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void Update()
        {
            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    tblUser user = dc.tblUsers.Where(u => u.us_Id == this.Id).FirstOrDefault();

                    // If a user is selected, update the user info. Otherwise, throw an exception.
                    if (user != null)
                    {
                        Map(user);
                        dc.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static void Add(int recipeid, int ingredientid, int measureid)
        {
            try
            {
                // Create new instance of ChefsCornerEntities
                ChefsCornerEntities dc = new ChefsCornerEntities();

                // Create new instance of tblRecipeIngredient
                tblRecipeIngredient rin = new tblRecipeIngredient();

                // Add new Ids for recipes, ingredients, and measures to tblRecipeIngredients. Otherwise, throw an exception.
                rin.ri_Id = dc.tblRecipeIngredients.Any() ? dc.tblRecipeIngredients.Max(r => r.ri_Id) + 1 : 1;
                rin.in_Id = ingredientid;
                rin.rc_Id = recipeid;
                rin.ms_Id = measureid;
                dc.tblRecipeIngredients.Add(rin);
                dc.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 14
0
        public int Delete(int id)
        {
            int result = 0;

            try
            {
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    tblRecipe recipe = dc.tblRecipes.Where(r => r.rc_Id == id).FirstOrDefault();
                    if (recipe != null)
                    {
                        dc.tblRecipes.Remove(recipe);
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                return(0);

                throw e;
            }
        }