using Microsoft.AspNetCore.Mvc; namespace API_development.Controllers { [Route("/api/[controller]")] [ApiController] [ApiExplorerSettings(GroupName = "Хобби пользователя")] public class HobbiUsersController : ControllerBase { ApplicationContext db = new ApplicationContext(); [HttpGet] public IActionResult Index(string hobbie) { List users = new List(); List hobbies = db.tbHobbies.Where(tb => tb.name == hobbie).ToList(); List usersHobbies = db.tbUserHobbies.ToList(); foreach (UsersHobbies elem in usersHobbies) { foreach (Hobbies hobbi in hobbies) { if (elem.idHobbi == hobbi.idHobbi) { Users user = db.tbUsers.Where(tb => tb.idUsers == elem.idUser).FirstOrDefault(); if (user != null) { users.Add(user); } } } } return Ok(users); } } }