示例#1
0
        public PagedResult <ChampionshipDTO> GetChampionships(Token token, GetChampionshipsCriteria criteria, PartialRetrievingInfo retrievingInfo)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new ChampionshipService(Session, securityInfo, Configuration);

            return(service.GetChampionships(criteria, retrievingInfo));
        }
        public void OtherProfile()
        {
            var championShip1 = CreateChampionship(profiles[0], "name1");
            var championShip2 = CreateChampionship(profiles[0], "name2");
            var championShip3 = CreateChampionship(profiles[1], "name3");

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

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var criteria = new GetChampionshipsCriteria();
                var res      = service.GetChampionships(data.Token, criteria, new PartialRetrievingInfo());

                Assert.AreEqual(2, res.AllItemsCount);
                Assert.AreEqual(1, res.Items.Where(x => x.GlobalId == championShip1.GlobalId).Count());
                Assert.AreEqual(1, res.Items.Where(x => x.GlobalId == championShip2.GlobalId).Count());
            });
        }
示例#3
0
        public PagedResult <ChampionshipDTO> GetChampionships(GetChampionshipsCriteria criteria, PartialRetrievingInfo retrievingInfo)
        {
            if (!SecurityInfo.Licence.IsInstructor)
            {
                throw new LicenceException("This feature is allowed for Instructor account");
            }

            using (var trans = Session.BeginGetTransaction())
            {
                var myProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var idQuery   = Session.QueryOver <Championship>().Where(x => x.Profile == myProfile);
                var query     = Session.QueryOver <Championship>()
                                .Fetch(x => x.Groups).Eager
                                //.Fetch(x => x.Reservations).Eager
                                //.Fetch(x => x.Customers).Eager
                                .Fetch(x => x.Entries).Eager
                                .Fetch(x => x.Entries.First().Exercise).Eager;

                if (criteria.ChampionshipId.HasValue)
                {
                    idQuery = idQuery.Where(x => x.GlobalId == criteria.ChampionshipId.Value);
                }

                idQuery.ApplyPaging(retrievingInfo);
                if (criteria.SortAscending)
                {
                    idQuery = idQuery.OrderBy(x => x.StartTime).Asc;
                    query   = query.OrderBy(x => x.StartTime).Asc;
                }
                else
                {
                    idQuery = idQuery.OrderBy(x => x.StartTime).Desc;
                    query   = query.OrderBy(x => x.StartTime).Desc;
                }

                var res = query.ToExPagedResults <ChampionshipDTO, Championship>(retrievingInfo, idQuery);
                trans.Commit();

                return(res);
            }
        }
        public void PagedResults()
        {
            CreateChampionship(profiles[0], "name1");
            CreateChampionship(profiles[0], "name2");
            CreateChampionship(profiles[0], "name3");

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

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var criteria = new GetChampionshipsCriteria();
                var res      = service.GetChampionships(data.Token, criteria, new PartialRetrievingInfo()
                {
                    PageSize = 2
                });

                Assert.AreEqual(3, res.AllItemsCount);
                Assert.AreEqual(2, res.Items.Count);
            });
        }
 public PagedResult <ChampionshipDTO> GetChampionships(Token token, GetChampionshipsCriteria criteria, PartialRetrievingInfo retrievingInfo)
 {
     return(exceptionHandling(token, () => InternalService.GetChampionships(token, criteria, retrievingInfo)));
 }
        public void DistinctResults()
        {
            var customer1 = CreateCustomer("cust", profiles[0]);
            var customer2 = CreateCustomer("cust1", profiles[0]);


            var championShip1 = CreateChampionship(profiles[0], "name1");

            var benchPress = CreateExercise(Session, null, "BenchPress", "H", globalId: new Guid("ece5dfd7-f995-45ae-bb34-067f26c4f7b4"));

            CreateReservation(championShip1, customer1);
            CreateReservation(championShip1, customer2);
            var champCust1 = new ChampionshipCustomer();

            champCust1.Customer = customer1;
            championShip1.Customers.Add(champCust1);
            var champCust2 = new ChampionshipCustomer();

            champCust2.Customer = customer2;
            championShip1.Customers.Add(champCust2);
            var champCust3 = new ChampionshipCustomer();

            champCust3.Customer = customer1;
            championShip1.Customers.Add(champCust3);
            var champCust4 = new ChampionshipCustomer();

            champCust4.Customer = customer2;
            championShip1.Customers.Add(champCust4);
            var champGroup = new ChampionshipGroup();

            champGroup.Name  = "gr1";
            champCust1.Group = champGroup;
            champCust2.Group = champGroup;
            champGroup.Members.Add(champCust1);
            champGroup.Members.Add(champCust2);
            championShip1.Groups.Add(champGroup);
            var champGroup1 = new ChampionshipGroup();

            champGroup1.Name = "gr2";
            champCust3.Group = champGroup1;
            champCust4.Group = champGroup1;
            champGroup1.Members.Add(champCust3);
            champGroup1.Members.Add(champCust4);
            championShip1.Groups.Add(champGroup1);

            var entry = new ChampionshipEntry();

            entry.Customer = champCust1;
            entry.Exercise = benchPress;
            championShip1.Entries.Add(entry);
            var entry1 = new ChampionshipEntry();

            entry1.Customer = champCust2;
            entry1.Exercise = benchPress;
            championShip1.Entries.Add(entry1);
            var entry3 = new ChampionshipEntry();

            entry3.Customer = champCust3;
            entry3.Exercise = benchPress;
            championShip1.Entries.Add(entry3);
            insertToDatabase(championShip1);

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

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var criteria = new GetChampionshipsCriteria();
                var res      = service.GetChampionships(data.Token, criteria, new PartialRetrievingInfo());

                Assert.AreEqual(1, res.AllItemsCount);
                Assert.AreEqual(1, res.Items.Where(x => x.GlobalId == championShip1.GlobalId).Count());

                Assert.AreEqual(3, res.Items[0].Entries.Count);
                Assert.AreEqual(2, res.Items[0].Groups.Count);
                Assert.AreEqual(4, res.Items[0].Customers.Count);
                Assert.AreEqual(2, res.Items[0].Groups[0].Members.Count);
                Assert.AreEqual(2, res.Items[0].Groups[1].Members.Count);
            });
        }
示例#7
0
 public static PagedResult <ChampionshipDTO> GetChampionships(GetChampionshipsCriteria criteria, PartialRetrievingInfo retrievingInfo)
 {
     return(exceptionHandling(() => Instance.GetChampionships(Token, criteria, retrievingInfo)));
 }