Ejemplo n.º 1
0
 /// <summary>
 /// lists all workouts
 /// </summary>
 /// <param name="publicOnly">indicates whether only public workouts are listet or non public workouts, aswell</param>
 /// <returns>List of workouts</returns>
 public IEnumerable<ml_WorkoutPlan> List(bool publicOnly, WorkoutSearchViewModel searchParam, out int workoutCount)
 {
     return List(-1, publicOnly, searchParam, out workoutCount);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// get list of workouts
        /// </summary>
        /// <param name="userID">ID of user whose workouts are listet. -1 for all users.</param>
        /// <param name="publicOnly">Indicates if only public workouts are listed or also non public ones.</param>
        /// <param name="searchParam">WorkoutSearchViewModel with the data from the filter form</param>
        /// <param name="workoutCount">out param. Gives the total number of workouts</param>
        /// <returns>List of WorkoutPlanModels</returns>
        private IEnumerable<ml_WorkoutPlan> List(int userID, bool publicOnly, WorkoutSearchViewModel searchParam, out int workoutCount)
        {
            workoutCount = (from p in _repo.GetAll()
                            where (userID == -1 || p.UserID == userID) &&
                                  p.Deleted == 0 &&
                                  (!publicOnly || p.Public == 1)
                            select p).Count();

            var result = from p in _repo.GetAll()
                         where (userID == -1 || p.UserID == userID) &&
                               p.Deleted == 0 &&
                               (!publicOnly || p.Public == 1)
                         select p;

            if (searchParam != null && !String.IsNullOrEmpty(searchParam.Keywords))
            {
                string[] keywords = searchParam.Keywords.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string keyword in keywords)
                {
                    string tmp = keyword;
                    result = result.Where(p => p.PlanName.Contains(keyword) || p.ml_User.userName.Contains(keyword));
                }
            }

            if (searchParam != null && searchParam.NumWorkouts > 0)
            {
                result = result.Where(p => p.NumWorkouts == searchParam.NumWorkouts);
            }

            result = result.OrderByDescending(p => p.CRDT);
            return result;
        }
Ejemplo n.º 3
0
        public ActionResult ListAll(WorkoutSearchViewModel model)
        {
            TempData["workoutSearchKeywords"] = model.Keywords;
            TempData["workoutSearchNumWorkouts"] = model.NumWorkouts;

            int workoutCount = 0;
            IEnumerable<ml_WorkoutPlan> workouts = _workoutService.List(true, model, out workoutCount);
            ViewData["WorkoutCount"] = workoutCount;

            return PartialView("_ListAll", workouts);
        }