public async Task CreateForm([FromBody] FormTemplateCreateInputDto input) { if (!input.IsValid()) { throw new ArgumentException(@"Form template is invalid."); } var formTemplate = await _formTemplatesRepository.FirstOrDefaultAsync(p => p.Name == input.Name); if (formTemplate != null) { throw new InvalidInputException(@"A form template with this name already exists."); } var folderPath = $"{_hostingEnvironment.ContentRootPath}\\FileTemplates\\"; Directory.CreateDirectory(folderPath); var filePath = CreateUniqueFilePath(input.Name); formTemplate = Mapper.Map <FormTemplate>(input); System.IO.File.WriteAllBytes(filePath, Convert.FromBase64String(input.FileBytes)); formTemplate.FilePath = filePath; var fieldsJson = JsonConvert.SerializeObject(_converterService.GetPdfFormFieldsList(filePath)); formTemplate.PdfFormFields = fieldsJson; await _formTemplatesRepository.InsertAsync(formTemplate); }