Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 public override List <Item> FindAll()
 {
     return(new List <Item>(CreateCriteria()
                            .CreateAlias("Category", "c")
                            .AddOrder(Order.Asc("c.Name"))
                            .AddOrder(Order.Asc("Name"))
                            .List <Item>()));
 }
Exemplo n.º 4
0
        public ActionResult AsList()
        {
            var criteria = DetachedCriteria.For <Article>().AddOrder(Order.Asc(Article.IndexProperty));

            criteria.Add(Restrictions.Eq(Article.PlacementProperty, ArticlePlacement.TopMenu));
            IList <Article> articles = daoTemplate.FindByCriteria <Article>(criteria);

            return(View(articles));
        }
Exemplo n.º 5
0
        //
        // GET: /Outcome/

        public ActionResult List()
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(Outcome));

            criteria.AddOrder(Order.Asc("Date"));
            var outcomes = daoTemplate.FindByCriteria <Outcome>(criteria);
            IEnumerable <OutcomeListItemViewModel> viewModels = outcomes.Select(income => new OutcomeListItemViewModel(income));

            return(View(viewModels));
        }
Exemplo n.º 6
0
        public IEnumerable <Category> ListCategoriesForProduct(Guid id)
        {
            var searchCriteria = DetachedCriteria.For(typeof(Category), "c")
                                 .CreateAlias("Products", "p")
                                 .Add(Restrictions.Eq("p.Id", id))
                                 .AddOrder(Order.Asc("Name"))
                                 .SetResultTransformer(new DistinctRootEntityResultTransformer());


            return(repository.Search(searchCriteria));
        }
Exemplo n.º 7
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>());
        }
Exemplo n.º 8
0
        private IList <SelectListItem> Products()
        {
            var products = daoTemplate.FindByCriteria(DetachedCriteria.For(typeof(Product)).AddOrder(Order.Asc("Name")));

            return((from Product product in products
                    select new SelectListItem()
            {
                Text = product.Name, Value = product.Id.ToString()
            }).ToList());
        }
Exemplo n.º 9
0
 public Order Asc()
 {
     return(Order.Asc(PropertyName));
 }
Exemplo n.º 10
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>());
        }