12345678910111213141516171819202122232425262728293031323334353637 |
- 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> hobbies = new List<Hobbies>();
- List<Users> users = db.tbUsers.Where(tb => tb.lastName == surname && tb.firstName == name).ToList();
- List<UsersHobbies> 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);
- }
- }
- }
|