예제 #1
0
        public ActionResult Edit(CommentCRUDModel model)
        {
            if (ModelState.IsValid)
            {
                var crudOperations = RepositoryFactory.Action<ICommentCrud>();

                // get original item to test change permissions
                var originalItem = crudOperations.FindByPk(model.Id);

                if (originalItem != null)
                {
                    originalItem.Name = model.Name;
                    originalItem.Text = model.Text;

                    using (var tran = RepositoryFactory.StartTransaction(IoC.Resolve<SearchUpdateContext>()))
                    {
                        crudOperations.Update(originalItem);
                        tran.Commit();
                        RepositoryFactory.Action<ISearchAction>().DeleteFromIndex(tran, originalItem.Id.ToString());
                        RepositoryFactory.Action<ISearchAction>().IndexComment(tran, originalItem);
                    }
                    return RedirectToActionWithAjax("Index");

                }
                else
                {
                    ModelState.AddModelError(string.Empty, ModelResources.ItemNotExistsError);
                }
            }
            return ViewWithAjax(model);
        }
예제 #2
0
 public ActionResult Delete(CommentCRUDModel model)
 {
     var item = RepositoryFactory.Action<ICommentCrud>().FindByPk(model.Id);
     using (var tran = RepositoryFactory.StartTransaction(IoC.Resolve<SearchUpdateContext>()))
     {
         RepositoryFactory.Action<ICommentCrud>().Delete(item);
         tran.Commit();
         RepositoryFactory.Action<ISearchAction>().DeleteFromIndex(tran, item.Id.ToString());
     }
     return RedirectToActionWithAjax("Index");
 }
예제 #3
0
파일: PageController.cs 프로젝트: vlko/jobs
        public ActionResult NewComment(PagedModel<CommentViewModel> commentsModel, CommentCRUDModel model, string sort)
        {
            var staticText = RepositoryFactory.Action<IStaticTextData>().Get(model.ContentId, DateTime.Now);
            model.ChangeUser = UserInfo.User;

            if (model.ChangeUser == null && model.RoboCheck != model.ExpressionCorrectValue)
            {
                ModelState.AddModelError<CommentCRUDModel>(item => item.RoboCheck, ModelResources.RoboCheckError);
            }

            // check for anonymous name required if not logged user
            if (model.ChangeUser == null && string.IsNullOrEmpty(model.AnonymousName))
            {
                ModelState.AddModelError<CommentCRUDModel>(item => item.AnonymousName, ModelResources.AnonymousRequireError);
            }
            else if (ModelState.IsValid)
            {
                model.ChangeDate = DateTime.Now;
                model.ClientIp = Request.UserHostAddress;
                model.UserAgent = Request.UserAgent;

                // for anonymous user encode text
                if (model.ChangeUser == null)
                {
                    model.Text = HtmlManipulation.RemoveTags(model.Text);
                }
                using (var tran = RepositoryFactory.StartTransaction(IoC.Resolve<SearchUpdateContext>()))
                {
                    RepositoryFactory.Action<ICommentCrud>().Create(model);
                    tran.Commit();
                    RepositoryFactory.Action<ISearchAction>().IndexComment(tran, model);
                }
                return RedirectToActionWithAjax(staticText.FriendlyUrl, routeValues: new {sort = sort});
            }

            CommentViewTypeEnum sortType = ParseCommentViewType(sort);

            IEnumerable<CommentTreeViewModel> comments;
            LoadComments(sortType, out comments, commentsModel, staticText.Id);

            return ViewWithAjax("ViewPage",
                new PageViewModel
                {
                    StaticText = staticText,
                    CommentViewType = sortType,
                    FlatComments = commentsModel,
                    TreeComments = comments,
                    NewComment = model
                });
        }
예제 #4
0
파일: CommentActions.cs 프로젝트: vlko/jobs
        public void Test_update()
        {
            using (RepositoryFactory.StartUnitOfWork())
            {
                var item = new CommentCRUDModel()
                {
                    Name = "test_update",
                    ParentId = null,
                    ChangeUser = _user,
                    AnonymousName = null,
                    ClientIp = "127.0.0.1",
                    ContentId = _testText.Id,
                    Text = "test_update",
                    ChangeDate = new DateTime(2002, 1, 1),
                    UserAgent = "ie6"
                };

                var crudActions = RepositoryFactory.GetRepository<Comment>().GetAction<ICommentCrud>();

                using (var tran = RepositoryFactory.StartTransaction())
                {
                    item = crudActions.Create(item);
                    tran.Commit();
                }

                var storedItem = crudActions.FindByPk(item.Id);

                Assert.AreEqual(item.Id, storedItem.Id);
                Assert.AreEqual(((User)item.ChangeUser).Id, ((User)storedItem.ChangeUser).Id);
                Assert.AreEqual(item.ChangeDate, storedItem.ChangeDate);
                Assert.AreEqual(item.AnonymousName, storedItem.AnonymousName);
                Assert.AreEqual(item.UserAgent, storedItem.UserAgent);
                Assert.AreEqual(item.ClientIp, storedItem.ClientIp);
                Assert.AreEqual(item.Name, storedItem.Name);
                Assert.AreEqual(item.Text, storedItem.Text);
                Assert.AreEqual(item.ContentId, storedItem.ContentId);

                item.Text = "test_update_changed";
                item.ChangeDate = new DateTime(2002, 1, 1);
                item.ChangeUser = null;

                using (var tran = RepositoryFactory.StartTransaction())
                {
                    item = crudActions.Create(item);
                    tran.Commit();
                }

                storedItem = crudActions.FindByPk(item.Id);

                Assert.AreEqual(item.Id, storedItem.Id);
                Assert.AreEqual(null, storedItem.ChangeUser);
                Assert.AreEqual(item.ChangeDate, storedItem.ChangeDate);
                Assert.AreEqual(item.AnonymousName, storedItem.AnonymousName);
                Assert.AreEqual(item.UserAgent, storedItem.UserAgent);
                Assert.AreEqual(item.ClientIp, storedItem.ClientIp);
                Assert.AreEqual(item.Name, storedItem.Name);
                Assert.AreEqual(item.Text, storedItem.Text);
                Assert.AreEqual(item.ContentId, storedItem.ContentId);
            }
        }
예제 #5
0
파일: CommentActions.cs 프로젝트: vlko/jobs
        public void Test_delete()
        {
            using (RepositoryFactory.StartUnitOfWork())
            {
                var item = new CommentCRUDModel()
                {
                    Name = "test_delete",
                    ParentId = null,
                    ChangeUser = _user,
                    AnonymousName = null,
                    ClientIp = "127.0.0.1",
                    ContentId = _testText.Id,
                    Text = "test_delete",
                    ChangeDate = new DateTime(2002, 1, 1),
                    UserAgent = "ie6"
                };

                var crudActions = RepositoryFactory.GetRepository<Comment>().GetAction<ICommentCrud>();
                var dataActions = RepositoryFactory.GetRepository<Comment>().GetAction<ICommentData>();

                var initialCommentCount = dataActions.GetAllForAdmin().Count();

                using (var tran = RepositoryFactory.StartTransaction())
                {
                    item = crudActions.Create(item);
                    tran.Commit();
                }

                WaitForIndexing();

                // check created item
                var storedItem = crudActions.FindByPk(item.Id);

                Assert.AreEqual(item.Id, storedItem.Id);
                Assert.AreEqual(((User)item.ChangeUser).Id, ((User)storedItem.ChangeUser).Id);
                Assert.AreEqual(item.ChangeDate, storedItem.ChangeDate);
                Assert.AreEqual(item.AnonymousName, storedItem.AnonymousName);
                Assert.AreEqual(item.UserAgent, storedItem.UserAgent);
                Assert.AreEqual(item.ClientIp, storedItem.ClientIp);
                Assert.AreEqual(item.Name, storedItem.Name);
                Assert.AreEqual(item.Text, storedItem.Text);
                Assert.AreEqual(item.ContentId, storedItem.ContentId);

                Assert.AreNotEqual(initialCommentCount, dataActions.GetAllForAdmin().Count());

                using (var tran = RepositoryFactory.StartTransaction())
                {
                    crudActions.Delete(item);
                    tran.Commit();
                }

                WaitForIndexing();

                Assert.AreEqual(initialCommentCount, dataActions.GetAllForAdmin().Count());
            }
        }