public async Task <string> AddWorkoutToClientList(string id, string userId) { var client = this.GetClient(userId); if (id == null) { return("invalid"); } if (!client.WorkoutsList.Any(x => x.ClientId == client.Id && x.WorkoutId == id)) { var workout = new WorkoutsList { WorkoutId = id, ClientId = client.Id }; await this.workoutClientsrepository.AddAsync(workout); await this.workoutClientsrepository.SaveChangesAsync(); return("added"); } return("contained"); }
private void DeleteWorkout(Workouts workout) { _workoutRepository.DeleteWorkout(workout.Workout_id); WorkoutsList.Remove(workout); }
public async Task DeleteShouldWorkCorrectlyWithExistingWorkoutInClientsList() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var client = new Client { Id = "client1", Name = "clientov", Phone = "088", HasBasketballExperience = true, PositionPlayed = PositionName.PowerForward, User = new ApplicationUser { Id = "clientUser" }, UserId = "clientUser", }; var workoutList = new WorkoutsList { ClientId = "client1", Client = client, WorkoutId = "w1", Workout = new Workout { Id = "w1", Name = "Workout One", Description = "Some kind of workout description", Position = new Position { Id = "PositionOne", Name = PositionName.ShootingGuard, Description = "Shooting guard position", Playstyle = "You play like a shooting guard", }, VideoUrl = "test youtube link", PositionId = "PositionOne", Picture = new Picture { Id = "pic", Url = "test url" }, PictureId = "pic", ImageUrl = "testimg", }, }; var clientsRepo = new EfDeletableEntityRepository <Client>(dbContext); var wlistRepo = new EfDeletableEntityRepository <WorkoutsList>(dbContext); var clientsDbService = new ClientsService(clientsRepo, wlistRepo); await dbContext.Clients.AddAsync(client); await dbContext.WorkoutsList.AddAsync(workoutList); await dbContext.SaveChangesAsync(); await clientsDbService.Delete("w1", "clientUser"); var result = wlistRepo.All().Where(x => x.ClientId == "client1") .FirstOrDefault(); Assert.Null(result); }