public ActionResult AddClient(ClientVM c) { ITrainerRepo trepo = TrainerRepoFactory.Create(); IClientRepo repo = ClientRepoFactory.Create(); if (ModelState.IsValid) { c.Trainers = new List <Trainer>(); var client = new Client { Trainers = new List <Trainer>(), ClientName = c.ClientName, StartingWeight = c.StartingWeight, CurrentWeight = c.CurrentWeight, FitnessGoals = c.FitnessGoals, }; foreach (var trainerID in c.SelectedTrainerID) { client.Trainers.Add(trepo.GetTrainerById(trainerID)); } repo.AddClient(client); } else { return(View(c)); } return(RedirectToAction("ClientList")); }
// GET: Home public ActionResult Index() { ITrainerRepo repo = TrainerRepoFactory.Create(); var model = repo.GetAllTrainers(); return(View(model)); }
public ActionResult EditWorkout(WorkoutVM w) { IWorkoutRepo wrepo = WorkoutRepoFactory.Create(); IClientRepo repo = ClientRepoFactory.Create(); ITrainerRepo trepo = TrainerRepoFactory.Create(); if (ModelState.IsValid) { var workout = new Workout { WorkoutID = w.WorkoutID, WorkoutName = w.WorkoutName, WorkoutDescription = w.WorkoutDescription, }; foreach (var trainerID in w.SelectedTrainerID) { workout.TrainerCreator.Add(trepo.GetTrainerById(trainerID)); } foreach (var clientID in w.SelectedClientID) { workout.ClientsOnWorkout.Add(repo.GetClientById(clientID)); } wrepo.EditWorkout(workout); } return(RedirectToAction("WorkoutList")); }
public ActionResult AddTrainer(TrainerVM t) { ITrainerRepo trepo = TrainerRepoFactory.Create(); IClientRepo repo = ClientRepoFactory.Create(); if (ModelState.IsValid) { var trainer = new Trainer { StartDate = DateTime.Today, TrainerID = t.TrainerID, TrainerName = t.TrainerName, HourlyRate = t.HourlyRate }; foreach (var clientID in t.SelectedClientID) { trainer.Clientelle.Add(repo.GetClientById(clientID)); } trepo.AddTrainer(trainer); } else { return(View(t)); } return(RedirectToAction("Index", "Home")); }
public ActionResult DeleteTrainer(int TrainerID) { ITrainerRepo repo = TrainerRepoFactory.Create(); repo.DeleteTrainer(TrainerID); return(RedirectToAction("Index", "Home")); }
public ActionResult EditTrainer(int id) { ITrainerRepo trepo = TrainerRepoFactory.Create(); IClientRepo repo = ClientRepoFactory.Create(); var trainer = trepo.GetTrainerById(id); var model = new TrainerVM { TrainerID = trainer.TrainerID, TrainerName = trainer.TrainerName, HourlyRate = trainer.HourlyRate, }; return(View(model)); }
public ActionResult EditTrainer(TrainerVM t) { IClientRepo repo = ClientRepoFactory.Create(); ITrainerRepo trepo = TrainerRepoFactory.Create(); if (ModelState.IsValid) { var trainer = new Trainer { Clientelle = new List <Client>(), TrainerID = t.TrainerID, TrainerName = t.TrainerName, HourlyRate = t.HourlyRate, StartDate = t.StartDate, }; foreach (var clientID in t.SelectedClientID) { trainer.Clientelle.Add(repo.GetClientById(clientID)); } trepo.EditTrainer(trainer); } return(RedirectToAction("Index", "Home")); }
protected override void Seed(FitnessApp.UI.FitnessDBContext context) { //create repos and userMGr and roleMgr to use throughout seed data ITrainerRepo orgrepo = TrainerRepoFactory.Create(); IClientRepo herorepo = ClientRepoFactory.Create(); IWorkoutRepo locorepo = WorkoutRepoFactory.Create(); var userMgr = new UserManager <IdentityUser>(new UserStore <IdentityUser>(context)); var roleMgr = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); if (!roleMgr.RoleExists("User")) { var role = new IdentityRole(); role.Name = "User"; roleMgr.Create(role); } if (!userMgr.Users.Any(u => u.UserName == "user")) { var user = new IdentityUser() { UserName = "******" }; userMgr.Create(user, "testing"); } var findmanager = userMgr.FindByName("user"); // create the user with the manager class if (!userMgr.IsInRole(findmanager.Id, "user")) { userMgr.AddToRole(findmanager.Id, "user"); } if (!roleMgr.RoleExists("admin")) { roleMgr.Create(new IdentityRole() { Name = "admin" }); } if (!userMgr.Users.Any(u => u.UserName == "admin")) { var user = new IdentityUser() { UserName = "******" }; userMgr.Create(user, "testing"); } var finduser = userMgr.FindByName("admin"); // create the user with the manager class if (!userMgr.IsInRole(finduser.Id, "admin")) { userMgr.AddToRole(finduser.Id, "admin"); } if (!context.Trainers.Any(t => t.TrainerName == "Arnold")) { var firsttrainer = new Trainer { TrainerName = "Arnold", TrainerID = 1, HourlyRate = 25, StartDate = new DateTime(2017, 1, 18), }; context.Trainers.Add(firsttrainer); context.SaveChanges(); } var trainer = context.Trainers.First(t => t.TrainerName == "Arnold"); if (!context.Clients.Any(c => c.ClientName == "Jarid")) { var firstclient = new Client { ClientName = "Jarid", ClientID = 1, ClientJoinDate = new DateTime(2017, 3, 23), CurrentWeight = 158, StartingWeight = 133, FitnessGoals = "I gotta get jacked so girls will want this hot body", }; context.Clients.Add(firstclient); context.SaveChanges(); } var client = context.Clients.First(c => c.ClientName == "Jarid"); if (!context.Workouts.Any(w => w.WorkoutName == "5x5 StrongLifts")) { var firstworkout = new Workout { WorkoutID = 1, WorkoutName = "5x5 StrongLifts", WorkoutDescription = "5 sets of 5 reps. Squat, Bench, Deadlift, Overhead and Row. Add 5 pounds after each workout.", }; context.Workouts.Add(firstworkout); context.SaveChanges(); } var workout = context.Workouts.First(w => w.WorkoutName == "5x5 StrongLifts"); }