Exemple #1
0
        public JsonResult Index2(int id)
        {
            //bool does_exist = false;
            string strUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

            strUser = do_magic(strUser);

            CommentRepository  rep    = new CommentRepository();
            IEnumerable <Like> mtndew = rep.GetLikes();
            bool comp;

            string cur_user;

            Like l = new Like();

            if (!string.IsNullOrEmpty(strUser))
            {
                foreach (var yay in mtndew)
                {
                    cur_user = yay.UserName;
                    comp     = cur_user == strUser;

                    if (yay.CommentID == id && comp)
                    {
                        return(Json(null, JsonRequestBehavior.AllowGet));
                    }
                }

                int slashPos = strUser.IndexOf("\\");
                if (slashPos != -1)
                {
                    strUser = strUser.Substring(slashPos + 1);
                }
                l.UserName  = strUser;
                l.CommentID = id;

                rep.AddLike(l);

                // System.Diagnostics.Debug.WriteLine(l.UserName);


                return(Json(l, JsonRequestBehavior.AllowGet));
            }
            else
            {
                l.UserName = "******";
                return(Json("Unknown user", JsonRequestBehavior.AllowGet));
            }
        }