Exemple #1
0
        public async Task <FileContentResult> ExportConfigurationsAsync(ExportConfigurationDto ids)
        {
            var fileName = "formConfigExport_" + DateTime.Now;
            var mimeType = "application/json";

            try
            {
                //Loop through the list of IDs,
                // for each ID get form configs from DB, then append to JSON
                var configList = new List <Dictionary <string, string> >();

                foreach (var id in ids.Components)
                {
                    var forms = await _formStore.GetAsync(id);

                    var configDictionary = new Dictionary <string, string>();
                    configDictionary.Add("Id", forms.Id.ToString());
                    configDictionary.Add("Path", forms.Path);
                    configDictionary.Add("Name", forms.Name);
                    configDictionary.Add("Description", forms.Description);
                    configDictionary.Add("Markup", forms.Markup);
                    configDictionary.Add("ModelType", forms.ModelType);
                    configDictionary.Add("Type", forms.Type);
                    configList.Add(configDictionary);
                }

                byte[] fileBytes = Encoding.ASCII.GetBytes(JsonSerializer.Serialize(configList));


                return(new FileContentResult(fileBytes, mimeType)
                {
                    FileDownloadName = fileName
                });
            }
            catch (Exception e)
            {
                Logger.Error("An error occurred", e);
                throw new Exception("An error occurred!");
            }
        }
Exemple #2
0
        public async Task <List <Dictionary <string, string> > > DeleteConfigurationsAsync([FromBody] ExportConfigurationDto ids)
        {
            var summary = new List <Dictionary <string, string> >();

            try
            {
                //Loop through the list of IDs
                foreach (var id in ids.Components)
                {
                    var deleteOutput = new Dictionary <string, string>();

                    string message = await _formStore.DeleteAsync(id);

                    deleteOutput.Add("Id", id.ToString());
                    deleteOutput.Add("Message", message);
                    summary.Add(deleteOutput);
                }

                return(summary);
            }
            catch (Exception e)
            {
                Logger.Error("An error occurred", e);
                throw new Exception("An error occurred!");
            }
        }