GetAllWorkoutForTraining.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using ApiMobileBelov.BaseConnection;
  2. using ApiMobileBelov.ModelBase;
  3. using Microsoft.AspNetCore.Mvc;
  4. namespace ApiMobileBelov.Controllers
  5. {
  6. [Route("api/[controller]/{idCategory}/{idTraining}")]
  7. [ApiController]
  8. [ApiExplorerSettings(GroupName = "Упражнения")]
  9. public class GetAllWorkoutForTraining : ControllerBase
  10. {
  11. ApplicationContext db = new ApplicationContext();
  12. [HttpGet]
  13. public IActionResult Index(int idCategory, int idTraining)
  14. {
  15. var allWorkouts = db.tableWorkout.ToList();
  16. var item = db.tableCategoryAndTraining.FirstOrDefault(x=>x.IdTraining == idTraining && x.IdCategory == idCategory);
  17. var allItems = db.tableCategoryAndTrainingAndWorkout.ToList();
  18. var obj = allItems.Where(x=>x.IdCategoryAndTraining == item.IdCategoryAndTraining).ToList();
  19. List<Workout> workouts = new List<Workout>();
  20. foreach (var a in obj)
  21. {
  22. var element = allWorkouts.FirstOrDefault(x => x.IdWorkout == a.IdWorkout);
  23. if (element != null)
  24. {
  25. workouts.Add(element);
  26. }
  27. }
  28. return Ok(workouts);
  29. }
  30. }
  31. }