public async Task ExecuteAsync(MaterialWorkflowDto workflowDto)
        {
            //var workflow = Mapper.Map<DocumentWorkflow>(workflowDto);
            var workflowRepo = Uow.GetRepository <DocumentWorkflow>();
            var workflow     = await workflowRepo.GetByIdAsync(workflowDto.Id);

            workflow.CurrentUserId = workflowDto.CurrentUserId;
            workflowRepo.Update(workflow);
            await Uow.SaveChangesAsync();

            ////var workflowWithIncludes = await Executor.GetQuery<GetWorkflowsByDocumentIdQuery>()
            ////    .Process(q => q.ExecuteAsync(workflowId));

            ////var result = Mapper.Map<MaterialWorkflowDto>(workflow);
        }
Beispiel #2
0
        public async Task <MaterialWorkflowDto> ExecuteAsync(MaterialWorkflowDto workflowDto, bool isPrevious = false)
        {
            var workflow   = Mapper.Map <DocumentWorkflow>(workflowDto);
            int workflowId = await Executor.GetCommand <ApplyDocumentWorkflowCommand>()
                             .Process(c => c.ExecuteAsync(workflow, isPrevious));

            await Executor.GetHandler <ProcessWorkflowByDocumentIdHandler>().Process(r => r.ExecuteAsync(workflowDto.OwnerId ?? default(int)));

            var workflowWithIncludes = await Executor.GetQuery <GetWorkflowsByDocumentIdQuery>()
                                       .Process(q => q.ExecuteAsync(workflowId));

            var result = Mapper.Map <MaterialWorkflowDto>(workflowWithIncludes);

            if (LastStageCodes.Contains(workflowDto.CurrentStageCode))
            {
                var workStatus = Executor.GetQuery <GetDocumentStatusByCodeQuery>().Process(q => q.Execute(DicDocumentStatusCodes.Completed));
                var document   = await Executor.GetQuery <GetDocumentByIdQuery>().Process(q => q.ExecuteAsync(workflow.OwnerId));

                document.StatusId = workStatus.Id;
                await Executor.GetCommand <UpdateDocumentCommand>().Process(c => c.Execute(document));
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Метод для автоматичесскиго перехода на этап в зависимости от конфигураций
        /// </summary>
        /// <param name="documentId">Id Документа</param>
        /// <returns>Создание Workflow</returns>
        public async Task <IList <MaterialWorkflowDto> > StartAutuRouteStage(int documentId, bool isSimpleWf = false)
        {
            var documentWorkflow = _unitOfWork.GetRepository <DocumentWorkflow>();
            var document         = _unitOfWork.GetRepository <Document>()
                                   .AsQueryable()
                                   .Include(cw => cw.Requests).ThenInclude(cw => cw.Request)
                                   .ThenInclude(cw => cw.CurrentWorkflow)
                                   .Include(cw => cw.Workflows)
                                   .Include(cw => cw.Type)
                                   .FirstOrDefault(d => d.Id == documentId);

            if (document == null)
            {
                return(null);
            }

            var currentUserId = NiisAmbientContext.Current.User.Identity.UserId;

            var currentWorkflow = document.CurrentWorkflows.FirstOrDefault(d => d.CurrentUserId == currentUserId);

            if (currentWorkflow == null)
            {
                if (isSimpleWf)
                {
                    currentWorkflow = document.CurrentWorkflows.FirstOrDefault();
                }
                else
                {
                    return(null);
                }
            }
            if (currentWorkflow == null)
            {
                return(null);
            }

            //Загружаем автопереходы связанные с текущим этапом(должен быть один)
            var autoRouteStages = _unitOfWork.GetRepository <AutoRouteStage>()
                                  .AsQueryable()
                                  .Include(d => d.AutoRouteStageEvents)
                                  .Include(d => d.NextStage)
                                  .Include(cw => cw.AutoRouteStageViewers)
                                  .Where(d => d.CurrentStageId == currentWorkflow.CurrentStageId &&
                                         d.AutoRouteStageEvents.Any(e => e.TypeId == document.TypeId))
                                  .ToList();

            if (!autoRouteStages.Any())
            {
                return(null);
            }

            var nextStages = new List <MaterialWorkflowDto>();

            foreach (var autoRouteStage in autoRouteStages)
            {
                //Берем Тип документа и Должность для перехода(должен быть один)
                var stageEvent = autoRouteStage.AutoRouteStageEvents
                                 .Where(d => d.TypeId == document.TypeId);
                if (!stageEvent.Any())
                {
                    continue;
                }

                var autoExecutor = _unitOfWork.GetRepository <ApplicationUser>()
                                   .AsQueryable()
                                   .FirstOrDefault(d => d.PositionId == stageEvent.FirstOrDefault().PositionId&& d.IsDeleted == false);
                if (autoExecutor == null)
                {
                    continue;
                }

                var workflowDto = new MaterialWorkflowDto()
                {
                    OwnerId                 = document.Id,
                    IsCurent                = true,
                    DateCreate              = DateTimeOffset.Now,
                    FromStageId             = currentWorkflow.CurrentStageId,
                    PreviousWorkflowId      = currentWorkflow.Id,
                    CurrentStageId          = autoRouteStage.NextStageId,
                    FromUserId              = currentWorkflow.CurrentUserId,
                    CurrentUserId           = autoExecutor.Id,
                    CurrentUserDepartmentId = autoExecutor.DepartmentId,
                    IsComplete              = autoRouteStage.NextStage.IsLast,
                    RouteId                 = currentWorkflow.RouteId,
                };

                var result = await Executor.GetHandler <CreateMaterialWorkFlowHandler>().Process(r => r.ExecuteAsync(workflowDto));

                nextStages.Add(result);
            }
            if (!nextStages.Any())
            {
                return(null);
            }

            return(nextStages);
        }
Beispiel #4
0
        public async Task <IActionResult> Post([FromBody] MaterialWorkflowDto workflowDto)
        {
            var result = await _mediator.Send(new WorkflowCreate.Command(workflowDto, User.Identity.GetUserId()));

            return(Ok(result));
        }