public ActionResult EpisodeReactions(Guid userId, int reactionTypeId, int episodeId, string action)
        {
            var context = new EngagementsEntities();
            int returnValue = 0;

            var episode = context.EpisodeReactions.FirstOrDefault(e => e.EpisodeId == episodeId && e.ReactionTypeId == reactionTypeId && e.UserId == userId);
            if (episode == null)
            {
                if (!String.IsNullOrEmpty(action.ToString()) && action.ToString().Equals("add"))
                {
                    EpisodeReaction episodeReaction = new EpisodeReaction();
                    episodeReaction.UserId = userId;
                    episodeReaction.EpisodeId = episodeId;
                    episodeReaction.ReactionTypeId = reactionTypeId;
                    episodeReaction.DateTime = DateTime.Now;
                    context.EpisodeReactions.Add(episodeReaction);

                    returnValue = context.SaveChanges();
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(action.ToString()) && action.ToString().Equals("remove"))
                {
                    context.EpisodeReactions.Remove(episode);
                    returnValue = context.SaveChanges();
                }
            }
            return Json(new { result = returnValue }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult CreateInteraction(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty
            };
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]);
                    bool isMissingRequiredFields = false;

                    foreach (var x in tmpCollection)
                    {
                        if (String.IsNullOrEmpty(x.Value))
                        {
                            isMissingRequiredFields = true;
                            break;
                        }
                    }

                    if (!isMissingRequiredFields) // process form
                    {
                        int reactionId = Convert.ToInt32(fc["reactionId"]);
                        string type = fc["type"];
                        int id = Convert.ToInt32(fc["id"]);
                        var UserId = new Guid(User.Identity.Name);
                        var registDt = DateTime.Now;
                        using (var context = new EngagementsEntities())
                        {
                            switch (type)
                            {
                                case "show":
                                    if (reactionId == GlobalConfig.SOCIAL_LOVE) //12 Is Social_Love
                                    {
                                        int click = Convert.ToInt32(fc["click"]);
                                        var reaction = context.ShowReactions.FirstOrDefault(i => i.CategoryId == id && i.ReactionTypeId == reactionId && i.UserId == UserId);
                                        if (reaction != null || click == 0)
                                            context.ShowReactions.Remove(reaction);
                                        else
                                        {
                                            reaction = new ShowReaction()
                                            {
                                                UserId = UserId,
                                                CategoryId = id,
                                                ReactionTypeId = reactionId,
                                                DateTime = registDt
                                            };
                                            context.ShowReactions.Add(reaction);
                                        }
                                    }
                                    else
                                    {
                                        var reaction = new ShowReaction()
                                        {
                                            UserId = UserId,
                                            CategoryId = id,
                                            ReactionTypeId = reactionId,
                                            DateTime = registDt
                                        };
                                        context.ShowReactions.Add(reaction);
                                    }
                                    break;
                                case "episode":
                                    if (reactionId == GlobalConfig.SOCIAL_LOVE) //12 Is Social_Love
                                    {
                                        int click = Convert.ToInt32(fc["click"]);
                                        var reaction = context.EpisodeReactions.FirstOrDefault(i => i.EpisodeId == id && i.ReactionTypeId == reactionId && i.UserId == UserId);
                                        if (reaction != null || click == 0)
                                            context.EpisodeReactions.Remove(reaction);
                                        else
                                        {
                                            reaction = new EpisodeReaction()
                                            {
                                                UserId = UserId,
                                                EpisodeId = id,
                                                ReactionTypeId = reactionId,
                                                DateTime = registDt
                                            };
                                            context.EpisodeReactions.Add(reaction);
                                        }
                                    }
                                    else
                                    {
                                        var reaction = new EpisodeReaction()
                                        {
                                            UserId = UserId,
                                            EpisodeId = id,
                                            ReactionTypeId = reactionId,
                                            DateTime = registDt
                                        };
                                        context.EpisodeReactions.Add(reaction);
                                    }
                                    break;
                                case "celebrity":
                                    if (reactionId == GlobalConfig.SOCIAL_LOVE) //12 Is Social_Love
                                    {
                                        int click = Convert.ToInt32(fc["click"]);
                                        var reaction = context.CelebrityReactions.FirstOrDefault(i => i.CelebrityId == id && i.ReactionTypeId == reactionId && i.UserId == UserId);
                                        if (reaction != null || click == 0)
                                            context.CelebrityReactions.Remove(reaction);
                                        else
                                        {
                                            reaction = new CelebrityReaction()
                                            {
                                                UserId = UserId,
                                                CelebrityId = id,
                                                ReactionTypeId = reactionId,
                                                DateTime = registDt
                                            };
                                            context.CelebrityReactions.Add(reaction);
                                        }
                                    }
                                    else
                                    {
                                        var reaction = new CelebrityReaction()
                                        {
                                            UserId = UserId,
                                            CelebrityId = id,
                                            ReactionTypeId = reactionId,
                                            DateTime = registDt
                                        };
                                        context.CelebrityReactions.Add(reaction);
                                    }
                                    break;
                            }

                            context.SaveChanges();
                        }
                    }

                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
 public ActionResult UpdateReaction(Guid userId, int reactionTypeId, string idx, string action, string type)
 {
     int returnValue = 0;
     try
     {
         if (!String.IsNullOrEmpty(type))
         {
             var context = new EngagementsEntities();
             DateTime registDt = DateTime.Now;
             switch (type)
             {
                 case "show":
                     {
                         var showId = Convert.ToInt32(idx);
                         var show = context.ShowReactions.FirstOrDefault(i => i.CategoryId == showId && i.ReactionTypeId == reactionTypeId && i.UserId == userId);
                         if (show == null)
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "add", true) == 0)
                             {
                                 var reaction = new ShowReaction()
                                 {
                                     UserId = userId,
                                     CategoryId = showId,
                                     ReactionTypeId = reactionTypeId,
                                     DateTime = registDt
                                 };
                                 context.ShowReactions.Add(reaction);
                             }
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "remove", true) == 0)
                                 context.ShowReactions.Remove(show);
                         }
                         returnValue = context.SaveChanges();
                         break;
                     }
                 case "episode":
                     {
                         var episodeId = Convert.ToInt32(idx);
                         var episode = context.EpisodeReactions.FirstOrDefault(i => i.EpisodeId == episodeId && i.ReactionTypeId == reactionTypeId && i.UserId == userId);
                         if (episode == null)
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "add", true) == 0)
                             {
                                 var reaction = new EpisodeReaction()
                                 {
                                     UserId = userId,
                                     EpisodeId = episodeId,
                                     ReactionTypeId = reactionTypeId,
                                     DateTime = registDt
                                 };
                                 context.EpisodeReactions.Add(reaction);
                             }
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "remove", true) == 0)
                                 context.EpisodeReactions.Remove(episode);
                         }
                         returnValue = context.SaveChanges();
                         break;
                     }
                 case "celebrity":
                     {
                         var celebrityId = Convert.ToInt32(idx);
                         var celebrity = context.CelebrityReactions.FirstOrDefault(i => i.CelebrityId == celebrityId && i.ReactionTypeId == reactionTypeId && i.UserId == userId);
                         if (celebrity == null)
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "add", true) == 0)
                             {
                                 var reaction = new CelebrityReaction()
                                 {
                                     UserId = userId,
                                     CelebrityId = celebrityId,
                                     ReactionTypeId = reactionTypeId,
                                     DateTime = registDt
                                 };
                                 context.CelebrityReactions.Add(reaction);
                             }
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "remove", true) == 0)
                                 context.CelebrityReactions.Remove(celebrity);
                         }
                         returnValue = context.SaveChanges();
                         break;
                     }
                 case "channel":
                     {
                         var channelId = Convert.ToInt32(idx);
                         var channel = context.ChannelReactions.FirstOrDefault(i => i.ChannelId == channelId && i.ReactionTypeId == reactionTypeId && i.UserId == userId);
                         if (channel == null)
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "add", true) == 0)
                             {
                                 var reaction = new ChannelReaction()
                                 {
                                     UserId = userId,
                                     ChannelId = channelId,
                                     ReactionTypeId = reactionTypeId,
                                     DateTime = registDt
                                 };
                                 context.ChannelReactions.Add(reaction);
                             }
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "remove", true) == 0)
                                 context.ChannelReactions.Remove(channel);
                         }
                         returnValue = context.SaveChanges();
                         break;
                     }
                 case "youtube":
                     {
                         var youtubeId = idx;
                         var youtube = context.YouTubeReactions.FirstOrDefault(i => i.YouTubeId == youtubeId && i.ReactionTypeId == reactionTypeId && i.UserId == userId);
                         if (youtube == null)
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "add", true) == 0)
                             {
                                 var reaction = new YouTubeReaction()
                                 {
                                     UserId = userId,
                                     YouTubeId = youtubeId,
                                     ReactionTypeId = reactionTypeId,
                                     DateTime = registDt
                                 };
                                 context.YouTubeReactions.Add(reaction);
                             }
                         }
                         else
                         {
                             if (!String.IsNullOrEmpty(action) && String.Compare(action, "remove", true) == 0)
                                 context.YouTubeReactions.Remove(youtube);
                         }
                         returnValue = context.SaveChanges();
                         break;
                     }
             }
         }
     }
     catch (Exception e) { return Json(new { result = e.InnerException.Message }, JsonRequestBehavior.AllowGet); }
     return Json(new { result = returnValue }, JsonRequestBehavior.AllowGet);
 }