public async Task <IActionResult> GetFilterRequests(FilterIn filter) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <RequestOut> result; try { var requests = await _context.Requests.Where(req => (req.id_teacher == get_teacherId_from_adress(filter.adress))).Include(r => r.items) .ThenInclude(i => i.Item).ToListAsync(); if (requests.Count == 0) { return(BadRequest(new { errorText = "No requests in this school" })); } result = new List <RequestOut>(); foreach (Requests request in requests) { Teachers teacher = get_teacher_from_teacherId(request.id_teacher); Managers manager = get_manager_from_managerId(request.id_manager); result.Add(new RequestOut(request, manager.name + " " + manager.surname + " " + manager.lastname, teacher.name + " " + teacher.surname + " " + teacher.lastname)); } } catch (Exception e) { return(BadRequest(new { errorText = "No such school" })); } //"SELECT Requests.id_request, Requests.date, Requests.confirmed, Requests.date_confirmed, Requests.finished, Requests.date_finished, Requests.id_teacher, Requests.id_manager, Items.id_item, Items.name, Request_items.items_num FROM Requests, Request_items, Items WHERE Requests.id_request = Request_items.id_request AND Request_items.id_item = Items.id_item").ToListAsync(); return(Ok(result)); }
public async Task <IActionResult> GetSchools(FilterIn filter) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var schools = await _context.Schools.Where(sch => sch.adress == filter.adress).Include(s => s.items) //FromSqlRaw($"SELECT * FROM Schools WHERE Schools.adress = {filter.adress}") .ThenInclude(i => i.Item).ToListAsync(); if (schools.Count == 0) { return(BadRequest(new { errorText = "No such schools" })); } List <SchoolOut> result = new List <SchoolOut>(); foreach (Schools school in schools) { Teachers teacher = get_teacher_from_teacherId(school.id_teacher); Managers manager = get_manager_from_managerId(school.id_manager); result.Add(new SchoolOut(school, manager.name + " " + manager.surname + " " + manager.lastname, teacher.name + " " + teacher.surname + " " + teacher.lastname)); } return(Ok(result)); }