Esempio n. 1
0
        public ActionResult Edit(CommentCRUDModel model)
        {
            if (ModelState.IsValid)
            {
                var crudOperations = RepositoryFactory.Command<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.Command<ISearchCommands>().DeleteFromIndex(tran, originalItem.Id.ToString());
                        RepositoryFactory.Command<ISearchCommands>().IndexComment(tran, originalItem);
                    }
                    return RedirectToActionWithAjax("Index");

                }
                else
                {
                    ModelState.AddModelError(string.Empty, ModelResources.ItemNotExistsError);
                }
            }
            return ViewWithAjax(model);
        }
Esempio n. 2
0
 public ActionResult Delete(CommentCRUDModel model)
 {
     var item = RepositoryFactory.Command<ICommentCrud>().FindByPk(model.Id);
     using (var tran = RepositoryFactory.StartTransaction(IoC.Resolve<SearchUpdateContext>()))
     {
         RepositoryFactory.Command<ICommentCrud>().Delete(item);
         tran.Commit();
         RepositoryFactory.Command<ISearchCommands>().DeleteFromIndex(tran, item.Id.ToString());
     }
     return RedirectToActionWithAjax("Index");
 }
Esempio n. 3
0
        public ActionResult NewComment(PagedModel<CommentViewModel> commentsModel, CommentCRUDModel model, string sort)
        {
            var staticText = RepositoryFactory.Command<IStaticTextData>().Get(model.ContentId, DateTime.Now);
            model.ChangeUser = CurrentUser;

            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.Command<ICommentCrud>().Create(model);
                    tran.Commit();
                    RepositoryFactory.Command<ISearchCommands>().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
                });
        }
Esempio n. 4
0
        public virtual 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>().GetCommand<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);
            }
        }
Esempio n. 5
0
        public virtual 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>().GetCommand<ICommentCrud>();
                var dataActions = RepositoryFactory.GetRepository<Comment>().GetCommand<ICommentData>();

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

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

                TestProvider.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();
                }

                TestProvider.WaitForIndexing();

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