public async Task TryInteract(PipelineItemInteractionDto dto)
        {
            await Execute(async() => {
                using (UnitOfWork db = new UnitOfWork())
                {
                    PipelineItemEntity pipelineItem = await db.GetRepo <PipelineItemEntity>().Get(dto.PipelineItemId.Value);
                    AccountEntity account           = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value);

                    PipelineItemInteractionEventEntity pipelineItemEvent = new PipelineItemInteractionEventEntity()
                    {
                        account_id       = account.id,
                        pipeline_item_id = pipelineItem.id,
                        timespan         = DateTime.Now
                    };

                    NotPermittedException ex = null;

                    if (account.Roles.SelectMany(r => r.PipelineItemPermissions).Any(m => m.id == pipelineItem.id))
                    {
                        pipelineItemEvent.log = $"Interaction with Pipeline item #{pipelineItem.id} by Account #{account.id}: SUCCESS";
                    }
                    else
                    {
                        pipelineItemEvent.log = $"Interaction with Pipeline item #{pipelineItem.id} by Account #{account.id}: ACCESS DENIED";
                        ex = new NotPermittedException(pipelineItemEvent.log);
                    }

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

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            });
        }
        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>();
                }
            }));
        }