public void ForCustomers_UserWithSmallStatistics()
        {
            var customer  = CreateCustomer("cust", profiles[0]);
            var customer1 = CreateCustomer("cust1", profiles[0]);
            var customer2 = CreateCustomer("cust1", profiles[1]);

            profiles[0].Statistics.StrengthTrainingEntriesCount = 0;
            profiles[0].Statistics.TrainingDaysCount            = 0;
            insertToDatabase(profiles[0].Statistics);


            CreateExerciseRecord(exercises[1], profiles[0], new Tuple <int, decimal>(5, 65), DateTime.UtcNow.AddDays(-15).Date, customer);
            CreateExerciseRecord(exercises[0], profiles[0], new Tuple <int, decimal>(11, 40), DateTime.UtcNow.AddDays(-10).Date, customer);
            CreateExerciseRecord(exercises[0], profiles[0], new Tuple <int, decimal>(3, 40), DateTime.UtcNow.AddDays(-11).Date, customer1);

            CreateExerciseRecord(exercises[0], profiles[1], new Tuple <int, decimal>(5, 67), DateTime.UtcNow.AddDays(-4).Date, customer2);

            CreateExerciseRecord(exercises[0], profiles[1], new Tuple <int, decimal>(3, 61), DateTime.UtcNow.AddDays(-5).Date);

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

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new ExerciseRecordsParams();
                param.ExerciseId = exercises[0].GlobalId;
                param.Mode       = RecordMode.Customer;
                var list         = service.ReportExerciseRecords(data.Token, param, new PartialRetrievingInfo());

                assert(list, new Tuple <Customer, decimal, DateTime>(customer, 40, DateTime.UtcNow.AddDays(-10).Date),
                       new Tuple <Customer, decimal, DateTime>(customer1, 40, DateTime.UtcNow.AddDays(-11).Date));
            });
        }
        public void ForUsers()
        {
            CreateExerciseRecord(exercises[1], profiles[0], new Tuple <int, decimal>(5, 65), DateTime.UtcNow.AddDays(-15).Date);
            CreateExerciseRecord(exercises[0], profiles[0], new Tuple <int, decimal>(11, 40), DateTime.UtcNow.AddDays(-10).Date);
            CreateExerciseRecord(exercises[0], profiles[2], new Tuple <int, decimal>(3, 40), DateTime.UtcNow.AddDays(-11).Date);

            CreateExerciseRecord(exercises[0], profiles[1], new Tuple <int, decimal>(5, 67), DateTime.UtcNow.AddDays(-4).Date);

            CreateExerciseRecord(exercises[0], profiles[3], new Tuple <int, decimal>(3, 61), DateTime.UtcNow.AddDays(-5).Date);

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

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new ExerciseRecordsParams();
                param.ExerciseId = exercises[0].GlobalId;
                var list         = service.ReportExerciseRecords(data.Token, param, new PartialRetrievingInfo());

                assert(list, new Tuple <Profile, decimal, DateTime>(profiles[1], 67, DateTime.UtcNow.AddDays(-4).Date),
                       new Tuple <Profile, decimal, DateTime>(profiles[3], 61, DateTime.UtcNow.AddDays(-5).Date),
                       new Tuple <Profile, decimal, DateTime>(profiles[0], 40, DateTime.UtcNow.AddDays(-10).Date),
                       new Tuple <Profile, decimal, DateTime>(profiles[2], 40, DateTime.UtcNow.AddDays(-11).Date));
            });
        }
        public void ForUsers_SkipUserWithSmallStatistics()
        {
            profiles[1].Statistics.StrengthTrainingEntriesCount = 0;
            profiles[1].Statistics.TrainingDaysCount            = 0;
            insertToDatabase(profiles[1].Statistics);
            CreateExerciseRecord(exercises[1], profiles[0], new Tuple <int, decimal>(5, 65), DateTime.UtcNow.AddDays(-15).Date);
            CreateExerciseRecord(exercises[0], profiles[0], new Tuple <int, decimal>(11, 40), DateTime.UtcNow.AddDays(-10).Date);
            CreateExerciseRecord(exercises[0], profiles[2], new Tuple <int, decimal>(3, 40), DateTime.UtcNow.AddDays(-11).Date);

            CreateExerciseRecord(exercises[0], profiles[1], new Tuple <int, decimal>(5, 67), DateTime.UtcNow.AddDays(-4).Date);

            CreateExerciseRecord(exercises[0], profiles[3], new Tuple <int, decimal>(3, 61), DateTime.UtcNow.AddDays(-5).Date);


            var         test    = Session.QueryOver <Profile>().Fetch(x => x.Statistics).Eager.List();
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new ExerciseRecordsParams();
                param.ExerciseId = exercises[0].GlobalId;
                var list         = service.ReportExerciseRecords(data.Token, param, new PartialRetrievingInfo());

                assert(list, new Tuple <Profile, decimal, DateTime>(profiles[3], 61, DateTime.UtcNow.AddDays(-5).Date),
                       new Tuple <Profile, decimal, DateTime>(profiles[0], 40, DateTime.UtcNow.AddDays(-10).Date),
                       new Tuple <Profile, decimal, DateTime>(profiles[2], 40, DateTime.UtcNow.AddDays(-11).Date));
            });
        }
        void fillPage(int pageIndex)
        {
            if (tokenSource != null)
            {
                tokenSource.Cancel();
                tokenSource = null;
            }
            tokenSource = new CancellationTokenSource();
            progressIndicator.IsRunning = true;
            var recordsForUsers = RecordMode;

            Task.Factory.StartNew(delegate(object cancellationToken)
            {
                CancellationToken cancelToken = (CancellationToken)cancellationToken;
                PartialRetrievingInfo info    = new PartialRetrievingInfo();
                info.PageIndex   = pageIndex;
                var param        = new ExerciseRecordsParams();
                param.ExerciseId = exercise.GlobalId;
                param.Mode       = recordsForUsers;
                var result       = ServiceManager.ReportExerciseRecords(param, info);
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }
                lstRecords.Dispatcher.BeginInvoke(new Action(delegate
                {
                    buildPager(result.AllItemsCount, info.PageSize, pageIndex);
                    lstRecords.ItemsSource      = result.Items.Select(x => new ExerciseRecordViewModel(x, result, info.PageSize));
                    progressIndicator.IsRunning = false;
                }));
            }, tokenSource.Token, tokenSource.Token);
        }
Esempio n. 5
0
        public PagedResult <ExerciseRecordsReportResultItem> ReportExerciseRecords(ExerciseRecordsParams param, PartialRetrievingInfo pageInfo)
        {
            Profile profile = null;
            var     query   = Session.QueryOver <ExerciseProfileData>().JoinAlias(x => x.Profile, () => profile).Fetch(x => x.Exercise).Eager;

            var dbMyProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);


            //query = query.Where(x => day.Profile == dbProfile);
            //if (param.CustomerId.HasValue)
            //{
            //    Customer customer = Session.Get<Customer>(param.CustomerId.Value);
            //    if (customer.Profile != dbProfile)
            //    {
            //        throw new CrossProfileOperationException("This customer doesn't belong to your profile");
            //    }
            //    query = query.Where(x => day.Customer == customer);
            //}
            //else
            if (param.Mode == RecordMode.Customer)
            {
                query = query.Where(x => x.Customer != null && x.Profile == dbMyProfile);
            }
            else if (param.Mode == RecordMode.Friends)
            {
                var friendsIds = dbMyProfile.Friends.Select(x => x.GlobalId).ToList();
                var bigOr      = Restrictions.Disjunction();
                bigOr.Add(Restrictions.On <Profile>(x => profile.GlobalId).IsIn((ICollection)friendsIds));
                bigOr.Add(Restrictions.Where <Profile>(x => profile.GlobalId == dbMyProfile.GlobalId));
                query = query.Where(x => x.Customer == null).And(bigOr);
            }
            else
            {
                query = PublicRecordsQueryCriteria(query, profile);
            }
            query = query.Where(x => x.Exercise.GlobalId == param.ExerciseId);


            query = query.OrderBy(z => z.MaxWeight).Desc.ThenBy(x => x.Repetitions).Desc;

            var listPack = query.ToPagedResults <ExerciseRecordsReportResultItem, ExerciseProfileData>(pageInfo);

            return(listPack);
            //IEnumerable<object[]> queryEnumerable = null;
            //int count = 0;
            //if (pageInfo.PageSize > PartialRetrievingInfo.AllElementsPageSize)
            //{
            //    IFutureValue<int> rowCountQuery = Session.QueryOver<Profile>(() => test1).WithSubquery.WhereExists(
            //    rowCount.Where(x => user.GlobalId == test1.GlobalId)).ToRowCountQuery().FutureValue<int>();
            //    //IQueryOver<object[]> pagedResults = query.ApplyPaging(pageInfo);
            //    if (pageInfo.PageSize > PartialRetrievingInfo.AllElementsPageSize)
            //    {
            //        query = (IQueryOver<StrengthTrainingItem, StrengthTrainingItem>) query.Take(pageInfo.PageSize).Skip(pageInfo.PageIndex * pageInfo.PageSize);
            //    }

            //    queryEnumerable = query.Future<object[]>();
            //    count = rowCountQuery.Value;
            //}
            //else
            //{
            //    queryEnumerable = query.Future<object[]>();
            //    count = queryEnumerable.Count();
            //}
            //var test = queryEnumerable.ToList();

            //Session.QueryOver<Profile>().WhereRestrictionOn(a => a.GlobalId).IsIn(test.Select(x => ((Profile) x[1]).GlobalId).ToArray()).List();

            //var result = queryEnumerable.Select(x =>
            //    new ExerciseRecordsReportResultItem()
            //        {
            //            Weight = (decimal)x[0],
            //            StrengthTrainingItemId = (Guid)x[3],
            //            User = (x[1]).Map<UserDTO>(),
            //            CustomerId = x[2]!=null?((Customer)x[2]).GlobalId:(Guid?) null,
            //            DateTime = (DateTime)x[4],
            //            Repetitions = (int)(decimal)x[5]
            //        }).ToList();

            //return new PagedResult<ExerciseRecordsReportResultItem>(result,count, pageInfo.PageIndex);
        }
 public PagedResult <ExerciseRecordsReportResultItem> ReportExerciseRecords(Token token, ExerciseRecordsParams param, PartialRetrievingInfo pageInfo)
 {
     return(exceptionHandling(token, () => InternalService.ReportExerciseRecords(token, param, pageInfo)));
 }
Esempio n. 7
0
        public PagedResult <ExerciseRecordsReportResultItem> ReportExerciseRecords(Token token, ExerciseRecordsParams param, PartialRetrievingInfo pageInfo)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new ReportService(Session, securityInfo, Configuration);

            return(service.ReportExerciseRecords(param, pageInfo));
        }
Esempio n. 8
0
 public static PagedResult <ExerciseRecordsReportResultItem> ReportExerciseRecords(ExerciseRecordsParams param, PartialRetrievingInfo pageInfo)
 {
     return(exceptionHandling(() => Instance.ReportExerciseRecords(Token, param, pageInfo)));
 }