コード例 #1
0
        private async Task <List <DataPointConfigurationDTO> > GetProjectDataPointConfigurationsAsync(int projectId)
        {
            var dataPointConfigurations = await Context.DataPointCategoryProperties.Select(x => new DataPointConfigurationDTO
            {
                CategoryPropertyId = x.DataPointCategoryPropertyId,
                ProjectId          = projectId,
                CategoryId         = x.DataPointCategoryId,
                CategoryName       = x.DataPointCategory.DataPointCategoryName,
                PropertyId         = x.DataPointPropertyId,
                PropertyName       = x.DataPointProperty.DataPointPropertyName,
                IsRequired         = false,
                IsInherited        = false
            }).ToListAsync();

            var project = Context.Projects.Where(x => x.ProjectId == projectId).FirstOrDefault();

            var parentOfficeIds = await GetParentOfficeIds(project.ParentProgram.OwnerId);

            parentOfficeIds.Add(project.ParentProgram.OwnerId);

            var parentProgramIds = await GetParentProgramIds(project.ParentProgram.ProgramId);

            parentProgramIds.Add(project.ParentProgram.ProgramId);

            var parentDataPointConfigurations = DataPointConfigurationQueries.CreateGetDataPointConfigurations(this.Context)
                                                .Where(x => parentOfficeIds.Contains(x.OfficeId.Value) || parentProgramIds.Contains(x.ProgramId.Value)).ToList();

            foreach (var config in parentDataPointConfigurations)
            {
                var temp = dataPointConfigurations.Where(x => x.CategoryPropertyId == config.CategoryPropertyId).FirstOrDefault();
                temp.DataPointConfigurationId = config.DataPointConfigurationId;
                temp.IsRequired  = true;
                temp.IsInherited = true;
            }

            var childDataPointConfigurations = DataPointConfigurationQueries.CreateGetDataPointConfigurations(this.Context)
                                               .Where(x => x.ProjectId == projectId).ToList();

            foreach (var config in childDataPointConfigurations)
            {
                var temp = dataPointConfigurations.Where(x => x.CategoryPropertyId == config.CategoryPropertyId).FirstOrDefault();
                if (temp.DataPointConfigurationId == null)
                {
                    temp.DataPointConfigurationId = config.DataPointConfigurationId;
                    temp.IsRequired = true;
                }
            }

            return(dataPointConfigurations);
        }
コード例 #2
0
        private async Task <List <DataPointConfigurationDTO> > GetOfficeDataPointConfigurationsAsync(int officeId)
        {
            // Get available properties
            var dataPointConfigurations = await Context.DataPointCategoryProperties.Select(x => new DataPointConfigurationDTO
            {
                CategoryPropertyId = x.DataPointCategoryPropertyId,
                OfficeId           = officeId,
                CategoryId         = x.DataPointCategoryId,
                CategoryName       = x.DataPointCategory.DataPointCategoryName,
                PropertyId         = x.DataPointPropertyId,
                PropertyName       = x.DataPointProperty.DataPointPropertyName,
                IsRequired         = false,
                IsInherited        = false
            }).ToListAsync();

            // Get parent office data configs
            var parentOfficeIds = await GetParentOfficeIds(officeId);

            var parentDataPointConfigurations = DataPointConfigurationQueries.CreateGetDataPointConfigurations(this.Context)
                                                .Where(x => parentOfficeIds.Contains(x.OfficeId.Value)).ToList();

            foreach (var config in parentDataPointConfigurations)
            {
                var temp = dataPointConfigurations.Where(x => x.CategoryPropertyId == config.CategoryPropertyId).FirstOrDefault();
                temp.DataPointConfigurationId = config.DataPointConfigurationId;
                temp.IsRequired  = true;
                temp.IsInherited = true;
            }

            // Get child office data configs
            var childDataPointConfigurations = DataPointConfigurationQueries.CreateGetDataPointConfigurations(this.Context)
                                               .Where(x => x.OfficeId == officeId).ToList();

            foreach (var config in childDataPointConfigurations)
            {
                var temp = dataPointConfigurations.Where(x => x.CategoryPropertyId == config.CategoryPropertyId).FirstOrDefault();
                if (temp.DataPointConfigurationId == null)
                {
                    temp.DataPointConfigurationId = config.DataPointConfigurationId;
                    temp.IsRequired = true;
                }
            }

            return(dataPointConfigurations);
        }