Exemple #1
0
        public string GetRecipes()
        {
            using (var db = new DBConnection.TastyRecipesEntities())
            {
                var recipes = db.tbRecipes.ToList();

                return(JsonConvert.SerializeObject(recipes));
            }
        }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
 protected void login_click(object sender, EventArgs e)
 {
     using (var db = new DBConnection.TastyRecipesEntities())
     {
         var user = db.tbUsers.Where(u => u.UserEmail == txtBoxMailLogin.Text && u.UserPassword == txtBoxPasswordLogin.Text).FirstOrDefault();
         if (null == user)
         {
             lblErrorLogin.Text = "email or password is incorrect";
         }
         else
         {
             enterUserToSession(user.UserName, user.UserEmail);
         }
     }
 }
Exemple #4
0
        /* ------------------------ 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);
                }
            }
        }
Exemple #5
0
        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);
                }
            }
        }