public ApiComment Add(ApiComment apiComment)
        {
            db.Comments.Add(Mapper.Map <ApiComment, Comment>(apiComment));
            db.SaveChanges();

            return(apiComment);
        }
Beispiel #2
0
        public ApiComment SingleComment(int id)
        {
            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var resultModel = new ApiComment
            {
                Id             = comment.Id,
                Date           = comment.Date,
                LastEditDate   = comment.LastEditDate,
                Likes          = comment.Likes,
                Dislikes       = comment.Dislikes,
                CommentContent = comment.CommentContent,
                ParentId       = comment.ParentId,
                MessageId      = comment.MessageId
            };

            if (comment.Message.Anonymized || comment.Message.Subverses.anonymized_mode)
            {
                resultModel.Name = comment.Id.ToString();
            }
            else
            {
                resultModel.Name = comment.Name;
            }

            return(resultModel);
        }
Beispiel #3
0
        public ApiComment SingleComment(int id)
        {
            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var resultModel = new ApiComment
            {
                Id             = comment.ID,
                Date           = comment.CreationDate,
                LastEditDate   = comment.LastEditDate,
                Likes          = (int)comment.UpCount,
                Dislikes       = (int)comment.DownCount,
                CommentContent = comment.Content,
                ParentId       = comment.ParentID,
                MessageId      = comment.SubmissionID
            };

            if (comment.Submission.IsAnonymized || comment.Submission.Subverse1.IsAnonymized)
            {
                resultModel.Name = comment.ID.ToString();
            }
            else
            {
                resultModel.Name = comment.UserName;
            }

            return(resultModel);
        }
Beispiel #4
0
        public JsonResult cmt(int id, string com)
        {
            if (userId() == -1)
            {
                return(Json(null));
            }
            Comment cmt = new Comment()
            {
                CommentBody = com,
                UserId      = userId(),
                ProductId   = id,
                date        = DateTime.Now
            };

            _db.Comments.Add(cmt);
            _db.SaveChanges();

            Account ac = _db.Accounts
                         .Where(c => c.Id == cmt.UserId).SingleOrDefault();

            ApiComment res = new ApiComment
            {
                Body     = cmt.CommentBody,
                Name     = ac.FullName,
                UrlImage = ac.ImageUrl
            };

            return(Json(res));
        }
Beispiel #5
0
 public Comment(ApiComment comment, Account account)
 {
     ApiComment = comment;
     ApiPost    = comment;
     Account    = account;
     ParseContent(comment.Content);
     LoadProfileImage().ContinueWith(t => t);
 }
Beispiel #6
0
 // Displays a comment in the console
 public static void DisplayComment(ApiComment comment)
 {
     Console.WriteLine($"ID - {comment.ID}\n" +
                       $"Content - {comment.Content}\n" +
                       $"Date posted - {comment.DatePosted}\n" +
                       $"Type - {comment.Type}");
     Console.WriteLine("========= User ========");
     DisplayUser(comment.User);
 }
Beispiel #7
0
        public IEnumerable <ApiComment> SubmissionComments(int submissionId)
        {
            var submission = _db.Messages.Find(submissionId);

            if (submission == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var firstComments = from f in submission.Comments
                                let commentScore = f.Likes - f.Dislikes
                                                   where f.ParentId == null
                                                   orderby commentScore descending
                                                   select f;

            var resultList = new List <ApiComment>();

            foreach (var firstComment in firstComments)
            {
                //do not show deleted comments unless they have replies
                if (firstComment.Name == "deleted" && submission.Comments.Count(a => a.ParentId == firstComment.Id) == 0)
                {
                    continue;
                }

                var resultModel = new ApiComment
                {
                    Id             = firstComment.Id,
                    Date           = firstComment.Date,
                    Dislikes       = firstComment.Dislikes,
                    LastEditDate   = firstComment.LastEditDate,
                    Likes          = firstComment.Likes,
                    MessageId      = firstComment.MessageId,
                    ParentId       = firstComment.ParentId,
                    CommentContent = firstComment.CommentContent
                };

                if (firstComment.Message.Anonymized || firstComment.Message.Subverses.anonymized_mode)
                {
                    resultModel.Name = firstComment.Id.ToString();
                }
                else
                {
                    resultModel.Name = firstComment.Name;
                }

                // TODO
                // fetch child comments

                resultList.Add(resultModel);
            }

            return(resultList);
        }
 public ApiComment Put([FromBody] ApiComment apiComment)
 {
     try
     {
         apiComment = service.Update(apiComment);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(apiComment);
 }
        public ApiComment GetSingle(int?id)
        {
            ApiComment apiComment = new ApiComment();

            try
            {
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(apiComment);
        }
        public ApiComment Update(ApiComment apiComment)
        {
            var commentInDB = db.Comments.Where(c => c.UserID == apiComment.UserID && c.ProID == apiComment.ProID).FirstOrDefault();

            if (commentInDB != null)
            {
                commentInDB = Mapper.Map <ApiComment, Comment>(apiComment);
                db.Entry(commentInDB).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }

            return(apiComment);
        }
 public ActionResult CreateComment(ApiComment comment)
 {
     try
     {
         var result = CommentRepository.CreateComment(comment.Cast());
         if (result == null)
         {
             return(StatusCode(500));
         }
         return(Ok(new ApiComment(result)));
     }
     catch
     {
         return(StatusCode(500));
     }
 }
 public ActionResult <ApiComment> UpdateComment(int id, ApiComment apiComment)
 {
     try
     {
         var result = CommentRepository.UpdateComment(id, apiComment.User, apiComment.Message, apiComment.IsLike);
         if (result == null)
         {
             return(StatusCode(500));
         }
         return(new ActionResult <ApiComment>(new ApiComment(result)));
     }
     catch
     {
         return(StatusCode(500));
     }
 }
Beispiel #13
0
        public IHttpActionResult Comments(string token, Guid referenceId)
        {
            if (auth.IsNotValid(token))
            {
                return(base.StatusCode(System.Net.HttpStatusCode.Unauthorized));
            }

            if (Guid.Empty == referenceId)
            {
                return(this.BadRequest("Reference Identifier"));
            }

            var userId   = auth.Device.UserIdentifier;
            var results  = this.socialCore.SearchComment(userId, referenceId);
            var comments = results.Select(r => ApiComment.Map(r));

            return(this.Ok <IEnumerable <ApiComment> >(comments));
        }
Beispiel #14
0
        public IHttpActionResult SaveComment(SecuredSocialComment comment)
        {
            if (auth.IsNotValid(comment))
            {
                return(base.StatusCode(HttpStatusCode.Unauthorized));
            }

            if (null == comment)
            {
                return(this.BadRequest("comment"));
            }

            if (comment.Delete)
            {
                if (Guid.Empty == comment.Identifier)
                {
                    return(this.BadRequest("Identifier"));
                }
            }
            else
            {
                if (Guid.Empty == comment.ReferenceIdentifier)
                {
                    return(this.BadRequest("Reference Identifier"));
                }

                if (string.IsNullOrWhiteSpace(comment.Comment))
                {
                    return(this.BadRequest("Comment must be specified"));
                }
            }

            comment.UserIdentifier = auth.Device.UserIdentifier;
            var newComment = this.socialCore.SaveComment(comment);

            emailCore.NewsFeedComment(newComment);

            var results = null != newComment?this.socialCore.SearchComment(comment.UserIdentifier, newComment.ReferenceIdentifier) : null;

            var comments = results.Select(r => ApiComment.Map(r));

            return(this.Ok <IEnumerable <ApiComment> >(comments));
        }
Beispiel #15
0
        public ApiComment AddComment(Guid patternId, Guid authorId, string text)
        {
            ApiComment apiComment = null;
            var        user       = usersRepository.GetById(authorId);
            var        pattern    = patternsRepository.GetById(patternId);

            if (user != null && pattern != null)
            {
                var comment = new Comment()
                {
                    Author  = user,
                    Pattern = pattern,
                    Text    = text
                };
                commentsRepository.Save(comment);
                apiComment = commentsRepository.GetApiComment(comment.Id);
            }
            return(apiComment);
        }
 public ApiComment Update(ApiComment comment)
 {
     return(factory.CommentsDAO.Update(comment));
 }
 public ApiComment Add(ApiComment comment)
 {
     return(factory.CommentsDAO.Add(comment));
 }
Beispiel #18
0
        public IEnumerable <ApiComment> SubmissionComments(int submissionId)
        {
            var submission = DataCache.Submission.Retrieve(submissionId);

            if (submission == null || submission.Subverse1.IsAdminDisabled == true)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            string cacheKey = String.Format("LegacyApi.SubmissionComments.{0}", submissionId).ToLower();
            IEnumerable <ApiComment> cacheData = CacheHandler.Retrieve <IEnumerable <ApiComment> >(cacheKey);

            if (cacheData == null)
            {
                cacheData = CacheHandler.Register(cacheKey, new Func <IEnumerable <ApiComment> >(() =>
                {
                    var firstComments = from f in submission.Comments
                                        let commentScore = (int)f.UpCount - (int)f.DownCount
                                                           where f.ParentID == null
                                                           orderby commentScore descending
                                                           select f;

                    var resultList = new List <ApiComment>();

                    foreach (var firstComment in firstComments.Take(10))
                    {
                        //do not show deleted comments unless they have replies
                        if (firstComment.IsDeleted && submission.Comments.Count(a => a.ParentID == firstComment.ID) == 0)
                        {
                            continue;
                        }

                        var resultModel = new ApiComment
                        {
                            Id             = firstComment.ID,
                            Date           = firstComment.CreationDate,
                            Dislikes       = (int)firstComment.DownCount,
                            LastEditDate   = firstComment.LastEditDate,
                            Likes          = (int)firstComment.UpCount,
                            MessageId      = firstComment.SubmissionID,
                            ParentId       = firstComment.ParentID,
                            CommentContent = firstComment.Content
                        };

                        if (firstComment.Submission.IsAnonymized || firstComment.Submission.Subverse1.IsAnonymized)
                        {
                            resultModel.Name = firstComment.ID.ToString();
                        }
                        else
                        {
                            resultModel.Name = firstComment.UserName;
                        }

                        // TODO
                        // fetch child comments

                        resultList.Add(resultModel);
                    }

                    return(resultList);
                }), TimeSpan.FromMinutes(5));
            }
            return(cacheData);
        }
Beispiel #19
0
        public ApiComment GetApiComment(Guid id)
        {
            ApiComment apiComment = commentsRepository.GetApiComment(id);

            return(apiComment);
        }
        public ApiComment Put(Guid patternId, ApiComment comment)
        {
            var apiComment = commentsLogic.AddComment(patternId, CurrentUser.Id, comment.Text);

            return(apiComment);
        }