public ActionResult Index(PagerParameters pagerParameters)
        {
            var pager      = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            var tot        = _redirectService.GetTable().Count();
            var pagerShape = _orchardServices.New.Pager(pager).TotalItemCount(tot);
            // adjust page value (in case of a previous deletion)
            var firstItemInPage = pager.PageSize * (pager.Page - 1) + 1;

            if (firstItemInPage > tot)
            {
                pager.Page = decimal.ToInt32(decimal.Ceiling(new decimal(tot) / pager.PageSize));
                pagerShape = _orchardServices.New.Pager(pager).TotalItemCount(tot);
            }

            var     items     = _redirectService.GetRedirects(pager.GetStartIndex(), pager.PageSize);
            dynamic viewModel = Shape.ViewModel()
                                .Redirects(items)
                                .Pager(pagerShape);

            return(View((object)viewModel));
        }
Ejemplo n.º 2
0
        public void Import(
            long createdDateTimeTick,
            string sourceUrl,
            string destinationUrl,
            bool isPermanent)
        {
            var result = _redirectService.GetTable().FirstOrDefault(x => x.SourceUrl == sourceUrl);

            if (result == null)
            {
                _redirectService.Add(new RedirectRule {
                    CreatedDateTime = new DateTime(createdDateTimeTick),
                    SourceUrl       = sourceUrl,
                    DestinationUrl  = destinationUrl,
                    IsPermanent     = isPermanent
                });
            }
        }
Ejemplo n.º 3
0
        public void RedirectsAreCreatedCorrectly()
        {
            Assert.That(_redirectService.GetTable().Count(), Is.EqualTo(0));
            var role = new RedirectRule {
                SourceUrl      = "sourceUrl",
                DestinationUrl = "destinationUrl",
                IsPermanent    = false
            };

            Assert.That(_redirectService.GetTable().Count(), Is.EqualTo(0));

            PopulateTable(6);
            Assert.That(_redirectService.GetTable().Count(), Is.EqualTo(6));

            var created = _redirectService.GetRedirects().ToArray();

            Assert.That(created.Length, Is.EqualTo(6));

            var sameObjects = true;

            for (int i = 0; i < created.Length; i++)
            {
                sameObjects &= created[i].SourceUrl == ("sourceUrl" + i.ToString()) &&
                               created[i].DestinationUrl == ("destinationUrl" + i.ToString()) &&
                               created[i].IsPermanent == (i % 2 == 0);
            }

            Assert.That(sameObjects);
        }