using System; using System.Linq; using WD7UVN_HFT_2023241.Models; using WD7UVN_HFT_2023241.Repository; namespace WD7UVN_HFT_2023241.Logic { public interface ILogicServices { public ICRUD CRUDOperations { get; set; } //additional, non-CRUD operations public IQueryable WhoWorksInMaintainerTeam(int maintainerTeamId); public IQueryable GetSubordinates(int managerId); public IQueryable WhoUsesService(int serviceId); public Employee WhoIsResponsibleForService(int serviceId); public IQueryable WhoMaintainsService(int serviceId); } public class LogicServices : ILogicServices { public ICRUD CRUDOperations { get; set; } public LogicServices(ICRUD CRUDOperations) { this.CRUDOperations = CRUDOperations; } public IQueryable WhoMaintainsService(int serviceId) { IQueryable 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 WhoWorksInMaintainerTeam(int maintainerTeamId) { return CRUDOperations .ReadAllEmployees() .Where(e => e.MAINTAINER_ID == maintainerTeamId); } public IQueryable GetSubordinates(int managerId) { return CRUDOperations .ReadAllEmployees() .Where(e => e.MANAGER_ID == managerId); } public IQueryable WhoUsesService(int serviceId) { return CRUDOperations .ReadAllCustomers() .Where(c => c.SERVICE_ID == serviceId); } } }