private static void loadExercises()
        {
            exercisesEvent.Reset();
            dictExercises = null;
            var task = Task.Factory.StartNew(delegate
            {
                ControlHelper.EnsureThreadLocalized();
                PagedResultRetriever retriever = new PagedResultRetriever();
                var res = retriever.GetAll(delegate(PartialRetrievingInfo pageInfo)
                {
                    try
                    {
                        ExerciseSearchCriteria search = ExerciseSearchCriteria.CreatePersonalCriteria();
                        return(ServiceManager.GetExercises(search, pageInfo));
                    }
                    catch (Exception)
                    {
                        exercisesEvent.Set();
                        throw;
                    }
                });
                dictExercises = res.ToDictionary(t => t.GlobalId);

                exercisesEvent.Set();
            }, exercisesEvent);

            LogUnhandledExceptions(task);
        }
 public ExerciseSearchResult GetList(ExerciseSearchCriteria criteria)
 {
     return(new ExerciseSearchResult()
     {
         SearchCriteria = criteria, Exercises = _mapper.Map <IList <Exercise> >(_context.Exercises.ToList())
     });
 }
        public void ExerciseRepository_GetExerciseRecorder_Retrieves_ExerciseRecorder_Successfully()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-practiceroutine-recorder.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IExerciseSearchCriteria crit = new ExerciseSearchCriteria
                {
                    Title = "Strumming Exercise 2"
                };

                var exercise         = uow.Exercises.Find(crit).First();
                var exerciseRecorder = uow.Exercises.GetExerciseRecorder(exercise.Id);

                Assert.IsNotNull(exerciseRecorder);
                Assert.That(exerciseRecorder.ExerciseId, Is.Not.Zero);
                Assert.AreEqual(0, exerciseRecorder.RecordedSeconds);
                Assert.IsFalse(exerciseRecorder.Recording);
                Assert.AreEqual(10, exerciseRecorder.CurrentManualProgress);
                Assert.AreEqual(5, exerciseRecorder.CurrentOverAllProgress);
                Assert.AreEqual(35, exerciseRecorder.CurrentSpeed);
                Assert.AreEqual(80, exerciseRecorder.TargetSpeed);
                Assert.AreEqual(10, exerciseRecorder.CurrentTimeProgress);
                Assert.AreEqual(60, exerciseRecorder.CurrentTotalSeconds);
                Assert.AreEqual("Strumming Exercise 2", exerciseRecorder.Title);
                Assert.AreEqual("00:01:00", exerciseRecorder.TotalSecondsDisplay);
                Assert.AreEqual(TimeFuncs.ZeroTimeDisplay, exerciseRecorder.RecordedSecondsDisplay);
            }
        }
示例#4
0
        public void TestGetExercises_OnlyBicepsAvailableForUser()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.ExerciseTypes.Add(Service.Model.ExerciseType.Biceps);
            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 7, new[] { "t02", "t04", "t05", "t12", "t14", "t15", "t25" }, null);

            profile = (ProfileDTO)profiles[1].Tag;
            data    = SecurityManager.CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 7, new[] { "t02", "t04", "t05", "t21", "t25", "t12", "t15" }, null);
        }
示例#5
0
        public void TestGetExercises_EmptyCriteria()
        {
            var                   criteria = new ExerciseSearchCriteria();
            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 0, null, null);

            profile = (ProfileDTO)profiles[1].Tag;
            data    = SecurityManager.CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 0, null, null);
        }
示例#6
0
        public PagedResult <ExerciseDTO> GetExercises(Token token, ExerciseSearchCriteria searchCriteria, PartialRetrievingInfo retrievingInfo)
        {
            var             securityInfo = SecurityManager.EnsureAuthentication(token);
            ExerciseService service      = new ExerciseService(Session, securityInfo, Configuration);

            return(service.GetExercises(searchCriteria, retrievingInfo));
        }
示例#7
0
        public void TestGetExercises_OnlyGlobalAndMine()
        {
            var criteria = ExerciseSearchCriteria.CreatePersonalCriteria();

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 21, new[] { "t01", "t02", "t03", "t04", "t05", "t06", "t07", "t08",
                                                        "t11", "t12", "t13", "t14", "t15", "t16", "t17", "t18", "t19", "t22", "t23", "t25", "t26" }, null);

            profile = (ProfileDTO)profiles[1].Tag;
            data    = SecurityManager.CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 20, new[] { "t01", "t02", "t03", "t04", "t05", "t06", "t07", "t08",
                                                        "t21", "t22", "t23", "t24", "t25", "t26", "t27", "t28", "t12", "t13", "t15", "t16" }, null);
        }
示例#8
0
        public void WithoutIsDeleted()
        {
            var deletedExercise = CreateExercise(Session, null, "test", "tt");

            deletedExercise.IsDeleted = true;
            insertToDatabase(deletedExercise);
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.ExerciseTypes.Add(Service.V2.Model.ExerciseType.Klatka);

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;

            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });

            var count = result.Items.Where(x => x.GlobalId == deletedExercise.GlobalId).Count();

            Assert.AreEqual(0, count);
        }
示例#9
0
        public void TestGetExercises_UserName()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.UserId = profiles[1].Id;

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;

            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });

            assertExercisesListPack(result, 5, new[] { "t22", "t23", "t25", "t26", "t28" }, null);

            profile = (ProfileDTO)profiles[1].Tag;
            data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });

            assertExercisesListPack(result, 8, new[] { "t21", "t22", "t23", "t24", "t25", "t26", "t27", "t28" }, null);
        }
示例#10
0
        public void TestGetExercises_PendingPublishOnly()
        {
            var criteria = new ExerciseSearchCriteria();

            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.PendingPublish);

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 2, new[] { "t19", "t28" }, null);

            profile = (ProfileDTO)profiles[1].Tag;
            data    = SecurityManager.CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });
            assertExercisesListPack(result, 2, new[] { "t19", "t28" }, null);
        }
示例#11
0
 public static PagedResult <ExerciseDTO> GetExercises(ExerciseSearchCriteria searchCriteria, PartialRetrievingInfo pageInfo)
 {
     return(exceptionHandling(delegate
     {
         pageInfo.PageSize = GetPageSize(150);
         return Instance.GetExercises(Token, searchCriteria, pageInfo);
     }));
 }
示例#12
0
 public void Fill(ExerciseSearchCriteria searchCriteria)
 {
     this.searchCriteria = searchCriteria;
     this.exercisesTree1.ClearContent();
     changeOperationState(false);
     currentPage       = 0;
     exercisesListPack = null;
     if (searchCriteria != null)
     {
         fillExercisesPage(0);
     }
 }
示例#13
0
        protected override void RetrieveObjects(BodyArchitectAccessServiceClient client1, PartialRetrievingInfo pageInfo, EventHandler <GetExercisesCompletedEventArgs> operationCompleted)
        {
            ExerciseSearchCriteria criteria = new ExerciseSearchCriteria();

            criteria.SearchGroups = new List <ExerciseSearchCriteriaGroup>();
            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.Mine);
            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.Global);
            criteria.ExerciseTypes = new List <ExerciseType>();

            client1.GetExercisesAsync(ApplicationState.Current.SessionData.Token, criteria, pageInfo);
            client1.GetExercisesCompleted -= operationCompleted;
            client1.GetExercisesCompleted += operationCompleted;
        }
示例#14
0
        private void Find()
        {
            ExerciseList.Clear();

            var exerciseSearchCriteria = new ExerciseSearchCriteria();

            exerciseSearchCriteria.Title = FindText;

            foreach (var exercise in exerciseService.Find(exerciseSearchCriteria))
            {
                ExerciseList.Add(Mapper.Map <ExerciseListItemModel>(exercise));
            }
        }
示例#15
0
        public PagedResult <ExerciseDTO> GetExercises(Token token, ExerciseSearchCriteria searchCriteria, PartialRetrievingInfo retrievingInfo)
        {
            BodyArchitect.Service.V2.InternalBodyArchitectService service = new V2.InternalBodyArchitectService(NHibernateContext.Current().Session);
            V2.Model.Token v2token = new V2.Model.Token(token.SessionId, token.Language);
            V2.Model.ExerciseSearchCriteria crit = new V2.Model.ExerciseSearchCriteria();
            V2.Model.PartialRetrievingInfo  nfo  = new V2.Model.PartialRetrievingInfo();
            crit = Mapper.Map <V2.Model.ExerciseSearchCriteria>(searchCriteria);
            nfo  = Mapper.Map <V2.Model.PartialRetrievingInfo>(retrievingInfo);

            var res = service.GetExercises(v2token, crit, nfo);
            var ret = Mapper.Map <V2.Model.PagedResult <V2.Model.ExerciseDTO>, PagedResult <ExerciseDTO> >(res);

            return(ret);
        }
        public void TestPublishWorkoutPlan_CrossProfile()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.UserId = profiles[1].Id;

            var         profile = (ProfileDTO)profiles[1].Tag;
            SessionData data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            var         plan    = (WorkoutPlanDTO)workoutPlans["test1-2"].Tag;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                Service.PublishWorkoutPlan(data.Token, plan);
            });
        }
示例#17
0
        public void TestGetExercises_SortOrder_Rating()
        {
            RatingUserValue rating = new RatingUserValue();

            rating.RatedObjectId = exercises["t05"].GlobalId;
            rating.ProfileId     = profiles[0].Id;
            rating.Rating        = 5;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t02"].GlobalId;
            rating.ProfileId     = profiles[1].Id;
            rating.Rating        = 5;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t04"].GlobalId;
            rating.ProfileId     = profiles[1].Id;
            rating.Rating        = 3;
            insertToDatabase(rating);

            rating = new RatingUserValue();
            rating.RatedObjectId = exercises["t01"].GlobalId;
            rating.ProfileId     = profiles[0].Id;
            rating.Rating        = 1;
            insertToDatabase(rating);

            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.SortOrder = WorkoutPlanSearchOrder.HighestRating;

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = SecurityManager.CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;
            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });
            Assert.AreEqual("t05", result.Items[0].Shortcut);
            Assert.AreEqual("t02", result.Items[1].Shortcut);
            Assert.AreEqual("t04", result.Items[2].Shortcut);
            Assert.AreEqual("t01", result.Items[3].Shortcut);
        }
        public void TestPublishWorkoutPlan_NotPublishedExercises()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.UserId = profiles[1].Id;

            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = SecurityManager.CreateNewSession(profile, ClientInformation);
            var         plan    = (WorkoutPlanDTO)workoutPlans["test1-2"].Tag;

            Assert.AreEqual(BodyArchitect.Service.Model.PublishStatus.Private, plan.Status);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                Service.PublishWorkoutPlan(data.Token, plan);
            });
        }
        public void ExerciseRepository_Find_Exercise_With_DateModified_On_Or_After_ToDateModified()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-exercises.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IExerciseSearchCriteria crit = new ExerciseSearchCriteria
                {
                    FromDateModified = new DateTime(2017, 6, 1)
                };

                var exercises = uow.Exercises.Find(crit);
                Assert.That(exercises.SingleOrDefault, Is.Not.Null);
                Assert.That(exercises.SingleOrDefault().Title == "Green Exercise 2");
            }
        }
        public void ExerciseRepository_Find_Exercise_With_Specific_Title_Gets_Applicable_Recs()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-exercises.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IExerciseSearchCriteria crit = new ExerciseSearchCriteria
                {
                    Title = "reen exercis"
                };

                var exercises = uow.Exercises.Find(crit);
                Assert.That(exercises.Where(ex => ex.Title == "Green Exercise").SingleOrDefault(), Is.Not.Null);
                Assert.That(exercises.Where(ex => ex.Title == "Green Exercise 1").SingleOrDefault(), Is.Not.Null);
                Assert.That(exercises.Where(ex => ex.Title == "Green Exercise 2").SingleOrDefault(), Is.Not.Null);
            }
        }
        public void ExerciseRepository_Find_Exercise_With_DateCreated_After_FromDateCreated_But_After_ToDateCreated()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-exercises.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IExerciseSearchCriteria crit = new ExerciseSearchCriteria
                {
                    FromDateCreated = new DateTime(2015, 11, 25),
                    ToDateCreated   = new DateTime(2016, 2, 2)
                };

                var exercises = uow.Exercises.Find(crit);
                Assert.That(exercises.Where(ex => ex.Title == "Blue Exercise").SingleOrDefault(), Is.Not.Null);
                Assert.That(exercises.Where(ex => ex.Title == "Orange Exercise").SingleOrDefault(), Is.Not.Null);
            }
        }
示例#22
0
        public void All()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;

            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                result = Service.GetExercises(data.Token, criteria, pageInfo);
            });

            assertExercisesListPack(result, new[] { "t01", "t02", "t03", "t11", "t12", "t21", "t22" });
        }
        public void ExerciseRepository_Find_Exercise_With_DateCreated_Before_ToDateCreated()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-exercises.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IExerciseSearchCriteria crit = new ExerciseSearchCriteria
                {
                    ToDateCreated = new DateTime(2015, 5, 2)
                };

                var exercises = uow.Exercises.Find(crit);
                Assert.That(exercises.Count(), Is.EqualTo(2));

                Assert.That(exercises.Where(ex => ex.Title == "Yellow Exercise").SingleOrDefault(), Is.Not.Null);
                Assert.That(exercises.Where(ex => ex.Title == "Green Exercise").SingleOrDefault(), Is.Not.Null);
            }
        }
示例#24
0
        public void Fill(ProfileInformationDTO user, bool isActive)
        {
            if (user != null)
            {
                if (isActive && (!filled || currentUser == null || currentUser.User.Id != user.User.Id))
                {
                    filled = true;
                    ExerciseSearchCriteria criteria = ExerciseSearchCriteria.CreateAllCriteria();
                    criteria.UserId = user.User.Id;
                    usrExercisesView1.Fill(criteria);
                }
            }
            else
            {
                usrExercisesView1.ClearContent();
            }

            currentUser = user;
        }
示例#25
0
        public void MineAndFavorites_ForCurrentUser()
        {
            var criteria = ExerciseSearchCriteria.CreateAllCriteria();

            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.Mine);
            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.Favorites);
            var                   profile  = (ProfileDTO)profiles[0].Tag;
            SessionData           data     = CreateNewSession(profile, ClientInformation);
            PartialRetrievingInfo pageInfo = new PartialRetrievingInfo();

            pageInfo.PageSize = 50;

            PagedResult <ExerciseDTO> result = null;

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                result = service.GetExercises(data.Token, criteria, pageInfo);
            });

            assertExercisesListPack(result, new[] { "t11", "t12", "t22" });
        }
示例#26
0
        private void doSearch()
        {
            ClearContent();
            pagerInfo = new PartialRetrievingInfo();

            criteria = new ExerciseSearchCriteria();
            //criteria = ExerciseSearchCriteria.CreateAllCriteria();
            criteria.SearchGroups.Add(ExerciseSearchCriteriaGroup.PendingPublish);

            foreach (CheckedListBoxItem value in cmbTypes.Properties.Items)
            {
                if (value.CheckState == CheckState.Checked)
                {
                    criteria.ExerciseTypes.Add((ExerciseType)value.Value);
                }
            }

            criteria.SortOrder = (WorkoutPlanSearchOrder)cmbSortOrder.SelectedIndex;

            fillPage(0);
        }
示例#27
0
        protected override void BeforeSearch(object param = null)
        {
            criteria = ExerciseSearchCriteria.CreateAllCriteria();

            foreach (var value in exerciseTypes)
            {
                if (value.IsChecked)
                {
                    criteria.ExerciseTypes.Add(value.Value);
                }
            }
            foreach (var value in SearchGroups)
            {
                if (value.IsChecked)
                {
                    criteria.SearchGroups.Add(value.Value);
                }
            }

            criteria.Name = ExerciseName;

            criteria.SortOrder     = SelectedOrder;
            criteria.SortAscending = SortAscending;
        }
示例#28
0
        protected override PagedResult <ExerciseDTO> GetItemsMethod(PartialRetrievingInfo pageInfo)
        {
            ExerciseSearchCriteria search = ExerciseSearchCriteria.CreatePersonalCriteria();

            return(ServiceManager.GetExercises(search, pageInfo));
        }
示例#29
0
        public PagedResult <ExerciseDTO> GetExercises(ExerciseSearchCriteria searchCriteria, PartialRetrievingInfo retrievingInfo)
        {
            Log.WriteWarning("GetExercises:Username={0},Search-UserId:{1},SearchGroups:{2}", SecurityInfo.SessionData.Profile.UserName, searchCriteria.UserId, searchCriteria.SearchGroups.Count);
            var session = Session;

            //Profile _profile = null;
            Exercise _exercise = null;

            using (var transactionScope = new TransactionManager(true))
            {
                var myProfile = session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                if (searchCriteria.UserId.HasValue)
                {
                    myProfile = session.Load <Profile>(searchCriteria.UserId.Value);
                }

                var ids = myProfile.FavoriteExercises.Select(x => x.GlobalId).ToList();

                var queryExercises = session.QueryOver <Exercise>(() => _exercise).Where(x => !x.IsDeleted);

                if (searchCriteria.ExerciseTypes.Count > 0)
                {
                    var langOr = Restrictions.Disjunction();
                    foreach (var lang in searchCriteria.ExerciseTypes)
                    {
                        langOr.Add <Exercise>(x => x.ExerciseType == (ExerciseType)lang);
                    }
                    queryExercises = queryExercises.And(langOr);
                }

                if (!string.IsNullOrEmpty(searchCriteria.Name))
                {
                    queryExercises = queryExercises.Where(Restrictions.InsensitiveLike("Name", searchCriteria.Name + "%"));
                }


                if (searchCriteria.SearchGroups.Count > 0)
                {
                    Disjunction mainOr = Restrictions.Disjunction();
                    if (searchCriteria.SearchGroups.IndexOf(ExerciseSearchCriteriaGroup.Global) > -1)
                    {
                        Log.WriteVerbose("Search: global");
                        mainOr.Add <Exercise>(dto => dto.Profile == null);
                    }
                    if (searchCriteria.SearchGroups.IndexOf(ExerciseSearchCriteriaGroup.Mine) > -1)
                    {
                        Log.WriteVerbose("Search: mine");
                        mainOr.Add <Exercise>(dto => dto.Profile == myProfile);
                    }
                    if (searchCriteria.SearchGroups.IndexOf(ExerciseSearchCriteriaGroup.Other) > -1)
                    {
                        Log.WriteVerbose("Search: other");
                        mainOr.Add <Exercise>(dto => dto.Profile != null && dto.Profile != myProfile);
                    }
                    if (searchCriteria.SearchGroups.IndexOf(ExerciseSearchCriteriaGroup.Favorites) > -1)
                    {
                        if (ids.Count > 0)
                        {
                            mainOr.Add <BodyArchitect.Model.TrainingPlan>(x => x.GlobalId.IsIn((ICollection)ids));
                        }
                    }
                    queryExercises = queryExercises.Where(mainOr);
                }

                //if (searchCriteria.UserId.HasValue)
                //{
                //    queryExercises = queryExercises.Where(dto => dto.Profile == myProfile);
                //}
                queryExercises = queryExercises.ApplySorting(searchCriteria.SortOrder, searchCriteria.SortAscending);

                var res1 = (from rv in session.Query <RatingUserValue>()
                            from tp in session.Query <Exercise>()
                            where tp.GlobalId == rv.RatedObjectId &&
                            rv.ProfileId == SecurityInfo.SessionData.Profile.GlobalId
                            select rv).ToDictionary(t => t.RatedObjectId);

                var listPack = queryExercises.ToPagedResults <ExerciseDTO, Exercise>(retrievingInfo, null,
                                                                                     delegate(IEnumerable <Exercise> list)
                {
                    var output = new List <ExerciseDTO>();
                    foreach (var planDto in list)
                    {
                        var tmp = planDto.Map <ExerciseDTO>();
                        if (res1.ContainsKey(planDto.GlobalId))
                        {
                            tmp.UserRating       = res1[planDto.GlobalId].Rating;
                            tmp.UserShortComment = res1[planDto.GlobalId].ShortComment;
                        }
                        output.Add(tmp);
                    }
                    return(output.ToArray());
                });
                transactionScope.CommitTransaction();
                return(listPack);
            }
        }
 public PagedResult <ExerciseDTO> GetExercises(Token token, ExerciseSearchCriteria searchCriteria, PartialRetrievingInfo retrievingInfo)
 {
     return(exceptionHandling(token, () => InternalService.GetExercises(token, searchCriteria, retrievingInfo)));
 }