123456789101112131415161718192021222324252627282930313233343536 |
- 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> users = new List<Users>();
- List<Hobbies> hobbies = db.tbHobbies.Where(tb => tb.name == hobbie).ToList();
- List<UsersHobbies> 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);
- }
- }
- }
|