Esempio n. 1
0
        public MvcContrib.Pagination.IPagination <CrawlerSessionViewModel> GetPagedList(int page, int size)
        {
            CrawlerSession  crawlerSessionAlias = null;
            CrawlerSettings settingsAlias       = null;
            var             query = Session.QueryOver <CrawlerSession>(() => crawlerSessionAlias).
                                    JoinAlias(() => crawlerSessionAlias.Settings, () => settingsAlias, JoinType.LeftOuterJoin).OrderBy(x => x.DateTime).Asc;

            var count      = query.ToRowCountQuery();
            var totalCount = count.FutureValue <int>();

            var firstResult = (page - 1) * size;

            CrawlerSessionViewModel viewModel = null;



            var viewModels =
                query.SelectList(list => list
                                 .Select(x => x.Id).WithAlias(() => viewModel.Id)
                                 .Select(x => x.Title).WithAlias(() => viewModel.Title)
                                 .Select(x => x.DateTime).WithAlias(() => viewModel.DateTime)
                                 .Select(x => x.StartUrl).WithAlias(() => viewModel.StartUrl))
                .TransformUsing(Transformers.AliasToBean(typeof(CrawlerSessionViewModel)))
                .Skip(firstResult)
                .Take(size)
                .Future <CrawlerSessionViewModel>();

            return(new CustomPagination <CrawlerSessionViewModel>(viewModels, page, size, totalCount.Value));
        }
        public ActionResult Create(CrawlerSessionViewModel crawlerSession)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var command = new ChangeCrawlerSessionCommand(
                        0,
                        crawlerSession.Title,
                        crawlerSession.StartUrl, crawlerSession.SearchDepth);

                    this._changeCrawlerSessionHandler.Handle(command);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(crawlerSession));
                }
            }
            catch (HibernateException hex)
            {
                if (NHibernateSession.Current.Transaction.IsActive)
                {
                    NHibernateSession.Current.Transaction.Rollback();
                }

                ModelState.AddModelError("", string.Format("a session with start url {0} allready exist.", crawlerSession.StartUrl));
                return(View(crawlerSession));
            }
        }
        public ActionResult Edit(int id, CrawlerSessionViewModel viewModel)
        {
            try
            {
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        // GET: /CrawlerSession/Details/5

        public ActionResult Details(int id)
        {
            CrawlerSessionViewModel viewModel = _crawlerSessionDetailsQuery.GetCrawlerSessionDetails(id);

            return(View(viewModel));
        }