Esempio n. 1
0
 public void AddPost(Comment post, string UserId, int DemId1)
 {
     post.AspNetUserId = UserId;
     post.Date = DateTime.Now;
     post.DemotivatorId = DemId1;
     post.Text = HttpUtility.HtmlEncode(post.Text);
     using (Entities db = new Entities())
     {
         db.Comments.Add(post);
         db.SaveChanges();
         var usr = db.AspNetUsers.FirstOrDefault(x => x.Id == post.AspNetUserId);
         var ret = new
         {
             Message = post.Text,
             PostedBy = post.AspNetUserId,
             PostedByName = usr.UserName,
             PostedByAvatar = imgFolder +  defaultAvatar,
             PostedDate = TimeAgo(post.Date),
             PostId = post.Id,
             LikeCount = post.Likes.Count()
         };
         Clients.Caller.addPost(ret, DemId1);
         Clients.Others.addPost(ret, DemId1);
     }
 }
 public JsonResult AddComment(string TextMessange, int IdDem)
 {
     var comment = new Comment();
     comment.Date = DateTime.Now;
     comment.AspNetUserId = User.Identity.GetUserId();
     comment.Text = TextMessange;
     comment.DemotivatorId = IdDem;
     db.Comments.Add(comment);
     db.SaveChanges();
     var ret = new
     {
         UserName = User.Identity.Name,
         Date = comment.Date.ToString("s"),
         Text = comment.Text
     };
     return Json(ret, JsonRequestBehavior.AllowGet);
 }