Ejemplo n.º 1
0
        public ActionResult <Models.WorkoutModel> GetWorkoutByDay(int day)
        {
            var userName = User.Claims.Single(a => a.Type == ClaimTypes.NameIdentifier).Value;

            var Schedule = _context.UserData
                           .Include(i => i.Workouts).ThenInclude(i => i.Exercises).ThenInclude(i => i.Sets)
                           .Include(i => i.UserSchedule)
                           .Where(i => i.User == userName)
                           .First().UserSchedule;

            if (Schedule == null)
            {
                return(NotFound("Schedule not found"));
            }
            var result = new Entities.Workout();

            switch (day)
            {
            case 1:
                result = Schedule.Monday;
                break;

            case 2:
                result = Schedule.Tuesday;
                break;

            case 3:
                result = Schedule.Wednesday;
                break;

            case 4:
                result = Schedule.Thursday;
                break;

            case 5:
                result = Schedule.Friday;
                break;

            case 6:
                result = Schedule.Saturday;
                break;

            case 7:
                result = Schedule.Sunday;
                break;

            default:
                return(BadRequest("Such day doesnt exist, value should be between 1-7"));

                break;
            }
            if (result == null)
            {
                return(NotFound("No workout this day"));
            }
            var answer = new Models.WorkoutModel()
            {
                Id        = result.Id,
                Name      = result.WorkoutName,
                Exercises = result.Exercises.Select(i => new ExerciseModel()
                {
                    Id           = i.Id,
                    ExerciseName = i.Name,
                    Type         = i.ExerciseType,
                    Sets         = i.Sets.Select(j => new SetModel()
                    {
                        Id       = j.Id,
                        Weights  = j.Weight,
                        RepCount = j.RepCount
                    }).ToList()
                }).ToList()
            };

            return(Ok(answer));
        }
Ejemplo n.º 2
0
        public ActionResult <Models.WorkoutModel> GetTodaysWorkout()
        {
            var userName = User.Claims.Single(a => a.Type == ClaimTypes.NameIdentifier).Value;

            var Schedule = _context.UserData
                           .Include(i => i.Workouts).ThenInclude(i => i.Exercises).ThenInclude(i => i.Sets)
                           .Include(i => i.UserSchedule)
                           .Where(i => i.User == userName)
                           .First().UserSchedule;

            if (Schedule == null)
            {
                return(NotFound("Schedule not found"));
            }

            string day = DateTime.Now.DayOfWeek.ToString();

            var result = new Entities.Workout();

            switch (day)
            {
            case "Monday":
                result = Schedule.Monday;
                break;

            case "Tuesday":
                result = Schedule.Tuesday;
                break;

            case "Wednesday":
                result = Schedule.Wednesday;
                break;

            case "Thursday":
                result = Schedule.Thursday;
                break;

            case "Friday":
                result = Schedule.Friday;
                break;

            case "Saturday":
                result = Schedule.Saturday;
                break;

            case "Sunday":
                result = Schedule.Sunday;
                break;
            }
            if (result == null)
            {
                return(NotFound("No workout this day"));
            }
            var answer = new Models.WorkoutModel()
            {
                Id        = result.Id,
                Name      = result.WorkoutName,
                Exercises = result.Exercises.Select(i => new ExerciseModel()
                {
                    Id           = i.Id,
                    ExerciseName = i.Name,
                    Type         = i.ExerciseType,
                    Sets         = i.Sets.Select(j => new SetModel()
                    {
                        Id       = j.Id,
                        Weights  = j.Weight,
                        RepCount = j.RepCount
                    }).ToList()
                }).ToList()
            };

            return(Ok(answer));
        }