예제 #1
0
        public async Task <Result <List <ActionDto> > > Handle(GetActionsCrossPlantQuery request, CancellationToken cancellationToken)
        {
            _plantSetter.SetCrossPlantQuery();
            var projects = await
                               (from p in _context.QuerySet <Project>()
                               .Include(t => t.Tags)
                               .ThenInclude(t => t.Actions)
                               .ThenInclude(a => a.Attachments)
                               select p).ToListAsync(cancellationToken);

            _plantSetter.ClearCrossPlantQuery();

            var actions = new List <ActionDto>();

            foreach (var project in projects)
            {
                var plantTitle = await _plantCache.GetPlantTitleAsync(project.Plant);

                foreach (var tag in project.Tags.Where(t => t.Actions.Count > 0))
                {
                    foreach (var action in tag.Actions)
                    {
                        var actionDto = new ActionDto(
                            project.Plant,
                            plantTitle,
                            project.Name,
                            project.Description,
                            project.IsClosed,
                            tag.Id,
                            tag.TagNo,
                            action.Id,
                            action.Title,
                            action.Description,
                            action.IsOverDue(),
                            action.DueTimeUtc,
                            action.IsClosed,
                            action.Attachments.ToList().Count);
                        actions.Add(actionDto);
                    }
                }
            }

            var orderedActions = actions
                                 .OrderBy(a => a.PlantId)
                                 .ThenBy(a => a.ProjectName)
                                 .ThenBy(a => a.TagNo)
                                 .ThenBy(a => a.Title)
                                 .AsEnumerable();

            if (request.Max > 0)
            {
                orderedActions = orderedActions.Take(request.Max);
            }
            return(new SuccessResult <List <ActionDto> >(orderedActions.ToList()));
        }
예제 #2
0
        private async Task <List <TagDto> > CreateTagDtosAsync(List <Project> projects, List <RequirementType> requirementTypes)
        {
            var tagDtos = new List <TagDto>();

            foreach (var project in projects)
            {
                var plantTitle = await _plantCache.GetPlantTitleAsync(project.Plant);

                foreach (var tag in project.Tags)
                {
                    var requirementDtos = tag.OrderedRequirements().Select(
                        r =>
                    {
                        var requirementType =
                            requirementTypes.Single(rt =>
                                                    rt.RequirementDefinitions.Any(rd => rd.Id == r.RequirementDefinitionId));
                        var requirementDefinition =
                            requirementType.RequirementDefinitions.Single(rd =>
                                                                          rd.Id == r.RequirementDefinitionId);

                        return(new RequirementDto(
                                   r.Id,
                                   requirementType.Code,
                                   requirementDefinition.Title,
                                   r.NextDueTimeUtc,
                                   r.GetNextDueInWeeks(),
                                   r.IsReadyAndDueToBePreserved()));
                    })
                                          .ToList();
                    var actionStatus = GetActionStatus(tag.Actions);
                    var tagDto       = new TagDto(
                        project.Plant,
                        plantTitle,
                        project.Name,
                        project.Description,
                        project.IsClosed,
                        tag.Id,
                        actionStatus,
                        tag.AreaCode,
                        tag.AreaDescription,
                        tag.Calloff,
                        tag.CommPkgNo,
                        tag.Description,
                        tag.DisciplineCode,
                        tag.DisciplineDescription,
                        tag.IsVoided,
                        tag.McPkgNo,
                        tag.PurchaseOrderNo,
                        tag.IsReadyToBePreserved(),
                        requirementDtos,
                        tag.Status,
                        tag.StepId,
                        tag.TagFunctionCode,
                        tag.TagNo,
                        tag.TagType);
                    tagDtos.Add(tagDto);
                }
            }

            return(tagDtos);
        }