Пример #1
0
        /// <summary>
        /// Get All available training Sessions for a user
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IEnumerable <PictureTrainingSessionViewModel> GetAllAvailable(int userId)
        {
            try
            {
                var lstAllByUsers = this.GetAllByUserId(userId);

                //Get all ids of the sessions
                IEnumerable <int> lstAllTrainingSessionsIds = TrainingSessionRepository.GetAll()
                                                              .Where(t => t.Date > DateTime.Now)
                                                              .Select(t => t.Id);

                //Get all ids and dates of the sessions on which the user is registered
                IEnumerable <int> lstAllTrainingSessionsIdsByUser = lstAllByUsers
                                                                    .Select(t => t.Id);

                IEnumerable <DateTime> lstAllTrainingSessionsDatesByUser = lstAllByUsers
                                                                           .Select(t => t.Date);

                //Get all ids of the available sessions for the user
                IEnumerable <int> ids = lstAllTrainingSessionsIds.Except(lstAllTrainingSessionsIdsByUser);

                //Returns sessions available for the user
                var lstAvailableSession = TrainingSessionRepository.GetAll()
                                          .Where(t => ids.Any(i => i == t.Id))
                                          .Where(t => !lstAllTrainingSessionsDatesByUser.Any(d => d == t.Date));

                List <PictureTrainingSessionViewModel> results = new List <PictureTrainingSessionViewModel>();

                //Foreach availableSession add the coorect picture
                foreach (var item in lstAvailableSession)
                {
                    // retrieve the trainingSession
                    TrainingSession t = TrainingSessionRepository.GetById(item.Id);

                    var pictureTraining = "";

                    if (item.AvailableSeat == 0)
                    {
                        pictureTraining = "unavailable.png";
                    }
                    else if (item.AvailableSeat < 3)
                    {
                        pictureTraining = "warning.png";
                    }

                    results.Add(new PictureTrainingSessionViewModel(t, pictureTraining)
                    {
                        Id              = t.Id,
                        AvailableSeat   = t.AvailableSeat,
                        Date            = t.Date,
                        PictureTraining = pictureTraining
                    });
                }
                return(results.OrderByDescending(r => r.Date));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public List <float> GetActivityInfoSums(int userId, DateTime now,
                                                PeriodTrainingDataStrategy periodStrategy,
                                                List <Types.TrainingType> activitylist)
        {
            var list = TrainingSessionRepository.GetAsQueryable <TrainingSession>().ToList()
                       .Where(
                d =>
                d.UserId == userId && periodStrategy.IsInLowerTimeBound(d))
                       .ToList();

            var timeSpans = periodStrategy.GetTimeSpans(now, periodStrategy.NumberOfRecords);

            var values = new List <float>();

            foreach (var timespan in timeSpans)
            {
                var allSessionInTimespan = AllSessionInTimespan(list, timespan);

                var activityCount = allSessionInTimespan.Sum(s => activitylist.Contains(s.TrainingEnumTypeId) ? 1 : 0);

                values.Add(activityCount);
            }

            return(values);
        }
Пример #3
0
        /// <summary>
        /// Get all results of the training Session of a user (session passed)
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IEnumerable <ResultTrainingSessionViewModel> GetResultsByUserId(int userId)
        {
            try
            {
                //Get All User Training
                IEnumerable <UserTrainingSession> lstUT = UserTrainingSessionRepository.GetAll().Where(ut => ut.UserId == userId);

                List <ResultTrainingSessionViewModel> results = new List <ResultTrainingSessionViewModel>();
                foreach (var item in lstUT)
                {
                    TrainingSession t = TrainingSessionRepository.GetById(item.TrainingSessionId);
                    if (t.Date < DateTime.Now)
                    {
                        results.Add(new ResultTrainingSessionViewModel(t, item.Result)
                        {
                            AvailableSeat = t.AvailableSeat, Date = t.Date, Id = t.Id, Result = item.Result
                        });
                    }
                }
                return(results.OrderByDescending(t => t.Date));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public List <TrainingDataTainingDetailsModel.TrainingDataValue> GetEffortSummary(int userId, DateTime now,
                                                                                         PeriodTrainingDataStrategy periodTrainingDataStrategy, NumericCalculationTypeStrategy numericCalculationTypeStrategy, int numberOfRecordsToDisplay)
        {
            var sessions = TrainingSessionRepository.GetAsQueryable <TrainingSession>().ToList()
                           .Where(d => d.UserId == userId && periodTrainingDataStrategy.IsInLowerTimeBound(d))
                           .ToList();

            return(GetEffortSummary(now, periodTrainingDataStrategy, numericCalculationTypeStrategy, numberOfRecordsToDisplay, sessions));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="trainingSession"></param>
        /// <returns></returns>
        public bool SubmitTrainingData(int userId, TrainingSession trainingSession)
        {
            if (TrainingSessionRepository == null)
            {
                TrainingSessionRepository = new SqlDataAccess.Entities.View.TrainingSessionsRepository();
            }

            if (TrainingSessionDataRepository == null)
            {
                TrainingSessionDataRepository = new NoSqlDataAccess.Entities.View.TrainingSessionMeasurmentDataRepository();
            }

            Guid uniqueId = Guid.NewGuid();

            GenericError error;

            trainingSession.UserId = userId;

            try
            {
                trainingSession.MeasurementInfo.TrainingSessionId = uniqueId;

                TrainingSessionDataRepository.InsertEntity(out error, trainingSession.MeasurementInfo);
            }
            catch (Exception e)
            {
                error = new GenericError()
                {
                    ErrorDesc = e.Message
                };
            }

            if (error == null)
            {
                try
                {
                    // SAVE TO SQL SERVER

                    trainingSession.TrainingSessionId = uniqueId;

                    TrainingSessionRepository.InsertEntity(out error, trainingSession);
                }
                catch (Exception e)
                {
                    error = new GenericError()
                    {
                        ErrorDesc = e.Message
                    };
                }
            }

            return(error == null);
        }
        public IList <TrainingDataTainingDetailsModel.TrainingDataValue> GetMeasurementInfoSummary(int userId, DateTime now,
                                                                                                   PeriodTrainingDataStrategy periodTrainingDataStrategy,
                                                                                                   NumericCalculationTypeStrategy numericCalculationTypeStrategy,
                                                                                                   int numberOfRecordsToDisplay, Func <TrainingSessionMeasurmentData,
                                                                                                                                       IList <DecimalData> > getter)
        {
            var sessions = TrainingSessionRepository.GetAsQueryable <TrainingSession>().ToList()
                           .Where(d => d.UserId == userId && periodTrainingDataStrategy.IsInLowerTimeBound(d))
                           .ToList();

            return(GetMeasurementInfoSummary(now, periodTrainingDataStrategy, numericCalculationTypeStrategy, numberOfRecordsToDisplay, getter, sessions));
        }
        public Dictionary <Types.TrainingType, List <TrainingDataTainingDetailsModel.TrainingDataValue> > GetActivityInfoSummary(int userId, DateTime now,
                                                                                                                                 int numberOfRecordsToDisplay,
                                                                                                                                 PeriodTrainingDataStrategy periodTrainingDataStrategy,
                                                                                                                                 NumericCalculationTypeStrategy numericCalculationTypeStrategy,
                                                                                                                                 IList <Types.TrainingType> selectedActivityTypes)
        {
            var sessions = TrainingSessionRepository.GetAsQueryable <TrainingSession>().ToList()
                           .Where(
                d => d.UserId == userId && periodTrainingDataStrategy.IsInLowerTimeBound(d)).ToList();


            return(GetActivityInfoSummary(now, numberOfRecordsToDisplay, periodTrainingDataStrategy, numericCalculationTypeStrategy, selectedActivityTypes, sessions));
        }
        public TrainingDataTainingDetailsModel GetTrainingDataForPeriod(int userId,
                                                                        int period,
                                                                        DateTime now, TrainingDataSettings
                                                                        settings)
        {
            var trainingDataTainingDetailsModel = new TrainingDataTainingDetailsModel();

            Types.MeasurementInfoTypes type;
            Enum.TryParse(settings.MeasurmentType.ToString(), out type);
            var periodTrainingDataStrategy     = DataUtils.GetPeriodTrainingDataStrategy(userId, period);
            var numericCalculationTypeStrategy = _calculationStrategies[settings.MesurmentInfoCalculationType];

            var sessions = TrainingSessionRepository.GetAsQueryable <TrainingSession>().ToList()
                           .Where(d => d.UserId == userId && periodTrainingDataStrategy.IsInLowerTimeBound(d))
                           .ToList();

            var measurements = GetMeasurementInfoSummary(now, periodTrainingDataStrategy, numericCalculationTypeStrategy, periodTrainingDataStrategy.NumberOfRecords,
                                                         DataUtils.MeasurmentPropertySelectors[type], sessions);

            var activities = GetActivityInfoSummary(now, periodTrainingDataStrategy.NumberOfRecords,
                                                    periodTrainingDataStrategy,
                                                    numericCalculationTypeStrategy,
                                                    settings.SelectedActivitiesTypes.Cast <Types.TrainingType>().ToList(), sessions);

            var efforts = GetEffortSummary(now, periodTrainingDataStrategy,
                                           numericCalculationTypeStrategy,
                                           periodTrainingDataStrategy.NumberOfRecords, sessions);

            // NormalizeAllArrayValues(activities, measurements, efforts);
            if (measurements != null)
            {
                trainingDataTainingDetailsModel.Measurments = measurements.ToList();
            }
            if (activities != null)
            {
                trainingDataTainingDetailsModel.Activities = AddaptActivityDataFillOnlyOne(activities, periodTrainingDataStrategy.NumberOfRecords);
            }
            if (efforts != null)
            {
                trainingDataTainingDetailsModel.Efort = efforts.ToList();
            }

            trainingDataTainingDetailsModel.Activities.Reverse();
            trainingDataTainingDetailsModel.Efort.Reverse();
            trainingDataTainingDetailsModel.Measurments.Reverse();


            return(trainingDataTainingDetailsModel);
        }
Пример #9
0
 /// <summary>
 /// Get all training Sessions on which a user is registered
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public IEnumerable <TrainingSession> GetAllByUserId(int userId)
 {
     try
     {
         //Get All User Training
         IEnumerable <UserTrainingSession> lstUT = UserTrainingSessionRepository.GetAll();
         //Get All Training
         IEnumerable <TrainingSession> lstT = TrainingSessionRepository.GetAll();
         //return gettAllbyuserid
         List <int> ids = lstUT.Where(t => t.UserId == userId).Select(t => t.TrainingSessionId).ToList();
         return(lstT.Where(t => ids.Contains(t.Id)).Where(t => t.Date >= DateTime.Now).OrderByDescending(s => s.Date).ToList());
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Пример #10
0
 /// <summary>
 /// Update a training session
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public TrainingSession Update(TrainingSession entity)
 {
     return(TrainingSessionRepository.Update(entity));
 }
Пример #11
0
 /// <summary>
 /// Get a training session
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public TrainingSession GetByid(int id)
 {
     return(TrainingSessionRepository.GetById(id));
 }
Пример #12
0
 /// <summary>
 /// Get all trainings sessions
 /// </summary>
 /// <returns></returns>
 public IEnumerable <TrainingSession> GetAll()
 {
     return(TrainingSessionRepository.GetAll());
 }