コード例 #1
0
        public ActionResult DeleteComment(int id)
        {
            AlbumRepository albums = new AlbumRepository();
            CommentModel comment = albums.GetComment(id, true, true);
            UserRepository users = new UserRepository();
            UserModel user = users.GetByUsername(HttpContext.User.Identity.Name);
            string[] response = new string[2];

            if (user != null)
            {
                if (comment.User.Id == user.Id || comment.Album.User.Id == user.Id) //usuwac moze wlasciciel albumu lub komentarza
                {
                    response[0] = "ok";
                    response[1] = "";
                    albums.deleteComment(comment);
                }
                else
                {
                    response[0] = "error";
                    response[1] = "You are not allowed to delete this comment.";
                }
            }
            else
            {
                response[0] = "error";
                response[1] = "You need to be logged in to delete comments";
            }

            return Json(response);
        }