public void Show(ConfigurationEntryModel model)
 {
     ConfigurationEntry = model;
     Title      = ConfigurationEntry.Id == Guid.Empty ? "Add" : "Edit";
     ShowDialog = true;
     StateHasChanged();
 }
Exemple #2
0
        public async void ConfirmedAddEdit(ConfigurationEntryModel model)
        {
            await(model.Id == Guid.Empty
                ? ConfigurationEntryService.CreateAsync(model)
                : ConfigurationEntryService.UpdateAsync(model));
            AddEditDialog.Close();
            ConfigurationEntries = await ConfigurationEntryService.GetListAsync();

            StateHasChanged();
        }
Exemple #3
0
        public async Task AllInOne_SensiveValue()
        {
            await GetTokenAsync();

            // POST
            var model = new ConfigurationEntryModel
            {
                Key         = $"KEY_{Guid.NewGuid()}",
                Value       = "VALUE1",
                Description = "Description",
                IsSensitive = true,
            };

            var created = await CreateAsync(model);

            Assert.True(model.Id != created.Id);
            Assert.Equal(model.Key, created.Key);
            Assert.NotEqual("VALUE1", created.Value);
            Assert.Equal(model.Description, created.Description);

            // GET
            var list = await GetListAsync();

            Assert.True(list.Count > 0);

            // GET ONE
            var refreshed = await GetByIdAsync(created.Id);

            Assert.Equal(refreshed.Id, created.Id);
            Assert.Equal(refreshed.Key, created.Key);
            Assert.Equal(refreshed.Value, created.Value);
            Assert.Equal(refreshed.Description, created.Description);

            // PUT
            refreshed.Value = "VALUE2";
            var updated = await UpdateAsync(refreshed.Id, refreshed);

            Assert.Equal(refreshed.Id, updated.Id);
            Assert.NotEqual("VALUE2", updated.Value);
            Assert.Equal(refreshed.Description, updated.Description);

            // PUT
            refreshed.Value       = "VALUE3";
            refreshed.IsSensitive = false;
            updated = await UpdateAsync(refreshed.Id, refreshed);

            Assert.Equal(refreshed.Id, updated.Id);
            Assert.Equal("VALUE3", updated.Value);
            Assert.Equal(refreshed.Description, updated.Description);

            // DELETE
            await DeleteAsync(created.Id);

            await Assert.ThrowsAsync <HttpRequestException>(async() => await GetByIdAsync(created.Id));
        }
Exemple #4
0
 protected void EditSetting(ConfigurationEntryModel model)
 {
     AddEditDialog.Show(new ConfigurationEntryModel
     {
         Id          = model.Id,
         Key         = model.Key,
         Value       = model.IsSensitive ? string.Empty : model.Value,
         Description = model.Description,
         IsSensitive = model.IsSensitive,
     });
 }
Exemple #5
0
        public async Task <ActionResult <ConfigurationEntryModel> > Post([FromBody] ConfigurationEntryModel model)
        {
            var entity = model.ToEntity();

            if (entity.IsSensitive)
            {
                var cert      = _moduleOptions.Certificates.SettingsEncryption.FindCertificate();
                var encrypted = entity.Value.UseRSA(cert).Encrypt().ToBase64String();
                entity.Value = encrypted;
            }

            await _dispatcher.DispatchAsync(new AddOrUpdateEntityCommand <ConfigurationEntry>(entity));

            model = entity.ToModel();
            return(Created($"/api/ConfigurationEntries/{model.Id}", model));
        }
Exemple #6
0
        public async Task <ActionResult> Put(Guid id, [FromBody] ConfigurationEntryModel model)
        {
            var entity = await _dispatcher.DispatchAsync(new GetEntityByIdQuery <ConfigurationEntry> {
                Id = id, ThrowNotFoundIfNull = true
            });

            entity.Key         = model.Key;
            entity.Value       = model.Value;
            entity.Description = model.Description;
            entity.IsSensitive = model.IsSensitive;

            if (entity.IsSensitive)
            {
                var cert      = _moduleOptions.Certificates.SettingsEncryption.FindCertificate();
                var encrypted = entity.Value.UseRSA(cert).Encrypt().ToBase64String();
                entity.Value = encrypted;
            }

            await _dispatcher.DispatchAsync(new AddOrUpdateEntityCommand <ConfigurationEntry>(entity));

            model = entity.ToModel();

            return(Ok(model));
        }
Exemple #7
0
 protected void DeleteSetting(ConfigurationEntryModel model)
 {
     DeletingConfigurationEntry = model;
     DeleteDialog.Show();
 }
Exemple #8
0
        public async Task AllInOne_NonSensiveValue()
        {
            await GetTokenAsync();

            // POST
            var model = new ConfigurationEntryModel
            {
                Key         = $"KEY_{Guid.NewGuid()}",
                Value       = "VALUE1",
                Description = "Description",
            };

            var created = await CreateAsync(model);

            Assert.True(model.Id != created.Id);
            Assert.Equal(model.Key, created.Key);
            Assert.Equal("VALUE1", created.Value);
            Assert.Equal(model.Description, created.Description);

            // GET
            var list = await GetListAsync();

            Assert.True(list.Count > 0);

            // GET ONE
            var refreshed = await GetByIdAsync(created.Id);

            Assert.Equal(refreshed.Id, created.Id);
            Assert.Equal(refreshed.Key, created.Key);
            Assert.Equal(refreshed.Value, created.Value);
            Assert.Equal(refreshed.Description, created.Description);

            // PUT
            refreshed.Value = "VALUE2";
            var updated = await UpdateAsync(refreshed.Id, refreshed);

            Assert.Equal(refreshed.Id, updated.Id);
            Assert.Equal("VALUE2", updated.Value);
            Assert.Equal(refreshed.Description, updated.Description);

            // PUT
            refreshed.Value       = "VALUE3";
            refreshed.IsSensitive = true;
            updated = await UpdateAsync(refreshed.Id, refreshed);

            Assert.Equal(refreshed.Id, updated.Id);
            Assert.NotEqual("VALUE3", updated.Value);
            Assert.Equal(refreshed.Description, updated.Description);

            var path = Path.Combine(AppSettings.DownloadsFolder, "Practical.CleanArchitecture", Guid.NewGuid().ToString());

            Directory.CreateDirectory(path);

            // EXPORT Excel
            await ExportAsExcelAsync(path, "ConfigurationEntries.xlsx");

            Assert.True(File.Exists(Path.Combine(path, "ConfigurationEntries.xlsx")));

            // IMPORT Excel
            var importingEntries = await ImportExcelAsync(Path.Combine(path, "ConfigurationEntries.xlsx"));

            Assert.True(importingEntries.Count > 0);

            // DELETE
            await DeleteAsync(created.Id);

            await Assert.ThrowsAsync <HttpRequestException>(async() => await GetByIdAsync(created.Id));
        }
Exemple #9
0
 private async Task <ConfigurationEntryModel> UpdateAsync(Guid id, ConfigurationEntryModel model)
 {
     return(await PutAsync <ConfigurationEntryModel>($"api/ConfigurationEntries/{id}", model));
 }
Exemple #10
0
 private async Task <ConfigurationEntryModel> CreateAsync(ConfigurationEntryModel model)
 {
     return(await PostAsync <ConfigurationEntryModel>("api/ConfigurationEntries", model));
 }
        public async Task <ConfigurationEntryModel> UpdateAsync(ConfigurationEntryModel entry)
        {
            var updatedEntry = await PutAsync <ConfigurationEntryModel>($"api/ConfigurationEntries/{entry.Id}", entry);

            return(updatedEntry);
        }
        public async Task <ConfigurationEntryModel> CreateAsync(ConfigurationEntryModel entry)
        {
            var createdEntry = await PostAsync <ConfigurationEntryModel>($"api/ConfigurationEntries", entry);

            return(createdEntry);
        }