Пример #1
0
 internal bool TryAddNewRecipe(tblRecipe recipe)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             conn.tblRecipes.Add(recipe);
             conn.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #2
0
 internal bool TryAddNewUserData(tblUserData userData)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             conn.tblUserDatas.Add(userData);
             conn.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        internal bool TryRemoveRecipe(int recipeId)
        {
            try
            {
                using (var conn = new CookbookEntities())
                {
                    var recipeToRemove = conn.tblRecipes.FirstOrDefault(x => x.RecipeID == recipeId);

                    if (recipeToRemove != null)
                    {
                        conn.tblRecipes.Remove(recipeToRemove);
                        conn.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #4
0
 internal bool TryUpdateRecipe(tblRecipe updatedRecipe)
 {
     try
     {
         using (var conn = new CookbookEntities())
         {
             var recipeToUpdate = conn.tblRecipes.FirstOrDefault(x => x.RecipeID == updatedRecipe.RecipeID);
             if (recipeToUpdate != null)
             {
                 recipeToUpdate.Name         = updatedRecipe.Name;
                 recipeToUpdate.PersonsCount = updatedRecipe.PersonsCount;
                 recipeToUpdate.Type         = updatedRecipe.Type;
                 conn.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }