public ActionResult Create(string Content, int videoId)
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(Json(new { message = "redirect" }, JsonRequestBehavior.AllowGet));
            }

            treca_aplikacija_model db = new treca_aplikacija_model();
            comment comment           = new comment();

            comment.comment_video_id = (byte)videoId;

            string LoggedInUserName = User.Identity.GetApplicationUserUsername();

            foreach (var x in db.users)
            {
                if (x.user_username.Equals(LoggedInUserName))
                {
                    comment.comment_user_id = x.users_id;
                }
            }

            comment.comment_created = DateTime.Now;
            comment.comment_content = Content;

            db.comments.Add(comment);
            db.SaveChanges();
            //?


            UserViewModel    CommentOwner = ApplicationUtils.CreateUserViewModelDTO(db.users.Find(comment.comment_user_id));
            CommentViewModel Comment      = ApplicationUtils.CreateCommentViewModelDTO(db.comments.Find(comment.comment_id));

            return(Json(new { User = CommentOwner, Comment = Comment }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult Delete(string username)
        {
            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Unauthorized", "Account"));
            }

            using (treca_aplikacija_model db = new treca_aplikacija_model())
            {
                foreach (var x in db.users.ToList())
                {
                    if (x.user_username.Equals(username))
                    {
                        return(View(ApplicationUtils.CreateUserViewModelDTO(x)));
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public ActionResult Administrator(string query, bool isUser)
        {
            List <Object> retVal = new List <Object>();

            using (treca_aplikacija_model db = new treca_aplikacija_model())
            {
                if (isUser)
                {
                    foreach (var x in db.users.Where(x => x.user_username.Contains(query)).ToList())
                    {
                        retVal.Add(ApplicationUtils.CreateUserViewModelDTO(x));
                    }
                }
                else
                {
                    foreach (var x in db.videos.Where(x => x.video_name.Contains(query)).ToList())
                    {
                        retVal.Add(ApplicationUtils.CreateVideoViewModel(x));
                    }
                }

                return(Json(new { returnValues = retVal }, JsonRequestBehavior.AllowGet));
            }
        }