public void GetUserRating() { RatingUserValue rating = new RatingUserValue(); rating.RatedObjectId = definitions[0].GlobalId; rating.Rating = 2; rating.ProfileId = profiles[0].GlobalId; rating.VotedDate = DateTime.UtcNow; insertToDatabase(rating); rating = new RatingUserValue(); rating.RatedObjectId = definitions[0].GlobalId; rating.Rating = 5; rating.ProfileId = profiles[1].GlobalId; rating.VotedDate = DateTime.UtcNow; insertToDatabase(rating); var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); Assert.AreEqual(2, result.Items.Where(x => x.GlobalId == definitions[0].GlobalId).Single().UserRating); Assert.AreEqual(null, result.Items.Where(x => x.GlobalId == definitions[1].GlobalId).Single().UserRating); }
protected override PagedResult <SupplementCycleDefinitionDTO> GetItemsMethod(PartialRetrievingInfo pageInfo) { var param = new GetSupplementsCycleDefinitionsParam(); param.UserId = UserContext.Current.CurrentProfile.GlobalId; param.SearchGroups.Add(WorkoutPlanSearchCriteriaGroup.Mine); param.SearchGroups.Add(WorkoutPlanSearchCriteriaGroup.Favorites); return(ServiceManager.GetSupplementsCycleDefinitions(param, pageInfo)); }
public void Supplements_One() { var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { param.Supplements.Add(supplements[0].GlobalId); result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); assert(result, "def2", "def4"); }
public void PagedResults() { var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 2; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); Assert.AreEqual(definitions.Count, result.AllItemsCount); Assert.AreEqual(2, result.Items.Count); }
public void ForProfile_OtherProfile() { var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { param.UserId = profiles[1].GlobalId; param.SearchGroups.Add(WorkoutPlanSearchCriteriaGroup.Mine); result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); assert(result, "def6", "def4"); }
public void OnlyOneLanguage() { var param = new GetSupplementsCycleDefinitionsParam(); param.Languages.Add(Language.Languages[0].Shortcut); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); assert(result, "def1"); }
public void ForOneDifficult() { var param = new GetSupplementsCycleDefinitionsParam(); param.Difficults.Add(Service.V2.Model.TrainingPlans.TrainingPlanDifficult.Professional); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); assert(result, "def1"); }
public void Supplements_Two_And_ReturnsEmptyList() { var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { param.Supplements.Add(supplements[1].GlobalId); param.Supplements.Add(supplements[3].GlobalId); param.SupplementsListOperator = CriteriaOperator.And; result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); Assert.AreEqual(0, result.AllItemsCount); }
public void SortName_Asc() { var param = new GetSupplementsCycleDefinitionsParam(); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); PartialRetrievingInfo pageInfo = new PartialRetrievingInfo(); pageInfo.PageSize = 50; PagedResult <SupplementCycleDefinitionDTO> result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { param.SortAscending = true; param.SortOrder = SearchSortOrder.Name; result = service.GetSupplementsCycleDefinitions(data.Token, param, pageInfo); }); Assert.AreEqual("def1", result.Items[0].Name); Assert.AreEqual("def2", result.Items[1].Name); Assert.AreEqual("def3", result.Items[2].Name); Assert.AreEqual("def4", result.Items[3].Name); }
private static IQueryOver <SupplementCycleDefinition, SupplementCycleDefinition> getSupplementsCycleDefinitionsCriterias(GetSupplementsCycleDefinitionsParam param, Profile loggedProfile, List <Guid> ids, Profile myProfile, IQueryOver <SupplementCycleDefinition, SupplementCycleDefinition> queryCustomer) { SupplementCycleDosage dosage = null; SupplementCycleWeek week = null; queryCustomer = queryCustomer.JoinAlias(x => x.Weeks, () => week) .JoinAlias(x => x.Weeks.First().Dosages, () => dosage); if (param.LegalCriteria == CanBeIllegalCriteria.OnlyLegal) { queryCustomer = queryCustomer.Where(x => !x.CanBeIllegal); } else if (param.LegalCriteria == CanBeIllegalCriteria.OnlyIllegal) { queryCustomer = queryCustomer.Where(x => x.CanBeIllegal); } if (param.PlanId.HasValue) { queryCustomer = queryCustomer.Where(x => x.GlobalId == param.PlanId.Value); } if (param.Languages.Count > 0) { var langOr = Restrictions.Disjunction(); foreach (var lang in param.Languages) { langOr.Add <SupplementCycleDefinition>(x => x.Language == lang); } queryCustomer = queryCustomer.And(langOr); } if (param.Purposes.Count > 0) { var purposeOr = Restrictions.Disjunction(); foreach (var purpose in param.Purposes) { purposeOr.Add <SupplementCycleDefinition>(x => x.Purpose == (WorkoutPlanPurpose)purpose); } queryCustomer = queryCustomer.And(purposeOr); } if (param.Difficults.Count > 0) { var mainOr = Restrictions.Disjunction(); foreach (TrainingPlanDifficult diff in param.Difficults) { var tt = (BodyArchitect.Model.TrainingPlanDifficult)diff; mainOr.Add <SupplementCycleDefinition>(x => x.Difficult == tt); } queryCustomer = queryCustomer.And(mainOr); } if (param.Supplements.Count > 0) { Junction supplementsOperations = null; if (param.SupplementsListOperator == CriteriaOperator.Or) { supplementsOperations = Restrictions.Disjunction(); foreach (var supplementId in param.Supplements) { supplementsOperations.Add <SupplementCycleDefinition>(x => dosage.Supplement.GlobalId == supplementId); } } else { supplementsOperations = Restrictions.Conjunction(); foreach (var supplementId in param.Supplements) { var orderIdsCriteria = DetachedCriteria.For <SupplementCycleDosage>(); orderIdsCriteria.SetProjection(Projections.CountDistinct("GlobalId")) .Add(Restrictions.Where <SupplementCycleDosage>(x => x.Supplement.GlobalId == supplementId)) .Add(Restrictions.Where <SupplementCycleDosage>(x => x.Week.GlobalId == week.GlobalId)); supplementsOperations.Add(Subqueries.Lt(0, orderIdsCriteria)); //supplementsOperations.Add<SupplementCycleDosage>(x => dosage.Supplement.GlobalId == supplementId); } } queryCustomer = queryCustomer.And(supplementsOperations); } queryCustomer = queryCustomer.Where(x => x.Profile == loggedProfile || (x.Profile != loggedProfile && x.Status == PublishStatus.Published)); var groupOr = new Disjunction(); if (param.SearchGroups.Count > 0) { if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Mine) > -1) { groupOr.Add <BodyArchitect.Model.SupplementCycleDefinition>(x => x.Profile == myProfile); } if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Favorites) > -1) { if (myProfile.FavoriteSupplementCycleDefinitions.Count > 0) { groupOr.Add <BodyArchitect.Model.SupplementCycleDefinition>(x => x.GlobalId.IsIn((ICollection)ids)); } } if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Other) > -1) { var tmpAnd = Restrictions.Conjunction(); tmpAnd.Add <BodyArchitect.Model.SupplementCycleDefinition>( dto => dto.Profile != null && dto.Profile != myProfile); if (ids.Count > 0) { tmpAnd.Add(Restrictions.On <BodyArchitect.Model.SupplementCycleDefinition>(x => x.GlobalId).Not.IsIn((ICollection)ids)); } groupOr.Add(tmpAnd); } queryCustomer = queryCustomer.Where(groupOr); } return(queryCustomer); }
public PagedResult <SupplementCycleDefinitionDTO> GetSupplementsCycleDefinitions(GetSupplementsCycleDefinitionsParam param, PartialRetrievingInfo pageInfo) { Log.WriteWarning("GetSupplementsCycleDefinitions:Username={0}", SecurityInfo.SessionData.Profile.UserName); using (var transactionScope = Session.BeginGetTransaction()) { var myProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); var loggedProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); if (param.UserId.HasValue) { myProfile = Session.Load <Profile>(param.UserId.Value); } var ids = myProfile.FavoriteSupplementCycleDefinitions.Select(x => x.GlobalId).ToList(); var idsQuery = Session.QueryOver <SupplementCycleDefinition>(); idsQuery = getSupplementsCycleDefinitionsCriterias(param, loggedProfile, ids, myProfile, idsQuery); idsQuery = idsQuery.ApplySorting(param.SortOrder, param.SortAscending); var fetchQuery = Session.QueryOver <SupplementCycleDefinition>() .Fetch(x => x.Weeks).Eager .Fetch(x => x.Weeks.First()).Eager .Fetch(x => x.Weeks.First().Dosages).Eager .Fetch(x => ((SupplementCycleDosage)x.Weeks.First().Dosages.First()).Supplement).Eager .Fetch(x => x.Profile).Eager; fetchQuery = fetchQuery.ApplySorting(param.SortOrder, param.SortAscending); var res1 = (from rv in Session.Query <RatingUserValue>() from tp in Session.Query <SupplementCycleDefinition>() where tp.GlobalId == rv.RatedObjectId && rv.ProfileId == SecurityInfo.SessionData.Profile.GlobalId select rv).ToDictionary(t => t.RatedObjectId); var listPack = fetchQuery.ToExPagedResults (pageInfo, idsQuery, delegate(IEnumerable <SupplementCycleDefinition> list) { var output = new List <SupplementCycleDefinitionDTO>(); foreach (var planDto in list) { var tmp = planDto.Map <SupplementCycleDefinitionDTO>(); if (res1.ContainsKey(planDto.GlobalId)) { tmp.UserRating = res1[planDto.GlobalId].Rating; tmp.UserShortComment = res1[planDto.GlobalId].ShortComment; } output.Add(tmp); } return(output.ToArray()); }); transactionScope.Commit(); return(listPack); } }
protected override void BeforeSearch(object param = null) { criteria = new GetSupplementsCycleDefinitionsParam(); criteria.SortOrder = SelectedOrder; }
public PagedResult <SupplementCycleDefinitionDTO> GetSupplementsCycleDefinitions(Token token, GetSupplementsCycleDefinitionsParam param, PartialRetrievingInfo pageInfo) { return(exceptionHandling(token, () => InternalService.GetSupplementsCycleDefinitions(token, param, pageInfo))); }
public PagedResult <SupplementCycleDefinitionDTO> GetSupplementsCycleDefinitions(Token token, GetSupplementsCycleDefinitionsParam param, PartialRetrievingInfo pageInfo) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new SupplementsEngineService(Session, securityInfo, Configuration); return(service.GetSupplementsCycleDefinitions(param, pageInfo)); }