Esempio n. 1
0
        public async Task UpdateDataFormAsync(string tenant, string id, UpdateDataformRequest dataform)
        {
            using (var session = _documentStore.OpenAsyncSession(tenant))
            {
                var doc = await session.LoadAsync <DataForm>(id);

                if (doc == null)
                {
                    return;
                }

                doc.Description               = dataform.Description;
                doc.Title                     = dataform.Title;
                doc.Fields                    = new List <FieldConfiguration>(dataform.Fields.Project().To <FieldConfiguration>());
                doc.Plugins                   = dataform.Plugins;
                doc.Components                = dataform.Components;
                doc.AuthorizedClaims          = dataform.AuthorizedClaims?.ToArray() ?? new string[0];
                doc.DataSourceId              = dataform.DataSourceId;
                doc.RestrictDataAccessByOwner = dataform.RestrictDataAccessByOwner;

                if (!string.IsNullOrWhiteSpace(dataform.NewDataSourceName))
                {
                    var factory = new DataSourceFactory(session);
                    doc.DataSourceId = (await factory.CreateDataSourceAsync(dataform.NewDataSourceName)).Id;
                }

                await session.SaveChangesAsync();
            }
        }
Esempio n. 2
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;
                }
            }
        }