Пример #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reply">PostReply object.</param>
 public CommentModel(PostReply reply)
 {
     this.Comments   = reply.Comments.ToList();
     this.PostID     = -1;
     this.ReplyID    = reply.Id;
     this.AddComment = false;
 }
Пример #2
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                var posts = await PageData.PManager.FBHelper.GetAllPosts();

                var postreplies = await PageData.PManager.FBHelper.GetAllReplies();

                foreach (var post in posts)
                {
                    if (post.Id == clickedPost.Id)
                    {
                        if (post.Replies == null)
                        {
                            post.Replies = new List <PostReply>();
                        }
                        PostReply reply = new PostReply(postreplies.Count + 1, clickedPost.Id, DateTime.Now, editorReply.Text);
                        postreplies.Add(reply);
                        post.Replies.Add(reply);
                    }
                }
                await PageData.PManager.FBHelper.firebase.Child("Posts").PutAsync(posts);

                await PageData.PManager.FBHelper.firebase.Child("PostReply").PutAsync(postreplies);

                await Navigation.PopAsync();
            }
            catch (Exception _e)
            {
                await DisplayAlert("Error", _e.Message, "OK");
            }
        }
Пример #3
0
        public ActionResult AddComment(int PostID, int ReplyID, string comment)
        {
            Comment c = new Comment();

            c.Author     = this.UserDB.GetByUserName(User.Identity.Name);
            c.Text       = comment;
            c.TimeOfPost = DateTime.UtcNow;
            int id = -1;

            if (-1 != ReplyID)
            {
                PostReply r = this.PostReplyDB.Find(ReplyID);
                r.Comments.Add(c);
                this.PostReplyDB.Edit(r);
                id = r.Head.Id;
            }
            else
            {
                Post p = this.PostDB.Find(PostID);
                p.Comments.Add(c);
                this.PostDB.Edit(p);
                id = PostID;
            }
            return(RedirectToAction("View", "Post", new { Id = id }));
        }
        public async Task <ActionResult <PostReply> > PostPostReply(PostReply postReply)
        {
            context.PostReplies.Add(postReply);
            await context.SaveChangesAsync();

            return(CreatedAtAction("GetPostReply", new { id = postReply.PostReplyId }, postReply));
        }
Пример #5
0
        public string PostReply(PostReply rep)
        {
            string content = Request["Reply1"];
            int    Com_id  = Convert.ToInt32(Request["Com_id"]);

            if (content == "")
            {
                return("kong");
            }
            if (Session["userid"] != null)
            {
                if (ModelState.IsValid)
                {
                    rep.PostComment_id    = Com_id;
                    rep.PostReply_content = content;
                    rep.User_id           = Convert.ToInt32(Session["userid"].ToString());
                    rep.Addtime           = System.DateTime.Now;
                    db.PostReply.Add(rep);
                    db.SaveChanges();
                    return("aa");
                }
                else
                {
                    return("bb");
                }
            }
            else
            {
                return("nn");
            }
        }//回复评论
Пример #6
0
        private async Task <bool> ManipulateMediaListAsync(string listId, int movieId, string method, CancellationToken cancellationToken = default(CancellationToken))
        {
            RequireSessionId(SessionType.UserSession);

            if (string.IsNullOrWhiteSpace(listId))
            {
                throw new ArgumentNullException(nameof(listId));
            }

            // Movie Id is expected by the API and can not be null
            if (movieId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(movieId));
            }

            RestRequest req = _client.Create("list/{listId}/{method}");

            req.AddUrlSegment("listId", listId);
            req.AddUrlSegment("method", method);
            AddSessionId(req, SessionType.UserSession);

            req.SetBody(new { media_id = movieId });

            RestResponse <PostReply> response = await req.ExecutePost <PostReply>(cancellationToken).ConfigureAwait(false);

            // Status code 12 = "The item/record was updated successfully"
            // Status code 13 = "The item/record was deleted successfully"
            PostReply item = await response.GetDataObject().ConfigureAwait(false);

            // TODO: Previous code checked for item=null
            return(item.StatusCode == 12 || item.StatusCode == 13);
        }
        public async Task <IActionResult> PutPostReply(int id, PostReply postReply)
        {
            if (id != postReply.PostReplyId)
            {
                return(BadRequest());
            }

            context.Entry(postReply).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostReplyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #8
0
        public ActionResult Edit(int id, PostReply requestPostReply)
        {
            try
            {
                PostReply postReply = db.PostReplies.Find(id);

                if (postReply.UserId == User.Identity.GetUserId() || User.IsInRole("Admin"))
                {
                    if (TryUpdateModel(postReply))
                    {
                        postReply.Content = requestPostReply.Content;
                        db.SaveChanges();
                    }
                    return(Redirect("/Posts/Show/" + postReply.PostId));
                }
                else
                {
                    TempData["message"] = "Nu aveti dreptul sa faceti modificari";
                    return(RedirectToAction("Index", "Posts"));
                }
            }
            catch (Exception e)
            {
                return(View(requestPostReply));
            }
        }
Пример #9
0
        public void AppendReply(PostReply reply)
        {
            var replyTreeItem = new TreeItem <PostReply>(reply, new());

            PostReplyTree.Children.Insert(0, replyTreeItem);
            ToggleReplyForm(false);
        }
Пример #10
0
        public Task Delete(int Id)
        {
            PostReply reply = GetById(Id);

            _context.Remove(reply);
            return(_context.SaveChangesAsync());
        }
Пример #11
0
        public void UpdateReply(PostReply reply)
        {
            PostReply _reply = GetReply(reply.Id);

            _reply.Content = reply.Content;
            _context.SaveChanges();
        }
Пример #12
0
 public ActionResult Show(PostReply postReply)
 {
     postReply.Created = DateTime.Now;
     postReply.UserId  = User.Identity.GetUserId();
     try
     {
         if (ModelState.IsValid)
         {
             db.PostReplies.Add(postReply);
             db.SaveChanges();
             return(Redirect("/Posts/Show/" + postReply.Id));
         }
         else
         {
             Post a = db.Posts.Find(postReply.Id);
             SetAccessRights();
             return(View(a));
         }
     }
     catch (Exception e)
     {
         Post a = db.Posts.Find(postReply.Id);
         SetAccessRights();
         return(View(a));
     }
 }
Пример #13
0
        public ServiceResponse <PostReply> AddReply(PostReply reply)
        {
            try
            {
                var newReply = new PostReply
                {
                    Id        = reply.Id,
                    Post      = reply.Post,
                    Content   = reply.Content,
                    CreatedOn = DateTime.Now,
                    User      = reply.User
                };

                _db.PostReplies.Add(newReply);
                _db.SaveChanges();

                return(new ServiceResponse <PostReply>
                {
                    Data = reply,
                    DateTime = DateTime.UtcNow,
                    Message = "Reply created.",
                    IsSuccess = true
                });
            }
            catch (Exception e)
            {
                return(new ServiceResponse <PostReply>
                {
                    Data = reply,
                    DateTime = DateTime.UtcNow,
                    Message = "Error saving new reply.",
                    IsSuccess = false
                });
            }
        }
Пример #14
0
    /// <summary>
    /// Posts a reply to this post item. Calling this method results in a call to EWS.
    /// </summary>
    /// <param name="bodyPrefix">Body prefix.</param>
    void PostReply(MessageBody bodyPrefix)
    {
        PostReply postReply = this.CreatePostReply();

        postReply.BodyPrefix = bodyPrefix;

        postReply.Save();
    }
Пример #15
0
        public ActionResult DeleteReply(int id, PostReply reply, Post post)
        {
            PostReply replies = new PostReply();

            _replyService.DeleteReply(id, reply, post);

            return(RedirectToAction("GetPost", "Post", new { id = reply.Post.Id }));
        }
Пример #16
0
 public int Insert_PostReply(PostReply postReply)
 {
     using (_conn)
     {
         const string sql = @"INSERT INTO postreply
                     (content,postid,userid,username,createdate)
             VALUES  (@Content,@PostId,@UserId,@UserName,NOW())";
         return(Conn.Execute(sql, postReply));
     }
 }
 public PostReplyViewModel(
     PostReply replyDb,
     ApplicationUser userDb,
     Post postDb)
 {
     this.Id        = replyDb.Id;
     this.Content   = replyDb.Content;
     this.CreatedAt = replyDb.CreatedAt;
     this.Author    = new ApplicationUserViewModel(userDb);
     this.PostId    = postDb.Id;
 }
Пример #18
0
 public async Task UpdateReplyContent(PostReply reply)
 {
     try
     {
         _db.Entry(reply).State = System.Data.Entity.EntityState.Modified;
         await _db.SaveChangesAsync();
     }
     catch (Exception exception)
     {
     }
 }
Пример #19
0
 public ActionResult UpdateReply(int id, PostReply reply, Post post)
 {
     try
     {
         _replyService.UpdateReply(reply);
         return(RedirectToAction("GetPost", "Post", new { id = reply.Post.Id }));
     }
     catch
     {
         return(View());
     }
 }
Пример #20
0
        public void DeleteReply(int id, PostReply reply, Post posts)
        {
            //find first or default instance of reply to delete
            var replytoDelete = _context.Replies.FirstOrDefault(r => r.Id == id);

            //if result is not null, remove from database & save changes
            if (replytoDelete != null)
            {
                _context.Replies.Remove(replytoDelete);
                _context.SaveChanges();
            }
        }
Пример #21
0
        public IActionResult Create([FromBody] CreateReplyViewModel postReplyToCreate)
        {
            var reply    = new PostReply();
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;

            reply.Content = postReplyToCreate.Content;
            reply.Post.Id = postReplyToCreate.PostId;
            reply.User.Id = int.Parse(claims.ElementAt(2).Value);

            _postReply.Create(reply);
            return(View());
        }
Пример #22
0
        public bool CreatePostReply(PostReplyCreate model, int postID)
        {
            var entity = new PostReply()
            {
                ReplyCreator = _userID,
                ReplyContent = model.ReplyContent,
                PostID       = postID,
                ReplyCreated = DateTimeOffset.Now
            };

            _dbContext.Replies.Add(entity);
            return(_dbContext.SaveChanges() == 1);
        }
Пример #23
0
 public void Create(PostReply postReply)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         SqlCommand command = new SqlCommand("spCreatePostReply", connection);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.Add(new SqlParameter("@PostId", postReply.Post.Id));
         command.Parameters.Add(new SqlParameter("@UserId", postReply.User.Id));
         command.Parameters.Add(new SqlParameter("@Content", postReply.Content));
         connection.Open();
         command.ExecuteNonQuery();
     }
 }
Пример #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reply">PostReply object.</param>
 public ViewLeftSideModel(PostReply reply)
 {
     this.ID          = reply.Id;
     this.HeadID      = reply.Head.Id;
     this.UpVotes     = reply.UpVotes.ToList();
     this.DownVotes   = reply.DownVotes.ToList();
     this.IsSolution  = reply.CorrectAnswer;
     this.IsReply     = true;
     this.HasSolution = reply.Head.Replies
                        .Where(post => post.CorrectAnswer == true)
                        .SingleOrDefault() == null ? false : true;
     this.PostAuthor = reply.Head.Author.Username.ToLower();
     this.Author     = reply.Author.Username.ToLower();
 }
Пример #25
0
        public ActionResult Edit(int id)
        {
            PostReply postReply = db.PostReplies.Find(id);

            if (postReply.UserId == User.Identity.GetUserId() || User.IsInRole("Admin"))
            {
                return(View(postReply));
            }
            else
            {
                TempData["message"] = "Nu aveti dreptul sa faceti modificari";
                return(RedirectToAction("Index", "Posts"));
            }
        }
Пример #26
0
        public IActionResult AddReply(PostReplyVIewModel model)
        {
            var user  = _userManager.FindByIdAsync(model.AuthorId).Result;
            var post  = _postService.GetById(model.PostId);
            var reply = new PostReply
            {
                Post    = post,
                Content = model.ReplyContent,
                Created = DateTime.Now,
                User    = user
            };

            _postService.AddReply(reply);
            _userService.IncrementRating(user.Id, typeof(PostReply));
            return(RedirectToAction("Index", "Post", new { postId = model.PostId }));
        }
Пример #27
0
        public async Task <IActionResult> ReplyPost(PostViewModel model)
        {
            var userId = _userManager.GetUserId(User);
            var user   = _userManager.FindByIdAsync(userId).Result;
            var post   = _postService.GetById(model.Id);
            var reply  = new PostReply
            {
                Content = model.NewReply.Content,
                Created = DateTime.Now,
                User    = user,
                Post    = post
            };
            await _commentService.AddReply(reply);

            return(RedirectToAction("Index", "Post", new { Id = reply.Post.Id }));
        }
Пример #28
0
        public ActionResult Delete(int id)
        {
            PostReply postReply = db.PostReplies.Find(id);

            if (postReply.UserId == User.Identity.GetUserId() || User.IsInRole("Admin"))
            {
                db.PostReplies.Remove(postReply);
                db.SaveChanges();
                return(Redirect("/Posts/Show/" + postReply.PostId));
            }
            else
            {
                TempData["message"] = "Nu aveti dreptul sa faceti modificari";
                return(RedirectToAction("Index", "Posts"));
            }
        }
Пример #29
0
        public bool ReplyOnComment(PostReply model)
        {
            var replyToPost = new Reply()
            {
                ReplyText = model.ReplyText,
                Author    = _userName,
                CommentId = model.CommentId,
                UserId    = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Replies.Add(replyToPost);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #30
0
        public async Task<PostReply> AddReply(NewPostReplyModel replyModel, ClaimsPrincipal user)
        {
            var postAuthor = !replyModel.IsAnonymous
                    ? new PostAuthor(user.GetUserId(), user.GetUserName())
                    : null;

            var postReply = new PostReply(
                replyModel.PostId,
                replyModel.PostReplyId,
                replyModel.Message,
                postAuthor);

            var result = await dbContext.PostReplies.Upsert(postReply);
            notificationsQueue.Enqueue(new(user.GetUserId(), replyModel.PostId));
            return result;
        }