Example #1
0
        public async Task <bool> UpdateProgram(WorkoutProgram program)
        {
            var programEntity = await _context.WorkoutPrograms
                                .Include(w => w.RoutineProgramEntries)
                                .SingleOrDefaultAsync(w => w.ID == program.ID);

            if (programEntity == null || programEntity.WTUserID != program.WTUserID)
            {
                return(false);
            }

            program.RoutineProgramEntries.ToList().ForEach(item => item.WorkoutProgramID = programEntity.ID);
            var updateRoutinesResult = await UpdateRoutinesForProgram(programEntity, program.RoutineProgramEntries.ToList());

            if (updateRoutinesResult == false)
            {
                return(false);
            }

            programEntity.Name        = program.Name;
            programEntity.Description = program.Description;

            await _context.SaveChangesAsync();

            return(true);
        }
Example #2
0
        public IActionResult Create([FromBody] WorkoutProgram program)
        {
            _context.WorkoutPrograms.Add(program);
            _context.SaveChanges();

            return(CreatedAtRoute("GetProgram", new { name = program.Name }, program));
        }
        public async Task <int> CreateWorkoutProgramAsync(ExerciseComplexity complexity, string userId)
        {
            var workoutProgram = new WorkoutProgram
            {
                ExerciseComplexity = complexity,
                ApplicationUserId  = userId,
            };

            await this.workoutRepository.AddAsync(workoutProgram);

            await this.workoutRepository.SaveChangesAsync();

            var exercises = await this.exercisesRepository
                            .All()
                            .Where(e => e.ExerciseComplexity == complexity)
                            .ToListAsync();

            foreach (var exercise in exercises)
            {
                var exercisesWorkoutProgram = new ExerciseWorkoutProgram
                {
                    ExerciseId       = exercise.Id,
                    WorkoutProgramId = workoutProgram.Id,
                };

                await this.exercisesWorkoutsRepository.AddAsync(exercisesWorkoutProgram);

                await this.exercisesWorkoutsRepository.SaveChangesAsync();
            }

            return(workoutProgram.Id);
        }
Example #4
0
        // GET: WorkoutPrograms/Create
        public IActionResult Create()
        {
            var workoutProgram = new WorkoutProgram();

            workoutProgram.WorkoutAssigments = new List <WorkoutAssigment>();
            PopulateAssignedWorkoutData(workoutProgram);
            return(View());
        }
Example #5
0
        public async Task <WorkoutProgram> GetFullWorkoutLayout(int workoutID)
        {
            var service = new WorkoutService();

            var program = new WorkoutProgram();

            program.ID          = workoutID;
            program.Name        = "blahhhh";
            program.WorkoutDays = new List <WorkoutDay>();

            List <FullWorkoutInfo> fullworkout = await service.GetFullWorkoutLayout(workoutID);

            //group by workout day
            var workoutDays = fullworkout.GroupBy(x => x.WorkoutDayTemplateID);

            var workoutDayList = new List <WorkoutDay>();

            foreach (var day in workoutDays)
            {
                var workoutDay = new WorkoutDay();
                workoutDay.WorkoutDayID     = day.Key;
                workoutDay.Name             = day.First().WorkoutDayTemplateName;
                workoutDay.DayOrder         = day.First().WorkoutDayTemplateDayOrder;
                workoutDay.WorkoutExercises = new List <WorkoutExercise>();

                //Group by exercise (in each workout day)
                var workoutDayExercises = day.GroupBy(x => x.ExerciseID);


                foreach (var exercise in workoutDayExercises)
                {
                    var workoutExercise = new WorkoutExercise();
                    workoutExercise.ExerciseID     = exercise.First().ExerciseID;
                    workoutExercise.ExerciseName   = exercise.First().Exercise;
                    workoutExercise.ExerciseTypeID = exercise.First().ExerciseTypeID;
                    workoutExercise.ExerciseType   = exercise.First().ExerciseType;

                    var setList = exercise.Select(x => new WorkoutSet
                    {
                        SetID     = x.SetID,
                        Reps      = x.Reps,
                        Weight    = 0, //Calculate this later?
                        UseTM     = x.UseTM.HasValue ? x.UseTM.Value : false,
                        TmPercent = x.TMPercent,
                        AMRAPSet  = x.AMRAPSet.HasValue ? x.AMRAPSet.Value : false,
                        WarmupSet = x.WarmupSet.HasValue ? x.WarmupSet.Value : false
                    });
                    workoutExercise.ExerciseSets = setList;
                    workoutDay.WorkoutExercises.Add(workoutExercise);
                }
                workoutDayList.Add(workoutDay);
            }
            //order by day order
            program.WorkoutDays = workoutDayList.OrderBy(x => x.DayOrder);

            return(program);
        }
 public ActionResult DeleteWorkoutSchedule(WorkoutProgram s)
 {
     if (ModelState.IsValid)
     {
         db.WorkoutPrograms.Attach(s);
         db.WorkoutPrograms.Remove(s);
         db.SaveChanges();
         TempData["Success"] = "Workout deleted successfully.";
         return RedirectToAction("ManagePrograms", "Trainer");
     }
     return View();
 }
 public ActionResult DeleteWorkoutSchedule(WorkoutProgram s)
 {
     if (ModelState.IsValid)
     {
         db.WorkoutPrograms.Attach(s);
         db.WorkoutPrograms.Remove(s);
         db.SaveChanges();
         TempData["Success"] = "Workout deleted successfully.";
         return(RedirectToAction("ManagePrograms", "Trainer"));
     }
     return(View());
 }
Example #8
0
        public async Task <bool> UpdateRoutinesForProgram(WorkoutProgram programEntity, List <RoutineProgramEntry> routineProgramEntries)
        {
            if (programEntity == null)
            {
                return(false);
            }

            //remove routines that arent present
            var routinesToBeRemoved = programEntity.RoutineProgramEntries.Where(item => !routineProgramEntries.Any(rp => rp.WorkoutRoutineID == item.WorkoutRoutineID)).ToList();

            _context.RemoveRange(routinesToBeRemoved);

            //add new or update existing routines
            List <RoutineProgramEntry> toBeAdded = new List <RoutineProgramEntry>();

            foreach (var rp in routineProgramEntries)
            {
                var rpEntity = programEntity.RoutineProgramEntries.FirstOrDefault(a => a.WorkoutRoutineID == rp.WorkoutRoutineID);
                if (rpEntity != null)
                {
                    if (rp.PlannedDates != null)
                    {
                        rpEntity.PlannedDates = rp.PlannedDates;
                    }
                }
                else
                {
                    rp.ID = 0;
                    toBeAdded.Add(rp);
                }
            }

            var allUserRoutineIDs = await _context.WorkoutRoutines
                                    .AsNoTracking()
                                    .Where(item => item.WTUserID == programEntity.WTUserID)
                                    .Select(item => item.ID)
                                    .ToListAsync();

            //check if all routines to be added belong to this user
            var routinesCheck = toBeAdded.All(item => allUserRoutineIDs.Contains((int)item.WorkoutRoutineID));

            if (routinesCheck == false)
            {
                return(false);
            }

            toBeAdded.ForEach(item => programEntity.RoutineProgramEntries.Add(item));

            await _context.SaveChangesAsync();

            return(true);
        }
        public ActionResult EditWorkoutSchedule(WorkoutProgram wp)
        {
            if (ModelState.IsValid)
            {
                var toBeUpdated = db.WorkoutPrograms.Find(wp.ID);
                db.Entry(toBeUpdated).CurrentValues.SetValues(wp);
                db.SaveChanges();
                TempData["Success"] = "Workout edited successfully.";
                return(RedirectToAction("ManagePrograms", "Trainer"));
            }

            return(View(wp));
        }
Example #10
0
        public async Task <WorkoutProgram> CreateProgram(WorkoutProgram program)
        {
            try
            {
                await _db.WorkoutPrograms.AddAsync(program);

                return(await _db.SaveChangesAsync() > 0 ? program : null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public ActionResult EditWorkoutSchedule(WorkoutProgram wp)
        {
            if (ModelState.IsValid)
            {
                var toBeUpdated = db.WorkoutPrograms.Find(wp.ID);
                db.Entry(toBeUpdated).CurrentValues.SetValues(wp);
                db.SaveChanges();
                TempData["Success"] = "Workout edited successfully.";
                return RedirectToAction("ManagePrograms", "Trainer");
            }

            return View(wp);
        }
 public ActionResult AddWorkoutSchedule(WorkoutProgram ws, String selectedID)
 {
     if (ModelState.IsValid)
     {
         User    u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
         Trainer t = db.Trainers.Where(x => x.EMail == u.EMail).FirstOrDefault();
         ws.TrainerID = t.ID;
         db.WorkoutPrograms.Add(ws);
         db.SaveChanges();
         TempData["Success"] = "Workout added successfully.";
         return(RedirectToAction("ManagePrograms", "Trainer"));
     }
     return(View());
 }
 public ActionResult AddWorkoutSchedule(WorkoutProgram ws,String selectedID)
 {
     if (ModelState.IsValid)
     {
         User u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
         Trainer t = db.Trainers.Where(x => x.EMail == u.EMail).FirstOrDefault();
         ws.TrainerID = t.ID;
         db.WorkoutPrograms.Add(ws);
         db.SaveChanges();
         TempData["Success"] = "Workout added successfully.";
         return RedirectToAction("ManagePrograms", "Trainer");
     }
     return View();
 }
Example #14
0
        public async Task <WorkoutProgram> EditProgram(int programId, WorkoutProgram updatedProgram)
        {
            try
            {
                var programToEdit = await _db.WorkoutPrograms.FirstOrDefaultAsync(p => p.Id == programId);

                programToEdit    = updatedProgram;
                programToEdit.Id = programId;
                return(await _db.SaveChangesAsync() > 0 ? programToEdit : null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #15
0
        public ActionResult ScheduleDetails(WorkoutProgram w)
        {
            if (ModelState.IsValid)
            {
                User     u           = db.Users.Find(int.Parse(Session["UserID"].ToString()));
                Customer c           = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
                var      toBeUpdated = db.Customers.Find(c.ID);
                c.WorkoutID = w.ID;
                db.Entry(toBeUpdated).CurrentValues.SetValues(c);
                db.SaveChanges();
                TempData["Success"] = "Workout program chosen successfully.";

                return(RedirectToAction("SelectProgram", "Customer"));
            }

            return(View());
        }
Example #16
0
        private void PopulateAssignedWorkoutData(WorkoutProgram workoutProgram)
        {
            var allWorkouts      = _unitOfWork.WorkoutRepository.GetAll();
            var workoutExercises = new HashSet <int>(workoutProgram.WorkoutAssigments.Select(e => e.WorkoutId));
            var viewModel        = new List <AssignedWorkoutData>();

            foreach (var workout in allWorkouts)
            {
                viewModel.Add(new AssignedWorkoutData()
                {
                    WorkoutId   = workout.WorkoutId,
                    WorkoutName = workout.WorkoutName,
                    Assigned    = workoutExercises.Contains(workout.WorkoutId)
                });
            }
            ViewData["Workouts"] = viewModel;
        }
Example #17
0
        private async Task <bool> SaveProgramImage(WorkoutProgram programEntity)
        {
            try
            {
                // get this environment's web root path (the path
                // from which static content, like an image, is served)
                var    webRootPath    = _hostingEnvironment.WebRootPath;
                string folderName     = "Images/Programs/" + programEntity.WTUserID.ToString();
                string fullFolderPath = $"{webRootPath}/{folderName}/";

                // create path if not exists... write bytes and auto-close stream
                FileInfo file = new FileInfo(fullFolderPath);
                file.Directory.Create();

                // create the filename
                string imageName      = programEntity.ImagePath;
                var    imageExtension = imageName.Substring(imageName.LastIndexOf("."));

                string fileName = "program_" + programEntity.ID + "_" + Guid.NewGuid() + imageExtension;

                //delete previuos image
                string[] fileList = Directory.GetFiles(fullFolderPath, $"*program_{programEntity.ID}*");
                foreach (var fileToDelete in fileList)
                {
                    System.IO.File.Delete(fileToDelete);
                }

                // the full file path
                var filePath = Path.Combine($"{fullFolderPath}/{fileName}");

                System.IO.File.WriteAllBytes(filePath, programEntity.ImageBytes);

                // fill out the filename
                programEntity.ImagePath = folderName + "/" + fileName;

                await _repository.UpdateImageForProgram(programEntity.ID, programEntity.ImagePath);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(500, ex, ex.Message);
                return(false);
            }
        }
        private void unosButton_Click(object sender, EventArgs e)
        {
            if (validiraj())
            {
                Random id = new Random();
                int r = id.Next(1111, 9999);
                WorkoutProgram WorkoutProgram = new WorkoutProgram(
                       r, opis_wprogram_rich_box.Text, "Licni Program", vjezbe_rich_box.Text);
                if (tipwp_combo.Text == "Tipicni Program")
                    WorkoutProgram.TipProgramaS = "Tipicni Program";

                DAL.DAL d = DAL.DAL.Instanca;
                d.kreirajKonekciju("localhost", "Teretana", "root", "");
                DAL.DAL.WorkoutProgramDAO c = d.getDAO.getWorkoutProgramDAO();

                WorkoutProgram.IdWorkoutPrograma = (int)c.create(WorkoutProgram);
                d.terminirajKonekciju();
                MessageBox.Show("Workout program unesen! ID je: " + r);
                Close();
            }
        }
Example #19
0
        public async Task <bool> AddProgramForUser(int?userId, WorkoutProgram program)
        {
            var user = await GetUserByUserId(userId);

            if (user == null)
            {
                return(false);
            }

            program.ID       = 0;
            program.WTUserID = userId;
            program.RoutineProgramEntries.ToList().ForEach(item => item.WorkoutProgramID = program.ID);
            if (string.IsNullOrEmpty(program.ImagePath))
            {
                program.ImagePath = "Images/monkasProgram.png";
            }


            //check if the posted routinesIds belong to the user
            var allUserRoutineIds = await _context.WorkoutRoutines
                                    .AsNoTracking()
                                    .Where(item => item.WTUserID == userId)
                                    .Select(item => item.ID)
                                    .ToListAsync();


            var routinesCheck = program.RoutineProgramEntries.All(item => allUserRoutineIds.Contains((int)item.WorkoutRoutineID));

            if (!routinesCheck)
            {
                return(false);
            }

            _context.WorkoutPrograms.Add(program);

            await _context.SaveChangesAsync();

            return(true);
        }
Example #20
0
        private void UpdateWorkoutProgramWorkouts(string[] selectedWorkouts, WorkoutProgram workoutProgram)
        {
            if (selectedWorkouts == null)
            {
                workoutProgram.WorkoutAssigments = new List <WorkoutAssigment>();
                return;
            }

            var selectedWorkoutsHS = new HashSet <string>(selectedWorkouts);
            var workoutExercises   = new HashSet <int>
                                         (workoutProgram.WorkoutAssigments.Select(c => c.Workout.WorkoutId));
            var workouts = _unitOfWork.WorkoutRepository.GetAll();

            foreach (var workout in workouts)
            {
                if (selectedWorkoutsHS.Contains(workout.WorkoutId.ToString()))
                {
                    if (!workoutExercises.Contains(workout.WorkoutId))
                    {
                        workoutProgram.WorkoutAssigments.Add(new WorkoutAssigment()
                        {
                            WorkoutProgramId = workoutProgram.WorkoutProgramId,
                            WorkoutId        = workout.WorkoutId
                        });
                    }
                }
                else
                {
                    if (workoutExercises.Contains(workout.WorkoutId))
                    {
                        WorkoutAssigment workoutToRemove =
                            workoutProgram.WorkoutAssigments.SingleOrDefault(i => i.WorkoutId == workout.WorkoutId);

                        workoutProgram.WorkoutAssigments.Remove(workoutToRemove);
                        _unitOfWork.WorkoutProgramRepository.SaveAsync();
                    }
                }
            }
        }
Example #21
0
        public ActionResult SelectProgram()
        {
            User           u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
            Customer       c = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
            WorkoutProgram w = db.WorkoutPrograms.Find(c.WorkoutID);

            if (w != null)
            {
                if (w.Schedule.Length > 10)
                {
                    TempData["Info"] = "Your current program is " + w.Schedule.Substring(0, w.Schedule.Length - 5) + "...";
                }
                else
                {
                    TempData["Info"] = "Your current program is " + w.Schedule;
                }
            }
            else
            {
                TempData["Info"] = "You do not have a current schedule.";
            }
            return(View(db.WorkoutPrograms.ToList()));
        }
        public ActionResult DeleteWorkoutSchedule(int id)
        {
            WorkoutProgram wp = db.WorkoutPrograms.Where(x => x.ID == id).FirstOrDefault();

            return(View(wp));
        }
        public ActionResult ScheduleDetails(WorkoutProgram w)
        {
            if (ModelState.IsValid)
            {
                User u = db.Users.Find(int.Parse(Session["UserID"].ToString()));
                Customer c = db.Customers.Where(x => x.EMail == u.EMail).FirstOrDefault();
                var toBeUpdated = db.Customers.Find(c.ID);
                c.WorkoutID = w.ID;
                db.Entry(toBeUpdated).CurrentValues.SetValues(c);
                db.SaveChanges();
                TempData["Success"] = "Workout program chosen successfully.";

                return RedirectToAction("SelectProgram", "Customer");
            }

            return View();
        }
Example #24
0
        public static void Initialize(WorkoutsContext context)
        {
            context.Database.EnsureCreated();

            //look for any workouts
            if (context.WorkoutPrograms.Any())
            {
                return; //db already has data
            }


            var workouts = new WorkoutProgram[]
            {
                new WorkoutProgram {
                    author = "MR", Name = "workout102", difficulty = 3
                },
                new WorkoutProgram {
                    author = "PR", Name = "workout99", difficulty = 1
                },
                new WorkoutProgram {
                    author = "KR", Name = "workout87", difficulty = 2
                }
            };

            foreach (WorkoutProgram wp in workouts)
            {
                context.WorkoutPrograms.Add(wp);
            }

            context.SaveChanges();

            var exercises = new Exercise[]
            {
                new Exercise {
                    name = "squat", repstime = "12", sets = 1, description = "sq and up", WorkoutProgramId = 1
                },
                new Exercise {
                    name = "bench press", repstime = "9", sets = 3, description = "presss", WorkoutProgramId = 2
                },
                new Exercise {
                    name = "rollover", repstime = "5s", sets = 1, description = "rolll", WorkoutProgramId = 2
                }
            };

            foreach (Exercise ex in exercises)
            {
                context.Exercises.Add(ex);
            }

            context.SaveChanges();

            DateTime date = DateTime.Now;
            var      logs = new Log[]
            {
                new Log {
                    date = date, username = "******", WorkoutProgramId = 1
                },
                new Log {
                    date = date, username = "******", WorkoutProgramId = 2
                }
            };

            foreach (Log l in logs)
            {
                context.Logs.Add(l);
            }

            context.SaveChanges();
        }
Example #25
0
        public async Task Seed()
        {
            _context.Database.EnsureCreated();
            var user = await _userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new User()
                {
                    FirstName = "Stella",
                    LastName  = "Selena",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };

                var result = await _userManager.CreateAsync(user, "P@ssw0rd!");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create default user");
                }
            }
            if (!_context.Products.Any())
            {
                //create sample data from json
                var file     = Path.Combine(_hosting.ContentRootPath, "Data/supplement.json");
                var json     = File.ReadAllText(file);
                var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json);
                _context.Products.AddRange(products);

                var order = new Order()
                {
                    OrderDate   = DateTime.Now,
                    OrderNumber = "12345",
                    User        = user,
                    Items       = new List <OrderItem>()
                    {
                        new OrderItem()
                        {
                            Product   = products.First(),
                            Quantity  = 5,
                            UnitPrice = products.First().Price
                        }
                    }
                };

                _context.Orders.Add(order);
            }

            if (!_context.Gyms.Any())
            {
                var gyms = new Gym[]
                {
                    new Gym {
                        GymName = "Myrens", City = "Oslo", Country = "Norway", PostalCode = 0473, Description = "Myrens squash og treningssenter", Street = "Sandakerveien 22", Website = "www.myrens.no", Email = "*****@*****.**", PhoneNumber = 94815633
                    },
                    new Gym {
                        GymName = "Sats", City = "Oslo", Country = "Norway", PostalCode = 0372, Description = "Sats treningssenter", Street = "Arendalsgata 33", Website = "www.sats.no", Email = "*****@*****.**", PhoneNumber = 45633943
                    },
                    new Gym {
                        GymName = "Elixia", City = "Oslo", Country = "Norway", PostalCode = 0252, Description = "Elixia treningssenter", Street = "Middelthunsgate 15", Website = "www.elixia.no", Email = "*****@*****.**", PhoneNumber = 4335442
                    }
                };
                foreach (Gym g in gyms)
                {
                    _context.Gyms.Add(g);
                }
            }
            if (!_context.Employees.Any())
            {
                var employees = new Employee[]
                {
                    new Employee {
                        FirstName = "Layne", LastName = "Norton", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Male, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Certification = Certification.PersonalTrainer, Specialization = Specialization.SportsConditioning,          /*GymId = 1*/
                    },
                    new Employee {
                        FirstName = "Mark", LastName = "Bell", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Male, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Certification = Certification.PersonalTrainer, Specialization = Specialization.SportsConditioning,           /*GymId = 2*/
                    },
                    new Employee {
                        FirstName = "Omar", LastName = "Isuf", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Male, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Certification = Certification.PersonalTrainer, Specialization = Specialization.SportsConditioning,          /*GymId = 3*/
                    }
                };
                foreach (Employee e in employees)
                {
                    _context.Employees.Add(e);
                }
            }

            if (!_context.Customers.Any())
            {
                var customers = new Customer[]
                {
                    new Customer {
                        FirstName = "Stella", LastName = "Selena", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Female, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Goal = Goal.Maintenance, Weight = 65, Height = 175, ActivityLevel = ActivityLevel.Moderate, BodyFat = 20         /*, GymId = 1, EmployeeId = 1*/
                    },
                    new Customer {
                        FirstName = "Stefan", LastName = "Selena", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Female, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Goal = Goal.Maintenance, Weight = 65, Height = 175, ActivityLevel = ActivityLevel.Moderate, BodyFat = 20         /*, GymId = 2/*, EmployeeId = 2*/
                    },
                    new Customer {
                        FirstName = "Athena", LastName = "Selena", Birthday = DateTime.Parse("1991-10-28"), Gender = Gender.Female, Country = "Norway", City = "Oslo", Email = "*****@*****.**", Goal = Goal.Maintenance, Weight = 65, Height = 175, ActivityLevel = ActivityLevel.Moderate, BodyFat = 20         /*, GymId = 3/*, EmployeeId = 3*/
                    }
                };
                foreach (Customer c in customers)
                {
                    _context.Customers.Add(c);
                }
            }

            if (!_context.Exercises.Any())
            {
                var exercises = new Exercise[]
                {
                    new Exercise
                    {
                        ExerciseName        = "Squat",
                        ExerciseDescription = "squat down",
                        MuscleGroup         = MuscleGroup.Legs
                    },
                    new Exercise
                    {
                        ExerciseName        = "Rows",
                        ExerciseDescription = "barbell/ dumbbell",
                        MuscleGroup         = MuscleGroup.Back
                    },
                    new Exercise
                    {
                        ExerciseName        = "Shoulder press",
                        ExerciseDescription = "alternative to barbell press",
                        MuscleGroup         = MuscleGroup.Shoulders
                    }
                };
                foreach (Exercise e in exercises)
                {
                    _context.Exercises.Add(e);
                }
            }
            if (!_context.WorkoutTypes.Any())
            {
                var workoutTypes = new WorkoutType[]
                {
                    new WorkoutType {
                        WorkoutTypeName = "Strength", WorkoutTypeDescription = "Strength training"
                    },
                    new WorkoutType {
                        WorkoutTypeName = "Cardio", WorkoutTypeDescription = "Cardio training"
                    },
                    new WorkoutType {
                        WorkoutTypeName = "HIIT", WorkoutTypeDescription = "High intensity intervals training"
                    }
                };
                foreach (WorkoutType w in workoutTypes)
                {
                    _context.WorkoutTypes.Add(w);
                }
            }
            if (!_context.Workouts.Any())
            {
                var workouts = new Workout[]
                {
                    new Workout {
                        WorkoutName = "Legs",        /* WorkoutTypeId = 1*/
                    },
                    new Workout {
                        WorkoutName = "Chest and Shoulders"        /*, WorkoutTypeId = 1*/
                    }
                };
                foreach (Workout workout in workouts)
                {
                    _context.Workouts.Add(workout);
                }
            }
            if (!_context.WorkoutPrograms.Any())
            {
                var workoutPrograms = new WorkoutProgram[]
                {
                    new WorkoutProgram {
                        WorkoutProgramName = "PHAT", WorkoutProgramDescription = "Layne Norton's Program"
                    },
                    new WorkoutProgram {
                        WorkoutProgramName = "Starting Strength", WorkoutProgramDescription = "Mark Rippetoe's Program"
                    }
                };

                foreach (WorkoutProgram workoutProgram in workoutPrograms)
                {
                    _context.WorkoutPrograms.Add(workoutProgram);
                }
            }

            //if (!_context.ExerciseAssigments.Any())
            //{
            //    var exerciseAssigments = new ExerciseAssigment[]
            //    {
            //        new ExerciseAssigment{WorkoutId = _context.Workouts.First().WorkoutId, ExerciseId = _context.Exercises.First().ExerciseId},

            //    };

            //    foreach (ExerciseAssigment exerciseAssigment in exerciseAssigments)
            //    {
            //        _context.ExerciseAssigments.Add(exerciseAssigment);
            //    }

            //}


            //if (!_context.WorkoutAssigments.Any())
            //{
            //    var workoutAssigments = new WorkoutAssigment[]
            //    {
            //        new WorkoutAssigment{WorkoutId = _context.Workouts.First().WorkoutId, WorkoutProgramId = _context.WorkoutPrograms.First().WorkoutProgramId}
            //    };

            //    foreach (WorkoutAssigment workoutAssigment in workoutAssigments)
            //    {
            //        _context.WorkoutAssigments.Add(workoutAssigment);
            //    }

            //}

            _context.SaveChanges();
        }
Example #26
0
        public ActionResult ScheduleDetails(int id)
        {
            WorkoutProgram w = db.WorkoutPrograms.Find(id);

            return(View(w));
        }
Example #27
0
        public static void Initialize(WorkoutTrackingDBContext context)
        {
            context.Database.EnsureCreated();

            if (context.Users.Any())
            {
                return;   // DB has been seeded
            }

            var users = new WTUser[]
            {
                new WTUser {
                    FirstName = "Riste", LastName = "Poposki", RegisterDate = DateTime.Parse("2017-09-01"), Email = "*****@*****.**", Password = "******", Username = "******"
                },
                new WTUser {
                    FirstName = "Monkas", LastName = "MonkaGiga", RegisterDate = DateTime.Now, Email = "*****@*****.**", Password = "******", Username = "******"
                },
            };

            context.Users.AddRange(users);
            context.SaveChanges();


            var exercises = new Exercise[]
            {
                new Exercise {
                    Name = "Riste Execise 1", WTUserID = 1, Category = Category.ARMS, Description = "Riste Execise Desc 1", IsEditable = true, ImagePath = "Images/monkas.jpg"
                },
                new Exercise {
                    Name = "Riste Execise 2", WTUserID = 1, Category = Category.CHEST, Description = "Riste Execise Desc 2", IsEditable = true, ImagePath = "Images/monkas.jpg"
                },
                new Exercise {
                    Name = "Monkas Execise 1", WTUserID = 2, Category = Category.LEGS, Description = "Monkas Execise Desc 1", IsEditable = true, ImagePath = "Images/monkas.jpg"
                },
                new Exercise {
                    Name = "Monkas Execise 2", WTUserID = 2, Category = Category.OTHER, Description = "Monkas Execise Desc 2", IsEditable = true, ImagePath = "Images/monkas.jpg"
                }
            };

            context.Exercises.AddRange(exercises);
            context.SaveChanges();


            var routines = new WorkoutRoutine[]
            {
                new WorkoutRoutine {
                    Name = "Riste Workout 1", Description = "Riste Routine Desc 1", WTUserID = 1, ImagePath = "Images/monkasRoutine.jpg"
                },
                new WorkoutRoutine {
                    Name = "Riste Workout 2", Description = "Riste Routine Desc 2", WTUserID = 1, ImagePath = "Images/monkasRoutine.jpg"
                },
                new WorkoutRoutine {
                    Name = "Monkas Workout 1", Description = "Monkas Routine Desc 1", WTUserID = 2, ImagePath = "Images/monkasRoutine.jpg"
                },
                new WorkoutRoutine {
                    Name = "Monkas Workout 1", Description = "Monkas Routine Desc 2", WTUserID = 2, ImagePath = "Images/monkasRoutine.jpg"
                }
            };

            context.WorkoutRoutines.AddRange(routines);
            context.SaveChanges();


            var programs = new WorkoutProgram[]
            {
                new WorkoutProgram {
                    Name = "Riste Program 1", Description = "Riste Program Desc 1", WTUserID = 1, ImagePath = "Images/monkasProgram.png"
                },
                new WorkoutProgram {
                    Name = "Riste Program 2", Description = "Riste Program Desc 2", WTUserID = 1, ImagePath = "Images/monkasProgram.png"
                },
                new WorkoutProgram {
                    Name = "Monkas Program 1", Description = "Monkas Program Desc 1", WTUserID = 2, ImagePath = "Images/monkasProgram.png"
                },
                new WorkoutProgram {
                    Name = "Monkas Program 1", Description = "Monkas Program Desc 2", WTUserID = 2, ImagePath = "Images/monkasProgram.png"
                },
            };

            context.WorkoutPrograms.AddRange(programs);
            context.SaveChanges();


            var sessions = new WorkoutSession[]
            {
                new WorkoutSession {
                    Date = DateTime.Now, WTUserID = 1
                },
                new WorkoutSession {
                    Date = DateTime.Now.AddDays(1), WTUserID = 1
                },
                new WorkoutSession {
                    Date = DateTime.Now, WTUserID = 2
                },
                new WorkoutSession {
                    Date = DateTime.Now.AddDays(1), WTUserID = 2
                },
            };

            context.WorkoutSessions.AddRange(sessions);
            context.SaveChanges();


            var bodyStats = new BodyStatistic[]
            {
                new BodyStatistic {
                    DateCreated = DateTime.Now, Year = DateTime.Now.Year, Month = DateTime.Now.Month, Week = DateTime.Now.GetWeekOfMonth(), WTUserID = 1
                },
                new BodyStatistic {
                    DateCreated = DateTime.Now.AddDays(7), Year = DateTime.Now.AddDays(7).Year,
                    Month       = DateTime.Now.AddDays(7).Month, Week = DateTime.Now.AddDays(7).GetWeekOfMonth(), WTUserID = 1
                },

                new BodyStatistic {
                    DateCreated = DateTime.Now, Year = DateTime.Now.Year, Month = DateTime.Now.Month, Week = DateTime.Now.GetWeekOfMonth(), WTUserID = 2
                },
                new BodyStatistic {
                    DateCreated = DateTime.Now.AddDays(7), Year = DateTime.Now.AddDays(7).Year,
                    Month       = DateTime.Now.AddDays(7).Month, Week = DateTime.Now.AddDays(7).GetWeekOfMonth(), WTUserID = 2
                },
            };

            context.BodyStatistics.AddRange(bodyStats);
            context.SaveChanges();



            var bodyAttributeTemplate = new BodyAttributeTemplate[]
            {
                new BodyAttributeTemplate {
                    AttributeName = "Template Attr 1", AttributeValue = "OK1", WTUserID = 1, IsDeletable = true
                },
                new BodyAttributeTemplate {
                    AttributeName = "Template Attr 2", AttributeValue = "OK2", WTUserID = 1, IsDeletable = true
                },
                new BodyAttributeTemplate {
                    AttributeName = "Template Attr 3", AttributeValue = "NO1", WTUserID = 2, IsDeletable = true
                },
                new BodyAttributeTemplate {
                    AttributeName = "Template Attr 4", AttributeValue = "NO2", WTUserID = 2, IsDeletable = true
                }
            };

            context.BodyAttributeTemplates.AddRange(bodyAttributeTemplate);
            context.SaveChanges();



            var exerciseAttribute1 = new ExerciseAttribute {
                AttributeName = "Sets", AttributeValue = "value1", ExerciseID = 1, IsDeletable = false
            };
            var exerciseAttribute2 = new ExerciseAttribute {
                AttributeName = "Repetitions", AttributeValue = "value2", ExerciseID = 2, IsDeletable = false
            };
            var exerciseAttribute3 = new ExerciseAttribute {
                AttributeName = "Sets", AttributeValue = "value1", ExerciseID = 3, IsDeletable = false
            };
            var exerciseAttribute4 = new ExerciseAttribute {
                AttributeName = "Repetitions", AttributeValue = "value2", ExerciseID = 4, IsDeletable = false
            };

            var exercise = context.Exercises.SingleOrDefault(e => e.ID == 1);

            exercise.Attributes = new List <ExerciseAttribute>();
            exercise.Attributes.Add(exerciseAttribute1);

            exercise            = context.Exercises.SingleOrDefault(e => e.ID == 2);
            exercise.Attributes = new List <ExerciseAttribute>();
            exercise.Attributes.Add(exerciseAttribute2);

            exercise            = context.Exercises.SingleOrDefault(e => e.ID == 3);
            exercise.Attributes = new List <ExerciseAttribute>();
            exercise.Attributes.Add(exerciseAttribute3);

            exercise            = context.Exercises.SingleOrDefault(e => e.ID == 4);
            exercise.Attributes = new List <ExerciseAttribute>();
            exercise.Attributes.Add(exerciseAttribute4);
            context.SaveChanges();



            var bodyStatAttribute1 = new BodyStatAttribute {
                AttributeName = "Riste Height", AttributeValue = "173", BodyStatisticID = 1, IsDeletable = true
            };
            var bodyStatAttribute2 = new BodyStatAttribute {
                AttributeName = "Riste Weight", AttributeValue = "71", BodyStatisticID = 2, IsDeletable = true
            };
            var bodyStatAttribute3 = new BodyStatAttribute {
                AttributeName = "Monkas Height", AttributeValue = "195", BodyStatisticID = 3, IsDeletable = true
            };
            var bodyStatAttribute4 = new BodyStatAttribute {
                AttributeName = "Monkas Weight", AttributeValue = "91", BodyStatisticID = 4, IsDeletable = true
            };

            var bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 1);

            bodyStat.BodyStatAttributes = new List <BodyStatAttribute>();
            bodyStat.BodyStatAttributes.Add(bodyStatAttribute1);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 2);
            bodyStat.BodyStatAttributes = new List <BodyStatAttribute>();
            bodyStat.BodyStatAttributes.Add(bodyStatAttribute2);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 3);
            bodyStat.BodyStatAttributes = new List <BodyStatAttribute>();
            bodyStat.BodyStatAttributes.Add(bodyStatAttribute3);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 4);
            bodyStat.BodyStatAttributes = new List <BodyStatAttribute>();
            bodyStat.BodyStatAttributes.Add(bodyStatAttribute4);
            context.SaveChanges();



            var progressImage1 = new ProgressImage {
                DateCreated = DateTime.Now, Url = "url1", BodyStatisticID = 1
            };
            var progressImage2 = new ProgressImage {
                DateCreated = DateTime.Now.AddDays(1), Url = "url2", BodyStatisticID = 2
            };
            var progressImage3 = new ProgressImage {
                DateCreated = DateTime.Now.AddDays(2), Url = "url3", BodyStatisticID = 3
            };
            var progressImage4 = new ProgressImage {
                DateCreated = DateTime.Now.AddDays(3), Url = "url4", BodyStatisticID = 4
            };

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 1);
            bodyStat.ProgressImages = new List <ProgressImage>();
            bodyStat.ProgressImages.Add(progressImage1);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 2);
            bodyStat.ProgressImages = new List <ProgressImage>();
            bodyStat.ProgressImages.Add(progressImage2);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 3);
            bodyStat.ProgressImages = new List <ProgressImage>();
            bodyStat.ProgressImages.Add(progressImage3);

            bodyStat = context.BodyStatistics.SingleOrDefault(e => e.ID == 4);
            bodyStat.ProgressImages = new List <ProgressImage>();
            bodyStat.ProgressImages.Add(progressImage4);
            context.SaveChanges();



            var exerciseRoutineEntry1 = new ExerciseRoutineEntry {
                ExerciseID = 1, WorkoutRoutineID = 1
            };
            var exerciseRoutineEntry2 = new ExerciseRoutineEntry {
                ExerciseID = 2, WorkoutRoutineID = 1
            };
            var exerciseRoutineEntry3 = new ExerciseRoutineEntry {
                ExerciseID = 1, WorkoutRoutineID = 2
            };

            var routine = context.WorkoutRoutines.SingleOrDefault(u => u.ID == 1);

            routine.ExerciseRoutineEntries = new List <ExerciseRoutineEntry>();
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry1);
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry2);

            routine = context.WorkoutRoutines.SingleOrDefault(u => u.ID == 2);
            routine.ExerciseRoutineEntries = new List <ExerciseRoutineEntry>();
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry3);

            var exerciseRoutineEntry4 = new ExerciseRoutineEntry {
                ExerciseID = 3, WorkoutRoutineID = 3
            };
            var exerciseRoutineEntry5 = new ExerciseRoutineEntry {
                ExerciseID = 4, WorkoutRoutineID = 3
            };
            var exerciseRoutineEntry6 = new ExerciseRoutineEntry {
                ExerciseID = 3, WorkoutRoutineID = 4
            };

            routine = context.WorkoutRoutines.SingleOrDefault(u => u.ID == 3);
            routine.ExerciseRoutineEntries = new List <ExerciseRoutineEntry>();
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry4);
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry5);

            routine = context.WorkoutRoutines.SingleOrDefault(u => u.ID == 4);
            routine.ExerciseRoutineEntries = new List <ExerciseRoutineEntry>();
            routine.ExerciseRoutineEntries.Add(exerciseRoutineEntry6);
            context.SaveChanges();



            var routineProgramEntry1 = new RoutineProgramEntry {
                WorkoutRoutineID = 1, WorkoutProgramID = 1, PlannedDates = "2018-05-26;2018-06-01"
            };
            var routineProgramEntry2 = new RoutineProgramEntry {
                WorkoutRoutineID = 2, WorkoutProgramID = 1, PlannedDates = "2018-05-29"
            };
            var routineProgramEntry3 = new RoutineProgramEntry {
                WorkoutRoutineID = 1, WorkoutProgramID = 2, PlannedDates = "2018-07-26;2018-07-27"
            };

            var program = context.WorkoutPrograms.SingleOrDefault(u => u.ID == 1);

            program.RoutineProgramEntries = new List <RoutineProgramEntry>();
            program.RoutineProgramEntries.Add(routineProgramEntry1);
            program.RoutineProgramEntries.Add(routineProgramEntry2);

            program = context.WorkoutPrograms.SingleOrDefault(u => u.ID == 2);
            program.RoutineProgramEntries = new List <RoutineProgramEntry>();
            program.RoutineProgramEntries.Add(routineProgramEntry3);

            var routineProgramEntry4 = new RoutineProgramEntry {
                WorkoutRoutineID = 3, WorkoutProgramID = 3, PlannedDates = "2018-01-26;2018-01-27"
            };
            var routineProgramEntry5 = new RoutineProgramEntry {
                WorkoutRoutineID = 4, WorkoutProgramID = 3, PlannedDates = "2018-02-26"
            };
            var routineProgramEntry6 = new RoutineProgramEntry {
                WorkoutRoutineID = 3, WorkoutProgramID = 4, PlannedDates = "2018-03-26;2018-03-27"
            };

            program = context.WorkoutPrograms.SingleOrDefault(u => u.ID == 3);
            program.RoutineProgramEntries = new List <RoutineProgramEntry>();
            program.RoutineProgramEntries.Add(routineProgramEntry4);
            program.RoutineProgramEntries.Add(routineProgramEntry5);

            program = context.WorkoutPrograms.SingleOrDefault(u => u.ID == 4);
            program.RoutineProgramEntries = new List <RoutineProgramEntry>();
            program.RoutineProgramEntries.Add(routineProgramEntry6);
            context.SaveChanges();



            var ConcreteExercisesList = exercises.ToList().Select(item => item.GetConcreteExerciseObject()).ToList();

            for (int i = 0; i < ConcreteExercisesList.Count(); i++)
            {
                var item = ConcreteExercisesList[i];
                item.WorkoutSessionID = i + 1;
                context.ConcreteExercises.Add(item);
            }
            context.SaveChanges();
        }