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