Example #1
0
        public ActionResult InsertComment(CommentBL comment)
        {
            try
            {
                if (BaseMVC.getUserId() != 0)
                {
                    comment.IdUser = BaseMVC.getUserId();
                }
                else if (comment.AnonymousEmail == null || comment.AnonymousName == null)
                {
                    return(Json(new { success = false, annonymousCredentials = false }));
                }

                var newUserId = KitBL.Instance.Comments.Insert(comment);
                if (newUserId > 0)
                {
                    UserBL user = new UserBL();
                    user.Id        = newUserId;
                    user.UserType  = UserTypeBL.Prospect;
                    user.FirstName = user.LastName = UserTypeBL.Member.ToString();
                    BaseMVC.setUser(user);

                    return(Json(new { success = true, newUser = true }));
                }
                return(Json(new { success = true }));
            }
            catch
            {
                return(Json(new { success = false }));
            }
        }
Example #2
0
 private void CommentChanged(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user, params string[] channelPath)
 {
     try {
         XUri     channel  = _channel.At(COMMENTS).At(channelPath);
         XUri     resource = CommentBL.GetUri(comment).WithHost(_wikiid);
         string[] origin   = new string[] { CommentBL.GetUri(comment).AsServerUri().ToString() };
         string   path     = parent.Title.AsUiUriPath() + "#comment" + comment.Number;
         XDoc     doc      = new XDoc("deki-event")
                             //userid is deprecated and user/id should be used instead
                             .Elem("userid", comment.PosterUserId)
                             .Elem("pageid", comment.PageId)
                             .Elem("uri.page", PageBL.GetUriCanonical(parent).AsServerUri().ToString())
                             .Start("user")
                             .Attr("id", user.ID)
                             .Attr("anonymous", UserBL.IsAnonymous(user))
                             .Elem("uri", UserBL.GetUri(user))
                             .End()
                             .Elem("channel", channel)
                             .Elem("uri", CommentBL.GetUri(comment).AsServerUri().ToString())
                             .Elem("path", path)
                             .Start("content").Attr("uri", CommentBL.GetUri(comment).AsServerUri().At("content").ToString()).End();
         if (comment.Content.Length < 255)
         {
             doc["content"].Attr("type", comment.ContentMimeType).Value(comment.Content);
         }
         Queue(eventTime, channel, resource, origin, doc);
     } catch (Exception e) {
         _log.WarnMethodCall("CommentChanged", "event couldn't be created");
     }
 }
        public Yield DeleteComment(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE    page    = null;
            CommentBE comment = null;

            GetCommentFromRequest(context, Permissions.ADMIN, out page, out comment);
            CommentBL.DeleteComment(page, comment);
            response.Return(DreamMessage.Ok());
            yield break;
        }
        public List <CommentModel> GetBoatDetailsById(int boatId, int commentId)
        {
            CommentBL comment = new CommentBL();

            if (boatId != 0)
            {
                a = comment.GetCommentsByBoatId(boatId);
            }
            return(a);
        }
Example #5
0
        public void Update(CommentBL comment)
        {
            if (null == comment)
            {
                return;
            }

            var item = AutoMapperBL <CommentBL, Comment> .Map(comment);

            Dbcontext.UowRepositoryComments.Update(item);
            Dbcontext.Save();
        }
Example #6
0
        public void CommentOnBoat()
        {
            CommentModel model = new CommentModel
            {
                comment     = "this boat is perfect",
                commentDate = DateTime.Now,
                boatId      = 5010,
                userId      = 11
            };;
            CommentBL com    = new CommentBL();
            var       result = com.SaveComment(model);

            Assert.IsTrue(result);
        }
Example #7
0
        public void Create(CommentBL comment)
        {
            if (null == comment)
            {
                return;
            }

            var item = new Comment()
            {
                Body = comment.Comment, UserId = comment.UserId, WorkId = comment.WorkId
            };

            Dbcontext.UowRepositoryComments.Create(item);
            Dbcontext.Save();
        }
Example #8
0
        public ActionResult NewComment(int postId)
        {
            CommentBL  commentBL = new CommentBL();
            CommentsVM comVM     = new CommentsVM();

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();
            comVM.newComment        = new Comment();
            comVM.newComment.PostId = postId;
            if (Session["login"] != null)
            {
                comVM.newComment.userName = Session["login"].ToString();
            }

            return(PartialView(comVM));
        }
        public Yield GetComment(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE    page      = null;
            CommentBE comment   = null;
            var       commentId = context.GetParam <uint>("commentid", 0);

            if (commentId > 0)
            {
                comment = CommentBL.GetComment(commentId);
            }
            else
            {
                GetCommentFromRequest(context, Permissions.READ, out page, out comment);
            }
            response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null)));
            yield break;
        }
Example #10
0
        public int Insert(CommentBL comment)
        {
            var           insertNewUser = 0;
            BLToDALMapper poMapper      = new BLToDALMapper();
            Comment       mappedComment = poMapper.MapComment(comment);

            if (mappedComment.IdUser == 0)
            {
                mappedComment.IdUser = DAL.SDK.Kit.Instance.Users.Insert(new User
                {
                    Email          = comment.AnonymousEmail,
                    FirstName      = comment.AnonymousName,
                    LastName       = "Guest",
                    Flags          = UserFlags.NotConfirmed,
                    JoinDate       = DateTime.Now,
                    UserType       = UserType.Prospect,
                    PasswordHashed = "password"
                });
                insertNewUser = mappedComment.IdUser;
                Softvision.BL.Services.SMTP.sendEmail("*****@*****.**", comment.AnonymousEmail, "Welcome " + comment.AnonymousName + " to Knowledgeshare.ro!", "Welcome! Please log in and continue contributing to our community! Your login email is: " + comment.AnonymousEmail);

                if (mappedComment.IdUser == 0)
                {
                    mappedComment.IdUser = 6;
                }
                else
                {
                    mappedComment.Flags = CommentsFlags.NotConfirmed;
                }
            }
            mappedComment.CreatedDate = DateTime.Now;
            DAL.SDK.Kit.Instance.Comments.InsertComment(mappedComment);

            //send email
            var article = DAL.SDK.Kit.Instance.Articles.GetArticleById(comment.IdArticle);
            var user    = DAL.SDK.Kit.Instance.Users.GetUserById(article.IdUser);

            Softvision.BL.Services.SMTP.sendEmail("*****@*****.**", user.Email, "New comment to your article!", user.FirstName + ", you have a new comment on on your aricle " + article.Title + ". You can check it out: " + comment.TextField);

            return(insertNewUser);
        }
        public Yield PostPageComment(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE page = PageBL_AuthorizePage(context, null, Permissions.READ, false);

            if (UserBL.IsAnonymous(DekiContext.Current.User))
            {
                throw new CommentPostForAnonymousDeniedException(AUTHREALM, string.Empty);
            }
            CommentBE comment = CommentBL.PostNewComment(page, request, context);

            if (comment != null)
            {
                DekiContext.Current.Instance.EventSink.CommentCreate(DekiContext.Current.Now, comment, page, DekiContext.Current.User);
                response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null)));
            }
            else
            {
                throw new CommentFailedPostFatalException();
            }
            yield break;
        }
Example #12
0
        public ActionResult CommentList(CommentsVM comVM)
        {
            comVM.newComment.date = DateTime.Now;

            CommentBL commentBL = new CommentBL();

            commentBL.AddComment(comVM.newComment);
            int postId = comVM.newComment.PostId;

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();

            PostBL      postBL = new PostBL();
            List <Post> list   = postBL.GetPosts();
            Post        post   = list.Where(u => u.PostId == postId).Single();

            post.numOfComments += 1;
            postBL.EditPost(post);

            return(PartialView("CommentList", comVM));
        }
Example #13
0
        public ActionResult DeleteComment(int id)
        {
            CommentBL commentBL = new CommentBL();
            Comment   c         = commentBL.GetComments().Where(u => u.CommentId == id).Single();

            commentBL.DeleteComment(c);
            int postId = c.PostId;

            PostBL      postBL = new PostBL();
            List <Post> list   = postBL.GetPosts();
            Post        post   = list.Where(u => u.PostId == postId).Single();

            post.numOfComments -= 1;
            postBL.EditPost(post);

            CommentsVM comVM = new CommentsVM();

            comVM.commentsList = commentBL.FindComments(postId);
            comVM.commentsList.Reverse();

            return(PartialView("CommentList", comVM));
        }
        public Yield PutCommentContent(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE    page    = null;
            CommentBE comment = null;

            GetCommentFromRequest(context, Permissions.READ, out page, out comment);
            if (UserBL.IsAnonymous(DekiContext.Current.User))
            {
                throw new CommentPostForAnonymousDeniedException(AUTHREALM, string.Empty);
            }
            comment = CommentBL.EditExistingComment(page, comment, request, context);
            if (comment != null)
            {
                DekiContext.Current.Instance.EventSink.CommentUpdate(DekiContext.Current.Now, comment, page, DekiContext.Current.User);
                response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null)));
            }
            else
            {
                throw new CommentFailedEditFatalException();
            }
            yield break;
        }
        public ActionResult Details(WorkVM user)
        {
            HttpCookie cookieReq = Request.Cookies["Localhost cookie"];

            int ids = 0;

            if (cookieReq != null)
            {
                ids = Convert.ToInt32(cookieReq["ids"]);
            }

            WorkBL newUser = AutoMapperBL <WorkVM, WorkBL> .Map(user);

            CommentBL newComment = new CommentBL();

            newComment.Comment = newUser.Title;
            newComment.WorkId  = newUser.Id;
            newComment.UserId  = ids;


            return(RedirectToActionPermanent("Index", "Works"));
        }
Example #16
0
        public ActionResult PostComments(int postID)
        {
            var postComments = new CommentBL().GetCommentsByPostID(postID);

            return(PartialView(postComments));
        }
Example #17
0
 public Comment MapComment(CommentBL comment)
 {
     return(Mapper.Map <CommentBL, Comment>(comment));
 }
        public Yield GetPageComments(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            CheckResponseCache(context, false);

            PageBE page = PageBL_AuthorizePage(context, null, Permissions.READ, false);
            uint   count, offset;

            string        filterStr = context.GetParam("filter", "nondeleted");
            CommentFilter filter;

            switch (filterStr.ToLowerInvariant())
            {
            case "any":
                filter = CommentFilter.ANY;
                break;

            case "nondeleted":
                filter = CommentFilter.NONDELETED;
                break;

            default:
                throw new CommentFilterInvalidArgumentException();
            }
            bool   includeDescendantPages = false;
            string depth = context.GetParam("depth", "0");

            switch (depth.ToLowerInvariant())
            {
            case "0":
                includeDescendantPages = false;
                break;

            case "infinity":
                includeDescendantPages = true;
                break;

            default:
                throw new DreamBadRequestException(string.Format("Invalid depth value '{0}'. Supported values are '0' and 'infinity'.", depth));
            }

            uint postedByUserIdtmp = context.GetParam <uint>("postedbyuserid", 0);
            uint?postedByUserId    = null;

            if (postedByUserIdtmp > 0)
            {
                postedByUserId = postedByUserIdtmp;
            }

            SortDirection sortDir;
            string        sortField;

            Utils.GetOffsetAndCountFromRequest(context, 100, out count, out offset, out sortDir, out sortField);
            sortDir = sortDir == SortDirection.UNDEFINED ? SortDirection.ASC : sortDir; // default sort is ascending by timestamp
            uint totalCount;
            XUri commentsUri           = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "comments");
            IList <CommentBE> comments = CommentBL.RetrieveCommentsForPage(page, filter, includeDescendantPages, postedByUserId, sortDir, offset, count, out totalCount);

            XDoc     ret = null;
            MimeType mimetype;

            switch (context.GetParam("format", "xml").ToLowerInvariant())
            {
            case "xml":
                ret      = CommentBL.GetCommentXml(comments, true, null, includeDescendantPages, offset, sortDir, null, commentsUri, totalCount);
                mimetype = MimeType.XML;
                break;

            case "atom":
                ret      = CommentBL.GetCommentXmlAsAtom(comments, context.Uri, page);
                mimetype = MimeType.ATOM;
                break;

            default:
                throw new DreamBadRequestException("Invalid format. Valid formats are 'xml' and 'atom'.");
            }

            response.Return(DreamMessage.Ok(mimetype, ret));
            yield break;
        }
        public ActionResult GetComments(WorkVM work)
        {
            HttpCookie cookieReqs = Request.Cookies["Localhost cookie"];
            int        idsWork    = work.Id;

            int idsUser = 0;

            if (cookieReqs != null)
            {
                idsUser = Convert.ToInt32(cookieReqs["ids"]);
            }
            else
            {
                FormsAuthentication.SignOut();
            }

            if (work.UserId != 0)
            {
                RatingBL userRatingForWork = ratingBL.GetRatings().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault();

                RatingBL newRating = new RatingBL
                {
                    Rank   = work.UserId,
                    UserId = idsUser,
                    WorkId = idsWork
                };

                if (userRatingForWork != null)
                {
                    RatingBL old = ratingBL.GetRating(userRatingForWork.Id);
                    ratingBL.DeleteRating(old.Id);
                    ratingBL.Create(newRating);
                }
                else
                {
                    ratingBL.Create(newRating);
                }
            }

            if (work.Name != null)
            {
                CommentBL newComment = new CommentBL();
                newComment.Comment = work.Name;
                newComment.UserId  = idsUser;
                newComment.WorkId  = idsWork;
                CommentBL test = commentBL.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault();

                if (null != commentBL.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault())
                {
                    CommentBL old = commentBL.GetComment(test.Id);
                    commentBL.DeleteComment(old.Id);
                    commentBL.Create(newComment);
                }
                else
                {
                    commentBL.Create(newComment);
                }
            }

            var commentList = commentBL.GetComments().Join(workBL.GetWorks(),
                                                           c => c.WorkId,
                                                           w => w.Id, (c, w) => new { Id = c.Id, Comment = c.Comment, UserId = c.UserId, WorkId = c.WorkId }).Join(userBL.GetUsers(),
                                                                                                                                                                   c => c.UserId,
                                                                                                                                                                   u => u.Id, (c, u) => new UserWithCommentVM {
                Id = c.Id, UserName = u.Login, Comment = c.Comment, WorkId = c.WorkId, IsDelete = u.IsDelete
            }).ToList();

            foreach (var item in commentList)
            {
                if (item.IsDelete == true)
                {
                    item.UserName = "******";
                }
            }
            ViewBag.CommentsList = commentList.Where(c => c.WorkId == idsWork).ToList();



            List <RatingBL> lst = ratingBL.GetRatings().Where(x => x.WorkId == idsWork).Join(userBL.GetUsers(),
                                                                                             c => c.UserId,
                                                                                             u => u.Id, (c, u) => new RatingBL {
                Id = c.Id, Rank = c.Rank, UserId = c.UserId, WorkId = c.WorkId, IsDeleteCheck = u.IsDelete
            }).Where(x => x.IsDeleteCheck == false).ToList();

            if (lst.Count != 0)
            {
                int sum    = 0;
                int rating = 0;
                foreach (var item in lst)
                {
                    sum += item.Rank;
                }
                rating          = sum / lst.Count;
                ViewBag.Ratings = rating;
            }
            else
            {
                ViewBag.Ratings = 0;
            }
            return(View("_CommentsTable"));
        }