partial void DeleteRecipe_Favoriter(Recipe_Favoriter instance);
 partial void UpdateRecipe_Favoriter(Recipe_Favoriter instance);
		private void detach_Recipe_Favoriters(Recipe_Favoriter entity)
		{
			this.SendPropertyChanging();
			entity.Recipe = null;
		}
 partial void InsertRecipe_Favoriter(Recipe_Favoriter instance);
Esempio n. 5
0
        /// <summary>
        /// Favorites another user's recipe
        /// </summary>
        /// <param name="postId">The recipe to favorite</param>
        /// <returns>Refreshes the page.</returns>
        public ActionResult FavoriteRecipe(int postId)
        {
            Recipe_Favoriter newFavoriter = new Recipe_Favoriter();
            newFavoriter.RecipeId = postId;
            newFavoriter.UserId = WebSecurity.CurrentUserId;
            if (!db.Recipe_Favoriters.Contains(newFavoriter))
            {
                db.Recipe_Favoriters.InsertOnSubmit(newFavoriter);
                var recipe = (from recipes in db.Recipes
                              where recipes.RecipeID == postId
                              select recipes).FirstOrDefault();
                recipe.FavoriteCount++;

                db.SubmitChanges();

                var favoriterUserName = (from userprofiles in userDb.UserProfiles
                                         where userprofiles.UserId == newFavoriter.UserId
                                     select userprofiles.UserName).FirstOrDefault();

                var userID = (from recipes in db.Recipes
                              where recipes.RecipeID == postId
                              select recipes.UserID).FirstOrDefault();

                SendSMS(userID, favoriterUserName + " has favorited one of your recipes. Come visit Cookbook and check out which recipe "
                    + favoriterUserName + " favorited!");
                SendEmail(userID, favoriterUserName + " has favorited one of your recipes.", favoriterUserName +
                    " has favorited one of your recipes. Come visit Cookbook and check out which recipe " +
                    favoriterUserName + " favorited!");
            }
            return Redirect(Request.UrlReferrer.AbsoluteUri);
        }