public HttpResponseMessage EditComment(string sessionKey, int id, CommentModel comment)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!"));
            }

            if (id != comment.ID)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            Comment updatedComment = null;

            try
            {
                updatedComment =
                    CommentsMapper.ToCommentEntity(comment, usersRepository);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid comment model provided!"));
            }

            this.commentsRepository.Update(id, updatedComment);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage AddComment(string sessionKey, CommentModel comment)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!"));
            }

            comment.Author = user.Nickname;

            Comment commentEntity = null;

            try
            {
                commentEntity = CommentsMapper.ToCommentEntity(comment, usersRepository);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid news article model provided!"));
            }

            comment.ID = commentEntity.ID;

            this.commentsRepository.Add(commentEntity);

            return(Request.CreateResponse(HttpStatusCode.Created, comment));
        }
        public HttpResponseMessage GetAll(string sessionKey)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid user!"));
            }

            ICollection <CommentModel> comments        = new List <CommentModel>();
            IQueryable <Comment>       commentEntities = this.commentsRepository.GetAll();

            foreach (var comment in commentEntities)
            {
                comments.Add(CommentsMapper.ToCommentModel(comment));
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, comments);

            return(response);
        }
Exemple #4
0
        protected void PostComment_OnClick(object sender, EventArgs e)
        {
            Comment newComment = CreateFromFields();

            if (this.ReplyToComment != null)
            {
                newComment.ReplyToCommentID = this.ReplyToComment.ID;
            }

            Return ReturnObj = CommentsMapper.Insert(newComment);

            if (ReturnObj != null)
            {
                switch (ReturnObj.IsError)
                {
                case false:
                    BasePage.SendMediaCommentApprovalRequest(CurrentMedia);

                    if (this.ReplyToComment != null)
                    {
                        BasePage.SendMediaReplyToComment(newComment, this.ReplyToComment);
                    }

                    ServerMessage.Text = "Thank you for your feedback. This is a moderated post. Your comment has been submitted for approval";

                    break;

                case true:
                    ServerMessage.Text = $"Error adding comment: {ReturnObj.Error}";
                    Bind();
                    break;
                }
            }
        }
        public HttpResponseMessage GetComments(string sessionKey)
        {
            User user = null;

            try
            {
                user = this.usersRepository.GetBySessionKey(sessionKey);
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid session key provided!"));
            }

            ICollection <CommentModel> commentModels = new List <CommentModel>();

            IQueryable <Comment> comments = this.commentsRepository
                                            .GetAll().Where(c => c.AuthorID == user.ID);

            foreach (Comment comment in comments)
            {
                commentModels.Add(CommentsMapper.ToCommentModel(comment));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, commentModels));
        }
        private Comment CreateFromFields()
        {
            Comment comment = CommentsMapper.CreateObject();

            comment.Name    = Name.Text;
            comment.Email   = Email.Text;
            comment.Message = Message.Text;

            comment.Status = StatusEnum.Pending.ToString();

            comment.Media    = CurrentMedia;
            comment.Language = BasePage.CurrentLanguage;

            return(comment);
        }
Exemple #7
0
        protected void DeletePermanently_OnClick(object sender, EventArgs e)
        {
            Comment comment = CommentsMapper.GetByID(long.Parse(((Button)sender).CommandArgument));

            comment = BaseMapper.GetObjectFromContext <Comment>(comment);

            //comment.MediaDetails.Clear();
            Return obj = CommentsMapper.DeletePermanently(comment);

            if (obj.IsError)
            {
                this.BasePage.DisplayErrorMessage("Error", obj.Error);
            }

            SetComments(statusEnum, mode, media);
        }
Exemple #8
0
        protected void Reject_OnClick(object sender, EventArgs e)
        {
            Comment comment = CommentsMapper.GetByID(long.Parse(((Button)sender).CommandArgument));

            comment = BaseMapper.GetObjectFromContext <Comment>(comment);

            comment.Status = StatusEnum.Rejected.ToString();
            Return obj = CommentsMapper.Update(comment);

            if (obj.IsError)
            {
                this.BasePage.DisplayErrorMessage("Error", obj.Error);
            }

            SetComments(statusEnum, mode, media);
        }
Exemple #9
0
        private void ChangeStatus(long commandArgument, StatusEnum newStatus)
        {
            var comment = CommentsMapper.GetByID(commandArgument);

            if (comment != null)
            {
                comment.Status = newStatus.ToString();

                var returnObj = CommentsMapper.Update(comment);

                if (returnObj.IsError)
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
                else
                {
                    BasePage.DisplaySuccessMessage("Successfully Updated Comment");
                    BasePage.ExecuteRawJS("UpdateCommentsTab(); RefreshSiteTreeNodeById(" + AdminBasePage.SelectedMedia.ParentMediaID + "); ReloadPreviewPanel(); ");
                }
            }
        }
Exemple #10
0
        protected void DeleteComment_Click(object sender, EventArgs e)
        {
            var commandArgument = long.Parse(((LinkButton)sender).CommandArgument);

            var comment = CommentsMapper.GetByID(commandArgument);

            if (comment != null)
            {
                var returnObj = CommentsMapper.DeletePermanently(comment);

                if (returnObj.IsError)
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
                else
                {
                    BasePage.DisplaySuccessMessage("Successfully Deleted Comment");
                    BasePage.ExecuteRawJS("UpdateCommentsTab(); RefreshSiteTreeNodeById(" + AdminBasePage.SelectedMedia.ParentMediaID + "); ReloadPreviewPanel(); ");
                }
            }
        }
Exemple #11
0
        private void ChangeStatus(long commandArgument, StatusEnum newStatus)
        {
            var comment = CommentsMapper.GetByID(commandArgument);

            if (comment != null)
            {
                comment.Status = newStatus.ToString();

                var returnObj = CommentsMapper.Update(comment);

                if (returnObj.IsError)
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
                else
                {
                    BasePage.DisplaySuccessMessage("Successfully Updated Comment");
                    BasePage.ExecuteRawJS("UpdateCommentsTab();");
                }
            }
        }
Exemple #12
0
        protected void DeleteComment_Click(object sender, EventArgs e)
        {
            var commandArgument = long.Parse(((LinkButton)sender).CommandArgument);

            var comment = CommentsMapper.GetByID(commandArgument);

            if (comment != null)
            {
                var returnObj = CommentsMapper.DeletePermanently(comment);

                if (returnObj.IsError)
                {
                    BasePage.DisplayErrorMessage("Error", returnObj.Error);
                }
                else
                {
                    BasePage.DisplaySuccessMessage("Successfully Deleted Comment");
                    BasePage.ExecuteRawJS("UpdateCommentsTab();");
                }
            }
        }
        protected void PostComment_OnClick(object sender, EventArgs e)
        {
            Comment newComment = CreateFromFields();

            if (this.ReplyToCommentID != 0)
            {
                newComment.ReplyToCommentID = this.ReplyToCommentID;
            }

            var mediaDetail = CurrentMedia.GetLiveMediaDetail();

            if (!mediaDetail.CommentsAreModerated)
            {
                newComment.Status = StatusEnum.Approved.ToString();
            }

            Return ReturnObj = CommentsMapper.Insert(newComment);

            if (ReturnObj != null)
            {
                switch (ReturnObj.IsError)
                {
                case false:
                    if (mediaDetail.CommentsAreModerated)
                    {
                        BasePage.SendMediaCommentApprovalRequest(CurrentMedia, newComment);
                    }

                    if (this.ReplyToCommentID != 0)
                    {
                        var comment = CommentsMapper.GetByID(ReplyToCommentID);

                        if (comment != null)
                        {
                            BasePage.SendMediaReplyToComment(newComment, comment);
                        }
                    }

                    ServerMessage.Visible = true;

                    if (mediaDetail.CommentsAreModerated)
                    {
                        ServerMessage.InnerHtml = "Thank you for your feedback. This is a moderated post. Your comment has been submitted for approval";
                    }
                    else
                    {
                        ServerMessage.InnerHtml = "Thank you for your feedback";
                    }

                    ServerMessage.Attributes["class"] += " alert alert-primary";


                    break;

                case true:
                    ServerMessage.Visible              = true;
                    ServerMessage.InnerHtml            = $"Error adding comment: {ReturnObj.Error}";
                    ServerMessage.Attributes["class"] += " alert alert-danger";

                    Bind();
                    break;
                }
            }
        }
        /// <summary>
        /// Helps map photo data transfer object.
        /// </summary>
        protected PhotoDTO MapPhoto(Photo photo)
        {
            User currentUser = _currentUserService.Get;

            if (currentUser == null)
            {
                var likes = new List <LikeDTO>(photo.Likes.Count);

                foreach (var like in photo.Likes)
                {
                    likes.Add(LikesMapper.Map(like,
                                              UsersMapper.Map(
                                                  like.Owner,
                                                  _unitOfWork.Confirmations.Find(c => c.UserId == like.OwnerId).FirstOrDefault() != null,
                                                  false, false, false
                                                  )));
                }

                var comments = new List <CommentDTO>(photo.Comments.Count);

                foreach (var comment in photo.Comments)
                {
                    comments.Add(CommentsMapper.Map(
                                     comment,
                                     UsersMapper.Map(
                                         comment.Owner,
                                         _unitOfWork.Confirmations.Find(c => c.UserId == comment.OwnerId).FirstOrDefault() != null,
                                         false, false, false
                                         )));
                }

                return(PhotosMapper.Map(
                           photo,
                           false,
                           false,
                           UsersMapper.Map(
                               photo.Owner,
                               _unitOfWork.Confirmations.Find(c => c.UserId == photo.OwnerId).FirstOrDefault() != null,
                               false, false, false
                               ),
                           likes,
                           comments,
                           TagsMapper.MapRange(_unitOfWork.Tagings.Find(t => t.PhotoId == photo.Id).Select(t => t.Tag))));
            }

            if (_unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == photo.OwnerId).FirstOrDefault() == null)
            {
                var likes = new List <LikeDTO>(photo.Likes.Count);

                foreach (var like in photo.Likes)
                {
                    likes.Add(LikesMapper.Map(like,
                                              UsersMapper.Map(
                                                  like.Owner,
                                                  _unitOfWork.Confirmations.Find(c => c.UserId == like.OwnerId).FirstOrDefault() != null,
                                                  _unitOfWork.Followings.Find(f => f.FollowedUserId == like.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                                                  _unitOfWork.Blockings.Find(b => b.BlockedUserId == like.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null,
                                                  _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == currentUser.Id).FirstOrDefault() != null
                                                  )));
                }

                var comments = new List <CommentDTO>(photo.Comments.Count);

                foreach (var comment in photo.Comments)
                {
                    comments.Add(CommentsMapper.Map(
                                     comment,
                                     UsersMapper.Map(
                                         comment.Owner,
                                         _unitOfWork.Confirmations.Find(c => c.UserId == comment.OwnerId).FirstOrDefault() != null,
                                         _unitOfWork.Followings.Find(f => f.FollowedUserId == comment.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                                         _unitOfWork.Blockings.Find(b => b.BlockedUserId == comment.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null,
                                         _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == currentUser.Id).FirstOrDefault() != null
                                         )));
                }

                return(PhotosMapper.Map(
                           photo,
                           _unitOfWork.Likes.Find(l => l.OwnerId == currentUser.Id && l.PhotoId == photo.Id).FirstOrDefault() != null,
                           _unitOfWork.Bookmarks.Find(b => b.UserId == currentUser.Id && b.PhotoId == photo.Id).FirstOrDefault() != null,
                           UsersMapper.Map(
                               photo.Owner,
                               _unitOfWork.Confirmations.Find(c => c.UserId == photo.OwnerId).FirstOrDefault() != null,
                               _unitOfWork.Followings.Find(f => f.FollowedUserId == photo.OwnerId && f.UserId == currentUser.Id).FirstOrDefault() != null,
                               _unitOfWork.Blockings.Find(b => b.BlockedUserId == photo.OwnerId && b.UserId == currentUser.Id).FirstOrDefault() != null,
                               _unitOfWork.Blockings.Find(b => b.BlockedUserId == currentUser.Id && b.UserId == photo.OwnerId).FirstOrDefault() != null
                               ),
                           likes,
                           comments,
                           TagsMapper.MapRange(_unitOfWork.Tagings.Find(t => t.PhotoId == photo.Id).Select(t => t.Tag))));
            }

            return(null);
        }