internal bool TryAddNewRecipe(tblRecipe recipe) { try { using (var conn = new CookbookEntities()) { conn.tblRecipes.Add(recipe); conn.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
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); } }