public int DeleteRecipe(int id) { using (var db = new DBConnection.TastyRecipesEntities()) { var recipe = db.tbRecipes.Where(i => i.id == id).FirstOrDefault(); db.tbRecipes.Remove(recipe); db.SaveChanges(); return(recipe.id); } }
/* ------------------------ Registration ------------------------ */ protected void submit_registration_click(object sender, EventArgs e) { using (var db = new DBConnection.TastyRecipesEntities()) { var user = db.tbUsers.Where(u => u.UserEmail == txtBoxMailRegister.Text).FirstOrDefault(); if (null == user) { //tbUser t = new db.tbUsers.Add(new tbUser { UserName = txtBoxUserNameRegister.Text, UserEmail = txtBoxMailRegister.Text, UserPassword = txtBoxPasswordRegister.Text }); db.SaveChanges(); enterUserToSession(txtBoxUserNameRegister.Text, txtBoxMailRegister.Text); } else { lblErrorRegister.Text = "User with that email is already exist"; ShowLogin(false); } } }
public int SaveRecipe() { using (var stream = new MemoryStream()) { var request = HttpContext.Current.Request; request.InputStream.Seek(0, SeekOrigin.Begin); request.InputStream.CopyTo(stream); var dataStr = Encoding.UTF8.GetString(stream.ToArray()); var data = (dynamic)JsonConvert.DeserializeObject(dataStr); using (var db = new DBConnection.TastyRecipesEntities()) { var d = data.data; int id = Convert.ToInt32(d["id"]); var recipe = id == 0 ? new tbRecipe() : db.tbRecipes.Where(i => i.id == id).FirstOrDefault(); recipe.RecipeName = Convert.ToString(d["RecipeName"]); recipe.RecipeDescription = Convert.ToString(d["RecipeDescription"]); recipe.RecipeMealType = Convert.ToString(d["RecipeMealType"]); recipe.RecipeCategory = Convert.ToString(d["RecipeCategory"]); recipe.RecipeIngredients = Convert.ToString(d["RecipeIngredients"]); recipe.RecipeTime = Convert.ToInt32(d["RecipeTime"]); recipe.RecipeDifficulty = Convert.ToString(d["RecipeDifficulty"]); recipe.RecipeInstructions = Convert.ToString(d["RecipeInstructions"]); recipe.RecipeImg = (byte[])(d["RecipeImg"]); recipe.UserName = Convert.ToString(d["UserName"]); recipe.UserEmail = Convert.ToString(d["UserEmail"]); if (id == 0) { db.tbRecipes.Add(recipe); } db.SaveChanges(); return(recipe.id); } } }