コード例 #1
0
        public ActionResult Actions(int movie_id, string UserAction)
        {
            UserAccess ua = new UserAccess();

            AgfMembershipProvider membership = new AgfMembershipProvider();

            try
            {
                if (ModelState.IsValid)
                {
                    bool check;
                    if (check = System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        var  user   = User.Identity.Name.ToString();
                        Guid?userId = membership.GetUserIdByEmail(user);


                        switch (UserAction)
                        {
                        case "w":
                        {
                            if (ua.User_AddtoWatched(movie_id, userId) == false)
                            {
                                return(Json(new { success = false, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new { success = true, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                        }

                        case "f":
                        {
                            if (ua.User_AddToFav(movie_id, userId) == false)
                            {
                                return(Json(new { success = false, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new { success = true, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                        }

                        case "t":
                        {
                            if (ua.AddToWatchlist(movie_id, userId) == false)
                            {
                                return(Json(new { success = false, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new { success = true, responseText = "Cannot add to Watched." }, JsonRequestBehavior.AllowGet));
                            }
                        }
                        }
                    }

                    else
                    {
                        ViewBag.failureMessage = "<p>FAILED. Please Login.</p>";

                        return(View());
                    }
                }
            }
            catch (Exception e1)
            {
                TempData["Msg"] = "Failed" + e1.Message;
            }
            return(View());
        }