public ActionResult Subscribe(int id, bool selected)
        {
            var userId = User.Identity.GetUserId();

            using (PushAllEntities en = new PushAllEntities())
            {
                var userTag = en.UserTags.SingleOrDefault(x => x.TagId == id && x.UserId == userId);
                if (selected)
                {
                    if (userTag == null)
                    {
                        en.UserTags.Add(new UserTag {
                            TagId = id, UserId = userId
                        });
                        en.SaveChanges();
                    }
                }
                else
                {
                    if (userTag != null)
                    {
                        en.UserTags.Remove(userTag);
                        en.SaveChanges();
                    }
                }
            }

            return(Json(new { }));
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            string cookieName = "pushalluser";

            string resultPushallUserId = null;

            var cookie = Request.Cookies[cookieName];

            if (cookie != null)
            {
                string encTicket = cookie.Value;
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encTicket);
                resultPushallUserId = ticket.UserData;
            }

            string pushallUserId = Request.Params["pushalluserid"];

            if (!string.IsNullOrWhiteSpace(pushallUserId))
            {
                string remoteAddr = Request.Params["REMOTE_ADDR"];
                string time       = Request.Params["time"];
                string sign       = Request.Params["sign"];

#if !DEBUG
                if (string.Equals(sign, CalculateMD5Hash(_pushallKey + pushallUserId + time + remoteAddr), StringComparison.InvariantCultureIgnoreCase))
#endif
                {
                    resultPushallUserId = pushallUserId;
                }
            }

            if (!string.IsNullOrWhiteSpace(resultPushallUserId))
            {
                if (User.Identity.IsAuthenticated)
                {
                    var userId = User.Identity.GetUserId();
                    using (PushAllEntities en = new PushAllEntities())
                    {
                        var pushUser = en.PushAllUsers.SingleOrDefault(x => x.UserId == userId);
                        if (pushUser == null)
                        {
                            en.PushAllUsers.Add(new PushAllUser {
                                UserId = userId, PushAllUserId = resultPushallUserId
                            });
                        }
                        else
                        {
                            pushUser.PushAllUserId = resultPushallUserId;
                        }
                        en.SaveChanges();
                    }

                    if (Response.Cookies[cookieName] != null)
                    {
                        Response.Cookies[cookieName].Expires = DateTime.Now.AddYears(-100);
                    }
                }
                else
                {
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                     cookieName,
                                                                                     DateTime.Now,
                                                                                     DateTime.Now.AddMinutes(90),
                                                                                     true,
                                                                                     resultPushallUserId,
                                                                                     FormsAuthentication.FormsCookiePath);

                    string encTicket1 = FormsAuthentication.Encrypt(ticket);

                    Response.Cookies.Add(new HttpCookie(cookieName, encTicket1)
                    {
                        HttpOnly = true
                    });
                }
            }
        }