示例#1
0
 public IList <Order> FindAllAdmin()
 {
     return(CreateCriteria()
            .Add(Expression.Eq("State", OrderState.Sent))
            .AddOrder(NHibOrder.Desc("DateSent"))
            .List <Order>());
 }
示例#2
0
        private DetachedCriteria GetSearchCriteriaFromListSearch(ProductListSearchCriteria listSearchCriteria, bool withTotal)
        {
            var searchCriteria = DetachedCriteria.For(typeof(Product), "p")
                                 .SetFetchMode("Prices", FetchMode.Join)
                                 .SetFetchMode("Categories", FetchMode.Join)
                                 .SetResultTransformer(new DistinctRootEntityResultTransformer());

            if (!listSearchCriteria.ShowDeletedProducts)
            {
                searchCriteria.Add(Restrictions.Eq("IsDeleted", false)); // default to showing not deleted products
            }

            if (!withTotal)
            {
                // add ordering by Property
                var sortBy = string.IsNullOrEmpty(listSearchCriteria.SortBy) ? "Name" : listSearchCriteria.SortBy;
                searchCriteria.AddOrder(listSearchCriteria.Ascending
                                            ? Order.Asc(sortBy)
                                            : Order.Desc(sortBy));
                searchCriteria.SetFirstResult(listSearchCriteria.CurrentPage * listSearchCriteria.ResultsPerPage)
                .SetMaxResults(listSearchCriteria.ResultsPerPage);
            }

            return(searchCriteria);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="criteria"></param>
        /// <param name="pageRequest"></param>
        /// <returns></returns>
        protected Page <T> Paginated <T>(ICriteria criteria, PageRequest pageRequest) where T : class
        {
            if (pageRequest.Size > 0)
            {
                criteria.SetFirstResult(pageRequest.Offset);
                criteria.SetMaxResults(pageRequest.Size);
            }

            if (pageRequest.Sort != null && pageRequest.Sort.Orders != null && pageRequest.Sort.Orders.Count > 0)
            {
                foreach (var o in pageRequest.Sort.Orders)
                {
                    if (o.Ascending)
                    {
                        criteria.AddOrder(Order.Asc(o.Property));
                    }
                    else
                    {
                        criteria.AddOrder(Order.Desc(o.Property));
                    }
                }
            }

            var result = criteria.List <T>();

            criteria.SetFirstResult(0);
            criteria.SetMaxResults(1);

            var totalElements = criteria.SetProjection(Projections.Count(Projections.Id())).UniqueResult <long>();

            return(new Page <T>(result, result.Count, pageRequest.Page, result.Count, pageRequest.Sort, totalElements,
                                pageRequest.Size));
        }
示例#4
0
        public ActionResult Index()
        {
            ViewData["categories"] = CategoryService.FindRootCategories().Where(cat => cat.IsVisible && cat.ParentIsVisible);

            var criteria = DetachedCriteria.For(typeof(Article));

            criteria.Add(Restrictions.Eq(Article.PlacementProperty, ArticlePlacement.News));
            criteria.AddOrder(Order.Desc(Article.LastUpdatedProperty));
            criteria.SetMaxResults(1);
            var articles = daoTemplate.FindByCriteria <Article>(criteria);

            if (articles.Count > 0)
            {
                ViewData["news"] = articles[0];
            }
            else
            {
                ViewData["news"] = new Article();
            }

            SetNewsArticleToViewData();


            return(View());
        }
示例#5
0
        public ActionResult Index()
        {
            var criteria = DetachedCriteria.For(typeof(Article)).AddOrder(Order.Desc(Article.LastUpdatedProperty));
            var articles = daoTemplate.FindByCriteria <Article>(criteria);

            return(View(articles));
        }
示例#6
0
        private ActionResult CommentsWidget()
        {
            var criteria = DetachedCriteria.For <Comment>();

            criteria.AddOrder(Order.Desc(Comment.DateProperty));
            var coments = daoTemplate.FindByCriteria <Comment>(criteria);

            return(View(coments));
        }
示例#7
0
        public ActionResult GetProductsJson(int productId)
        {
            var product  = daoTemplate.FindByID <Product>(productId);
            var criteria = DetachedCriteria.For <Product>();

            criteria.AddOrder(Order.Desc(Product.NameProperty));
            criteria.Add(Restrictions.Eq(Product.IsVisibleProperty, true));
            var products     = daoTemplate.FindByCriteria <Product>(criteria);
            var productsJson = products.Select(p => new { Name = p.Name, Id = p.Id, IsRecomended = product.Recomended.Contains(p) });

            return(Json(productsJson, JsonRequestBehavior.AllowGet));
        }
示例#8
0
        public ActionResult List()
        {
            var crit = DetachedCriteria.For(typeof(Question));

            crit.AddOrder(Order.Desc(Question.DateProperty));
            IList <Question> qs = daoTemplate.FindByCriteria <Question>(crit);
            var notViewed       = qs.Where(x => x.IsViewed == false);

            foreach (var q in notViewed)
            {
                q.IsViewed = true;
                daoTemplate.Save(q);
            }
            return(View(qs));
        }
示例#9
0
        private void SetNewsArticleToViewData()
        {
            DetachedCriteria criteria;
            IList <Article>  articles;

            criteria = DetachedCriteria.For(typeof(Article));
            criteria.Add(Restrictions.Eq(Article.PlacementProperty, ArticlePlacement.MainPage));
            criteria.AddOrder(Order.Desc(Article.LastUpdatedProperty));
            criteria.SetMaxResults(1);
            articles = daoTemplate.FindByCriteria <Article>(criteria);
            if (articles.Count > 0)
            {
                ViewData["article"] = articles[0].Text;
            }
            else
            {
                ViewData["article"] = "";
            }
        }
示例#10
0
        public IList <Order> FindByUserPaged(User user, int start, int size, SortDirection sortDirection, string sortField)
        {
            if (string.IsNullOrEmpty(sortField))
            {
                sortField     = "DateCreated";
                sortDirection = SortDirection.Descending;
            }

            return(CreateCriteria()
                   .Add(Expression.Eq("User", user))
                   //.AddOrder(NHibernate.Criterion.Order.Desc("DateCreated"))
                   .SetFirstResult(start)
                   .SetMaxResults(size)
                   .AddOrder(sortDirection == SortDirection.Ascending ? NHibOrder.Asc(sortField) : NHibOrder.Desc(sortField))
                   .List <Order>());
        }
示例#11
0
        public IList <Order> FindAllAdminPaged(int start, int size, SortDirection sortDirection, string sortField)
        {
            if (string.IsNullOrEmpty(sortField))
            {
                sortDirection = SortDirection.Descending;
                sortField     = "DateSent";
            }

            ICriteria criteria = CreateCriteria()
                                 .SetFirstResult(start)
                                 .SetMaxResults(size)
                                 .Add(Expression.Eq("State", OrderState.Sent))
                                 .CreateAlias("User", "user")
                                 .AddOrder(sortDirection == SortDirection.Ascending ? NHibOrder.Asc(sortField) : NHibOrder.Desc(sortField));

            return(criteria.List <Order>());
        }