예제 #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 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);
     }
 }