Пример #1
0
        public async Task ApplyAsync(BaseWorkflow workflow)
        {
            if (!(workflow is RequestWorkflow))
            {
                throw new ArgumentException(
                          $"The argument type: ${workflow.GetType()} is not {nameof(RequestWorkflow)}");
            }

            var requestWorkflow = (RequestWorkflow)workflow;

            requestWorkflow.DateUpdate = DateTimeOffset.Now;
            if (requestWorkflow.Id < 1)
            {
                requestWorkflow.DateCreate = DateTimeOffset.Now;
            }
            await _context.RequestWorkflows.AddAsync(requestWorkflow);

            var request = requestWorkflow.Owner ?? _context.Requests
                          .Include(r => r.ProtectionDocType).Include(r => r.Documents)
                          .ThenInclude(a => a.Document.Type).Include(r => r.CurrentWorkflow.CurrentStage)
                          .SingleOrDefault(r => r.Id == requestWorkflow.OwnerId);

            if (request == null)
            {
                throw new ApplicationException($"Workflow has incorrect request id: {requestWorkflow.OwnerId}");
            }
            var stage =
                await _context.DicRouteStages.SingleOrDefaultAsync(rs => rs.Id == requestWorkflow.CurrentStageId);

            CheckStage(request, stage);
            request.StatusId = stage?.RequestStatusId ?? request.StatusId;
            request.IsRead   = false;

            request.CurrentWorkflow   = requestWorkflow;
            request.CurrentWorkflowId = requestWorkflow.Id;
            request.DateUpdate        = DateTimeOffset.Now;

            request.IsComplete = workflow.IsComplete ?? request.IsComplete;
            _context.Requests.Update(request);
            _context.SaveChanges();
            await _taskRegister.RegisterAsync(request.Id);

            await _notificationSender.ProcessRequestAsync(request.Id);
        }
Пример #2
0
        public async Task ApplyAsync(BaseWorkflow workflow)
        {
            if (!(workflow is ProtectionDocWorkflow))
            {
                throw new ArgumentException(
                          $"The argument type: ${workflow.GetType()} is not {nameof(ProtectionDocWorkflow)}");
            }

            var protectionDocWorkflow = (ProtectionDocWorkflow)workflow;

            protectionDocWorkflow.DateUpdate = DateTimeOffset.Now;
            if (protectionDocWorkflow.Id < 1)
            {
                protectionDocWorkflow.DateCreate = DateTimeOffset.Now;
            }
            await _context.ProtectionDocWorkflows.AddAsync(protectionDocWorkflow);

            var protectionDoc = protectionDocWorkflow.Owner ?? _context.ProtectionDocs
                                .Include(r => r.Type)
                                .SingleOrDefault(r => r.Id == protectionDocWorkflow.OwnerId);

            if (protectionDoc == null)
            {
                throw new ApplicationException($"Workflow has incorrect request id: {protectionDocWorkflow.OwnerId}");
            }
            var stage = await _context.DicRouteStages.SingleOrDefaultAsync(rs => rs.Id == protectionDocWorkflow.CurrentStageId);

            protectionDoc.StatusId = stage?.ProtectionDocStatusId ?? protectionDoc.StatusId;

            protectionDoc.CurrentWorkflow   = protectionDocWorkflow;
            protectionDoc.CurrentWorkflowId = protectionDocWorkflow.Id;
            protectionDoc.DateUpdate        = DateTimeOffset.Now;

            _context.ProtectionDocs.Update(protectionDoc);
            await _context.SaveChangesAsync();

            await _notificationSender.ProcessRequestAsync(protectionDoc.Id);
        }