Esempio n. 1
0
        public async Task <CreateDataFormReturn> CreateDataFormAsync(string tenant, CreateDataformRequest dataform)
        {
            var entity = new DataForm
            {
                Description               = dataform.Description,
                Title                     = dataform.Title,
                Fields                    = dataform.Fields.Project().To <FieldConfiguration>().ToList(),
                Plugins                   = dataform.Plugins,
                AuthorizedClaims          = dataform.AuthorizedClaims as string[],
                DataSourceId              = dataform.DataSourceId,
                RestrictDataAccessByOwner = dataform.RestrictDataAccessByOwner
            };

            using (var session = _documentStore.OpenAsyncSession(tenant))
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(dataform.NewDataSourceName))
                    {
                        var factory = new DataSourceFactory(session);
                        entity.DataSourceId = (await factory.CreateDataSourceAsync(dataform.NewDataSourceName)).Id;
                    }

                    await session.StoreAsync(entity);

                    await session.SaveChangesAsync();

                    return(entity.Map().To <CreateDataFormReturn>());
                }
                catch (Exception)
                {
                    session.Dispose();
                    throw;
                }
            }
        }