public IActionResult Add([FromBody] ExercisePlanning exercisePlanning) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user_ID = _jwtHandler.GetUserID(_httpContextAccessor.HttpContext); //_roleService.IsUserManager(user_ID); //_userPhysioService.IsMemberOfPhysio(user_ID, exercisePlanning.UserExercise.User_ID); var userExercise = _userExerciseService.Get(exercisePlanning.UserExercise.User_ID, exercisePlanning.UserExercise.Exercise_ID); exercisePlanning.UserExercise = userExercise; _exercisePlanningService.Add(exercisePlanning); return(NoContent()); }
private void AddExercisePlanning(ExercisePlanning exercisePlanning) { using (var scope = _scopeFactory.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService <Context>(); dbContext.Attach(exercisePlanning); dbContext.Entry(exercisePlanning).State = EntityState.Added; // Add ExerciseSessions foreach (var date in Helper.GetDateTimes(exercisePlanning.StartDate, exercisePlanning.EndDate)) { dbContext.ExerciseSessions.Add(new ExerciseSession() { Date = date, IsComplete = false, ExercisePlanning = exercisePlanning }); } dbContext.SaveChanges(); } }
public static void Initialize(Context context) { context.Database.EnsureCreated(); if (!context.UserGroups.Any()) { context.UserGroups.Add(new UserGroup { ID = Models.Type.User, Type = "User", Description = "The end user that will use the application through the Unity application" }); context.UserGroups.Add(new UserGroup { ID = Models.Type.Manager, Type = "Manager", Description = "To manage and review statistics of its users. The physiotherapist" }); context.UserGroups.Add(new UserGroup { ID = Models.Type.Administrator, Type = "Administrator", Description = "Highest role to manage Managers" }); context.SaveChanges(); } if (!context.Users.Any()) { // m625LrMSdPa9IZlnFAaR4O6X9gXQxC4PRlfuPnZRb9Kb4Ka2 = password context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Admin", LastName = "Admin", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.Administrator) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Jan", LastName = "van Windmolen", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.Manager) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Herman", LastName = "de Tas", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.Manager) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Nick", LastName = "Windt", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.User) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Peter", LastName = "Torenvalk", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.User) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Lies", LastName = "Bakker", Gender = 'f', UserGroup = context.UserGroups.Find(API.Models.Type.User) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Henk", LastName = "Jansen", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.User) }); context.Add(new User { Email = "*****@*****.**", Password = "******", FirstName = "Kees", LastName = "van Berenstein", Gender = 'm', UserGroup = context.UserGroups.Find(API.Models.Type.User) }); context.SaveChanges(); } if (!context.UserPhysios.Any()) { User user = context.Users.First(a => a.Email == "*****@*****.**"); User user2 = context.Users.First(a => a.Email == "*****@*****.**"); User user3 = context.Users.First(a => a.Email == "*****@*****.**"); User user4 = context.Users.First(a => a.Email == "*****@*****.**"); User user5 = context.Users.First(a => a.Email == "*****@*****.**"); User fysio = context.Users.First(a => a.Email == "*****@*****.**"); User fysio2 = context.Users.First(a => a.Email == "*****@*****.**"); context.Add(new UserPhysio { User = user, Physio = fysio }); context.Add(new UserPhysio { User = user2, Physio = fysio }); context.Add(new UserPhysio { User = user3, Physio = fysio }); context.Add(new UserPhysio { User = user4, Physio = fysio }); context.Add(new UserPhysio { User = user5, Physio = fysio2 }); context.SaveChanges(); } if (!context.Exercises.Any()) { context.Add(new Exercise { Name = "Nek beweging", Description = "Beweeg uw nek van links naar rechts", Recording = new byte[8] }); context.Add(new Exercise { Name = "Arm spanning", Description = "Strek uw arm vooruit, span de spieren samen en beweeg de arm 90 graden naarboven", Recording = new byte[8] }); context.Add(new Exercise { Name = "Been strekking", Description = "Ga staan en strek uw been vooruit", Recording = new byte[8] }); context.SaveChanges(); } if (!context.UserExercises.Any()) { User user = context.Users.First(a => a.Email == "*****@*****.**"); User user2 = context.Users.First(a => a.Email == "*****@*****.**"); User user3 = context.Users.First(a => a.Email == "*****@*****.**"); User user4 = context.Users.First(a => a.Email == "*****@*****.**"); User user5 = context.Users.First(a => a.Email == "*****@*****.**"); Exercise exercise = context.Exercises.First(a => a.Name == "Nek beweging"); Exercise exercise2 = context.Exercises.First(a => a.Name == "Arm spanning"); Exercise exercise3 = context.Exercises.First(a => a.Name == "Been strekking"); context.Add(new UserExercise { User = user, Exercise = exercise }); context.Add(new UserExercise { User = user, Exercise = exercise2 }); context.Add(new UserExercise { User = user, Exercise = exercise3 }); context.Add(new UserExercise { User = user2, Exercise = exercise }); context.Add(new UserExercise { User = user2, Exercise = exercise3 }); context.Add(new UserExercise { User = user3, Exercise = exercise }); context.Add(new UserExercise { User = user3, Exercise = exercise2 }); context.Add(new UserExercise { User = user4, Exercise = exercise }); context.Add(new UserExercise { User = user4, Exercise = exercise2 }); context.Add(new UserExercise { User = user5, Exercise = exercise2 }); context.Add(new UserExercise { User = user5, Exercise = exercise3 }); context.SaveChanges(); } if (!context.ExercisePlannings.Any()) { UserExercise userExercise = context.UserExercises.First(); context.Add(new ExercisePlanning { StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(5), Description = "Meneer Windt, houd rekening met het feit dat u deze oefening goed op de feedback van het systeem let!", Amount = 100, UserExercise = userExercise }); context.SaveChanges(); } if (!context.ExerciseSessions.Any()) { ExercisePlanning exercisePlanning = context.ExercisePlannings.First(); context.Add(new ExerciseSession { Date = DateTime.Now, IsComplete = true, ExercisePlanning = exercisePlanning }); context.Add(new ExerciseSession { Date = DateTime.Now.AddDays(1), IsComplete = true, ExercisePlanning = exercisePlanning }); context.Add(new ExerciseSession { Date = DateTime.Now.AddDays(2), IsComplete = true, ExercisePlanning = exercisePlanning }); context.Add(new ExerciseSession { Date = DateTime.Now.AddDays(3), IsComplete = true, ExercisePlanning = exercisePlanning }); context.Add(new ExerciseSession { Date = DateTime.Now.AddDays(4), IsComplete = false, ExercisePlanning = exercisePlanning }); context.Add(new ExerciseSession { Date = DateTime.Now.AddDays(5), IsComplete = false, ExercisePlanning = exercisePlanning }); context.SaveChanges(); } if (!context.ExerciseResults.Any()) { ExerciseSession exerciseSession = context.ExerciseSessions.First(); context.Add(new ExerciseResult { Duration = 10000, Score = 80, Result = new byte[8], ExerciseSession = exerciseSession }); context.SaveChanges(); } }