示例#1
0
        public async Task <Guid> AddAsync(SummaryDocument doc)
        {
            var existing = await TryGetSummaryEntityForInspectionAsync(doc.InspectionId);

            if (existing != null)
            {
                throw ItemAlreadyExistsException.MatchingEntityExists("RusHydroPsaSummary", existing.Id);
            }
            if (doc.Id == Guid.Empty)
            {
                doc.Id = Guid.NewGuid();
            }
            var shiftAbsIndex = WorkingShiftAbsoluteIndex.GetAbsoluteIndex(doc.CompletionTime.LocalDateTime);
            var deptReportId  = DepartmentShiftReportIdBuilder.BuildReportId(doc.DepartmentId, shiftAbsIndex);
            var summary       = new Summary
            {
                Id = doc.Id,
                DepartmentShiftReportId = deptReportId,
                ShiftAbsoluteIndex      = shiftAbsIndex,
                BranchOfficeId          = doc.BranchOfficeId,
                CompletionTime          = doc.CompletionTime,
                DepartmentId            = doc.DepartmentId,
                EmployeeId      = doc.Employee.Id,
                InspectionId    = doc.InspectionId,
                SummaryDocument = doc,
                TenantId        = _tenantIdProvider.GetTenantId(),
                UpdateDate      = doc.UpdateDate
            };

            _psaSummaryRepository.Add(summary);
            await _psaSummaryRepository.SaveChangesAsync();

            return(summary.Id);
        }
示例#2
0
        public Task <List <SummaryDocument> > GetSummariesInDepartmentForShift(Guid departmentId, long absoluteShiftIndex)
        {
            var depShiftReportId = DepartmentShiftReportIdBuilder.BuildReportId(departmentId, absoluteShiftIndex);

            return(_psaSummaryRepository.Query()
                   .Where(s => s.DepartmentShiftReportId == depShiftReportId)
                   .Select(s => s.SummaryDocument).ToListAsync());
        }