コード例 #1
0
        public async Task <PipelineItemModel> Create(AuthorizedDto <PipelineItemDto> dto)
        {
            return(await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    PipelineItemEntity pipelineItemEntity = dto.Data.ToModel <PipelineItemModel>().ToEntity <PipelineItemEntity>();
                    pipelineItemEntity.PipelineItemSettingsValues = null;

                    await db.GetRepo <PipelineItemEntity>().Create(pipelineItemEntity);
                    await db.Save();

                    PipelineItemPrefabEntity prefab = await db.GetRepo <PipelineItemPrefabEntity>().Get(pipelineItemEntity.pipeline_item_prefab_id);

                    RoleEntity ownerRole = await RoleService.GetCompanyOwnerRole(prefab.company_id, db);
                    ownerRole.PipelineItemPermissions.Add(pipelineItemEntity);

                    RoleEntity creatorRole = await RoleService.GetCompanyWorkerRole(dto.Session.UserId, db);
                    creatorRole?.PipelineItemPermissions.Add(pipelineItemEntity);

                    await db.Save();

                    return pipelineItemEntity.ToModel <PipelineItemModel>();
                }
            }));
        }
コード例 #2
0
        public async Task <PipelineItemModel> SetupDetector(AuthorizedDto <SetupDetectorDto> dto)
        {
            return(await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    DetectorEntity detector = await db.GetRepo <DetectorEntity>().FirstOrDefault(d => d.id == dto.Data.DetectorId.Value);
                    detector.pipeline_item_id = dto.Data.PipelineItemId.Value;

                    await db.Save();

                    PipelineItemEntity pipelineItemEntity = await db.GetRepo <PipelineItemEntity>().FirstOrDefault(
                        p => p.id == dto.Data.PipelineItemId.Value
                        );

                    return pipelineItemEntity.ToModel <PipelineItemModel>();
                }
            }));
        }
コード例 #3
0
        public async Task <PipelineItemModel> SetupSettings(AuthorizedDto <PipelineItemDto> dto)
        {
            return(await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    IRepo <PipelineItemEntity> pipelineItemRepo = db.GetRepo <PipelineItemEntity>();

                    PipelineItemEntity pipelineItemEntity = await pipelineItemRepo.FirstOrDefault(pi => pi.id == dto.Data.Id.Value);

                    PipelineItemInteractionEventEntity pipelineItemEvent = new PipelineItemInteractionEventEntity()
                    {
                        account_id = dto.Session.UserId,
                        pipeline_item_id = pipelineItemEntity.id,
                        timespan = DateTime.Now,
                        log = $"Settings setup for Pipeline Item #{pipelineItemEntity.id} by {dto.Session.UserId}"
                    };

                    await db.GetRepo <PipelineItemInteractionEventEntity>().Create(pipelineItemEvent);

                    foreach (PipelineItemSettingsValueDto settingsValueDto in dto.Data.SettingsValues)
                    {
                        if (settingsValueDto.Id.HasValue)
                        {
                            PipelineItemSettingsValueEntity settingsValueEntity = pipelineItemEntity.PipelineItemSettingsValues.First(
                                setting => setting.id == settingsValueDto.Id.Value
                                );

                            DataType dataType = settingsValueEntity.PipelineItemSettingsPrefab.DataType.name.FromName();
                            DataTypeService.CheckIsDataOfType(settingsValueDto.ValueBase64, dataType);

                            settingsValueEntity.option_data_value_base64 = settingsValueDto.ValueBase64;
                        }
                        else
                        {
                            PipelineItemSettingsPrefabEntity pipelineItemSettingsPrefab = pipelineItemEntity.PipelineItemPrefab.PipelineItemSettingsPrefabs.FirstOrDefault(
                                settingsPrefab => settingsPrefab.id == settingsValueDto.PrefabId.Value
                                );

                            if (pipelineItemSettingsPrefab == null)
                            {
                                throw new NotFoundException("PipelineItemSettingsPrefab");
                            }

                            DataType dataType = pipelineItemSettingsPrefab.DataType.name.FromName();
                            DataTypeService.CheckIsDataOfType(settingsValueDto.ValueBase64, dataType);

                            PipelineItemSettingsValueEntity settingWithSameSettingPrefab = pipelineItemEntity.PipelineItemSettingsValues.FirstOrDefault(
                                setting => setting.pipeline_item_settings_prefab_id == settingsValueDto.PrefabId.Value
                                );

                            if (settingWithSameSettingPrefab != null)
                            {
                                settingWithSameSettingPrefab.option_data_value_base64 = settingsValueDto.ValueBase64;
                            }
                            else
                            {
                                PipelineItemSettingsValueEntity settingsValueEntity = new PipelineItemSettingsValueEntity()
                                {
                                    pipeline_item_id = pipelineItemEntity.id,
                                    option_data_value_base64 = settingsValueDto.ValueBase64,
                                    pipeline_item_settings_prefab_id = settingsValueDto.PrefabId.Value
                                };

                                pipelineItemEntity.PipelineItemSettingsValues.Add(settingsValueEntity);
                            }
                        }
                    }

                    await db.Save();
                    return pipelineItemEntity.ToModel <PipelineItemModel>();
                }
            }));
        }