private async Task <TestData> GetTestDataAsync(Guid inspectionId)
        {
            var inspection = await _inspectionService.GetInspectionWithTestsAsync(inspectionId);

            var hrvTest = inspection.Tests
                          .Where(t => t.MethodId == HrvMethodId.MethodId).FirstOrDefault();
            var svmrTest = inspection.Tests
                           .Where(t => t.MethodId == SvmrMethodId.MethodId).FirstOrDefault();

            if (hrvTest == null)
            {
                _logger.LogWarning($"Could not find HRV test data in the inspection '{inspectionId}'");
                return(null);
            }
            if (svmrTest == null)
            {
                _logger.LogWarning($"Could not find SVMR test data in the inspection '{inspectionId}'");
                return(null);
            }
            var hrvRawData  = JObject.Parse(hrvTest.MethodRawDataJson).ToObject <HrvRawData>();
            var svmrRawData = JObject.Parse(svmrTest.MethodRawDataJson).ToObject <SvmrRawData>();

            var pskEmp = await _orgStructRef.GetEmployeeAsync(inspection.EmployeeId);

            var branch = await _orgStructRef.GetBranchOfficeAsync(pskEmp.BranchOfficeId);

            var dept = await _orgStructRef.GetDepartmentAsync(pskEmp.DepartmentId);

            var pos = await _orgStructRef.GetPositionAsync(pskEmp.PositionId);

            var rhEmp = new RusHydro.ObjectModel.Employee
            {
                Id               = pskEmp.Id,
                FullName         = pskEmp.FullName,
                ExternalId       = pskEmp.ExternalId,
                BranchOfficeName = branch?.Name,
                BranchOfficeId   = pskEmp.BranchOfficeId,
                DepartmentName   = dept?.Name,
                DepartmentId     = pskEmp.DepartmentId,
                PositionName     = pos?.Name,
                PositionId       = pskEmp.PositionId,
            };

            hrvRawData.TestInfo.TestId  = hrvTest.Id;
            svmrRawData.TestInfo.TestId = svmrTest.Id;

            return(new TestData
            {
                Employee = rhEmp,
                Inspection = inspection,
                HrvRawData = hrvRawData,
                SvmrRawData = svmrRawData
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// returns a tuple of a department and its parent branch office
        /// throws ItemNotFoundException if any of the two is not found
        /// throws UnauthorizedAccessException if any of the two don't belong to the proper tenant
        /// </summary>
        /// <param name="departmentId"></param>
        /// <returns></returns>
        private async Task <Tuple <Department, BranchOffice> > GetOrgStructureItemsAsync(Guid departmentId)
        {
            var dept = await _orgStructReference.GetDepartmentAsync(departmentId);

            if (dept == null)
            {
                throw ItemNotFoundException.NotFoundByKey("Id", departmentId.ToString(), nameof(Department));;
            }
            await _tenantEntityAccessChecker.ValidateAccessToEntityAsync(dept, Shared.Permissions.EntityAction.Read);

            var branch = await _orgStructReference.GetBranchOfficeAsync(dept.BranchOfficeId);

            if (branch == null)
            {
                throw ItemNotFoundException.NotFoundByKey("Id", dept.BranchOfficeId.ToString(), nameof(BranchOffice));;
            }
            await _tenantEntityAccessChecker.ValidateAccessToEntityAsync(branch, Shared.Permissions.EntityAction.Read);

            return(Tuple.Create(dept, branch));
        }