예제 #1
0
        private IQueryOver <MyTraining, MyTraining> getMyTrainingsCriterias(IQueryOver <MyTraining, MyTraining> queryProducts, GetMyTrainingsParam param)
        {
            queryProducts = queryProducts.ApplyUser(param, Session, SecurityInfo);
            if (queryProducts == null)
            {
                return(null);
            }

            if (param.MyTrainingId.HasValue)
            {
                queryProducts = queryProducts.Where(day => day.GlobalId == param.MyTrainingId.Value);
            }
            if (param.StartDate.HasValue)
            {
                queryProducts = queryProducts.Where(day => day.StartDate >= param.StartDate);
            }
            if (param.EndDate.HasValue)
            {
                queryProducts = queryProducts.Where(day => day.StartDate <= param.EndDate);
            }


            if (param.TrainingEnds.Count > 0)
            {
                var langOr = Restrictions.Disjunction();
                foreach (var lang in param.TrainingEnds)
                {
                    langOr.Add <MyTraining>(x => x.TrainingEnd == (TrainingEnd)lang);
                }
                queryProducts = queryProducts.And(langOr);
            }

            IQueryOverOrderBuilder <MyTraining, MyTraining> orderBuilder;

            switch (param.SortOrder)
            {
            case MyTrainingSortOrder.StartDate:
                orderBuilder = queryProducts.OrderBy(x => x.StartDate);
                break;

            case MyTrainingSortOrder.PercentageCompleted:
                orderBuilder = queryProducts.OrderBy(x => x.PercentageCompleted);
                break;

            default:
                orderBuilder = queryProducts.OrderBy(x => x.Name);
                break;
            }
            if (param.SortAscending)
            {
                queryProducts = orderBuilder.Asc;
            }
            else
            {
                queryProducts = orderBuilder.Desc;
            }
            return(queryProducts);
        }