Adding two more non-crud queries
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using WD7UVN_HFT_2023241.Logic;
|
||||||
|
using System.Linq;
|
||||||
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
|
namespace WD7UVN_HFT_2023241.Endpoint
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/WhoIsResponsibleForService")]
|
||||||
|
public class WhoIsReponsibleForServiceController : ControllerBase
|
||||||
|
{
|
||||||
|
public ILogicServices LogicServices { get; set; }
|
||||||
|
|
||||||
|
public WhoIsReponsibleForServiceController(ILogicServices LogicServices)
|
||||||
|
{
|
||||||
|
this.LogicServices = LogicServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public Employee WhoIsResponsibleForService([FromQuery] int id)
|
||||||
|
{
|
||||||
|
return LogicServices.WhoIsResponsibleForService(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using WD7UVN_HFT_2023241.Logic;
|
||||||
|
using System.Linq;
|
||||||
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
|
namespace WD7UVN_HFT_2023241.Endpoint
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/WhoMaintainsService")]
|
||||||
|
public class WhoMaintainsServiceController : ControllerBase
|
||||||
|
{
|
||||||
|
public ILogicServices LogicServices { get; set; }
|
||||||
|
|
||||||
|
public WhoMaintainsServiceController(ILogicServices LogicServices)
|
||||||
|
{
|
||||||
|
this.LogicServices = LogicServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IQueryable<Customer> WhoUsesService([FromQuery] int id)
|
||||||
|
{
|
||||||
|
return LogicServices.WhoUsesService(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ namespace WD7UVN_HFT_2023241.Logic
|
|||||||
public IQueryable<Employee> WhoWorksInMaintainerTeam(int maintainerTeamId);
|
public IQueryable<Employee> WhoWorksInMaintainerTeam(int maintainerTeamId);
|
||||||
public IQueryable<Employee> GetSubordinates(int managerId);
|
public IQueryable<Employee> GetSubordinates(int managerId);
|
||||||
public IQueryable<Customer> WhoUsesService(int serviceId);
|
public IQueryable<Customer> WhoUsesService(int serviceId);
|
||||||
|
public Employee WhoIsResponsibleForService(int serviceId);
|
||||||
|
public IQueryable<Employee> WhoMaintainsService(int serviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LogicServices : ILogicServices
|
public class LogicServices : ILogicServices
|
||||||
@@ -24,7 +26,30 @@ namespace WD7UVN_HFT_2023241.Logic
|
|||||||
this.CRUDOperations = CRUDOperations;
|
this.CRUDOperations = CRUDOperations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<Employee> WhoWorksInMaintainerTeam(int maintainerTeamId)
|
public IQueryable<Employee> WhoMaintainsService(int serviceId)
|
||||||
|
{
|
||||||
|
IQueryable<Employee> query =
|
||||||
|
from employee in CRUDOperations.ReadAllEmployees()
|
||||||
|
join service in CRUDOperations.ReadAllServices() on employee.MAINTAINER_ID equals service.MAINTAINER_ID
|
||||||
|
where service.ID == serviceId
|
||||||
|
select employee;
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Employee WhoIsResponsibleForService(int serviceId)
|
||||||
|
{
|
||||||
|
var query =
|
||||||
|
from service in CRUDOperations.ReadAllServices()
|
||||||
|
join team in CRUDOperations.ReadAllMaintainerTeams() on service.MAINTAINER_ID equals team.ID
|
||||||
|
join employee in CRUDOperations.ReadAllEmployees() on team.LEADER_ID equals employee.ID
|
||||||
|
where service.ID == serviceId
|
||||||
|
select employee;
|
||||||
|
|
||||||
|
return query.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<Employee> WhoWorksInMaintainerTeam(int maintainerTeamId)
|
||||||
{
|
{
|
||||||
return CRUDOperations
|
return CRUDOperations
|
||||||
.ReadAllEmployees()
|
.ReadAllEmployees()
|
||||||
|
|||||||
Reference in New Issue
Block a user