public async Task <ActionResult <List <DepartmentResult> > > Get(int departmentId) { List <DepartmentResult> result = new List <DepartmentResult>(); if (departmentId == 0 && IsSystem) { // Get All var departments = await _departmentsService.GetAllAsync(); foreach (var department in departments) { result.Add(await DepartmentToResult(department)); } return(Ok(result)); } else if (departmentId >= 1) { if (departmentId == DepartmentId) { var department = await _departmentsService.GetDepartmentByIdAsync(departmentId); result.Add(await DepartmentToResult(department)); return(Ok(result)); } else { return(Unauthorized()); } } else { return(BadRequest()); } }
public async Task <ActionResult <List <UnitResult> > > GetUnitsForDepartment(int departmentId) { var results = new List <UnitResult>(); if (departmentId != DepartmentId && !IsSystem) { return(Unauthorized()); } if (departmentId == 0 && IsSystem) { // Get All var departments = await _departmentsService.GetAllAsync(); foreach (var department in departments) { var units = await _unitsService.GetUnitsForDepartmentAsync(departmentId); foreach (var u in units) { var unitResult = new UnitResult(); unitResult.Id = u.UnitId; unitResult.DepartmentId = u.DepartmentId; unitResult.Name = u.Name; unitResult.Type = u.Type; unitResult.StationId = u.StationGroupId; unitResult.VIN = u.VIN; unitResult.PlateNumber = u.PlateNumber; unitResult.FourWheel = u.FourWheel; unitResult.SpecialPermit = u.SpecialPermit; results.Add(unitResult); } } return(results); } else { var units = await _unitsService.GetUnitsForDepartmentAsync(departmentId); foreach (var u in units) { var unitResult = new UnitResult(); unitResult.Id = u.UnitId; unitResult.DepartmentId = u.DepartmentId; unitResult.Name = u.Name; unitResult.Type = u.Type; unitResult.StationId = u.StationGroupId; unitResult.VIN = u.VIN; unitResult.PlateNumber = u.PlateNumber; unitResult.FourWheel = u.FourWheel; unitResult.SpecialPermit = u.SpecialPermit; results.Add(unitResult); } } return(Ok(results)); }