public async void CreateFormShouldCreateNewEntityAndReturnCreated() { var allForms = await _fixture.GetHttpResult(UrlPath); var currentNumberOfForms = JsonConvert.DeserializeObject <List <FormListDto> >(allForms.Content.ReadAsStringAsync().Result).Count; _styles.Add(DataSeeder.StyleId1); _validations.Add(DataSeeder.ValidationId1); _fields.Append(new FieldCreateDto() { Name = "TestField", ContentType = "string", Label = "label", Placeholder = "placeholder", Value = "value", Required = true, OptionsJson = "{\"id\":42 , \"name\":\"Rolando\"}", FieldType = DataSeeder.FieldTypeId1, StyleIds = _styles, ValidationIds = _validations }); _fields.Append(new FieldCreateDto() { Name = "FieldTest", ContentType = "integer", Label = "bezeichnung", Placeholder = "platz", Value = "Wert", Required = false, OptionsJson = "{\"id\":69 , \"name\":\"Messi\"}", FieldType = DataSeeder.FieldTypeId1, ValidationIds = _validations }); var newForm = new FormCreateDto() { Title = "NewTest Form", IsPublic = true, RestrictedAccess = false, FormHasField = _fields }; var serializedForm = JsonConvert.SerializeObject(newForm); var result = await _fixture.PostHttpResult(UrlPath, serializedForm); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.Created); allForms = await _fixture.GetHttpResult(UrlPath); var newNumberOfForms = JsonConvert.DeserializeObject <List <FormListDto> >(allForms.Content.ReadAsStringAsync().Result).Count; newNumberOfForms.Should().Be(currentNumberOfForms + 1); }
public virtual IActionResult UpdateFormById([FromRoute] Guid formId, [FromBody] FormCreateDto formCreateDto) { if (!ModelState.IsValid) { return(BadRequest()); } return(_formRepository.UpdateFormById(formId, formCreateDto)); }
public static Form ToModel(this FormCreateDto response) { return(new Form() { Id = Guid.NewGuid(), Title = response.Title, Created = DateTime.UtcNow, Deprecated = false, IsPublic = response.IsPublic, RestrictedAccess = response.RestrictedAccess }); }
// updates a specific form // sets the old form to deprecated // the new form references the old one // returns the updated form as a DTO public IActionResult UpdateFormById(Guid formId, FormCreateDto formCreateDto) { // Set updated Form Deprecated true var formToUpdate = _applicationDbContext.Form.SingleOrDefault(form => form.Id == formId); formToUpdate.Deprecated = true; Save(); // Create new Form. var newForm = CreateNewForm(formCreateDto, formToUpdate.Id); return(new OkObjectResult(newForm)); }
public virtual IActionResult AddForm([FromBody] FormCreateDto form) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newForm = _formRepository.CreateNewForm(form, null); _formRepository.Save(); var location = "/forms/" + newForm.Id; return(Created(location, newForm)); }
// creates a new form and returns the created object as a DTO public FormDetailDto CreateNewForm(FormCreateDto formToCreate, Guid?previousVerison) { var fieldIndex = 1; var newForm = formToCreate.ToModel(); if (previousVerison != null) { newForm.PreviousVersion = previousVerison; } _applicationDbContext.Form.Add(newForm); Save(); foreach (var field in formToCreate.FormHasField) { CreateNewField(newForm.Id, field, fieldIndex); fieldIndex++; } return(GetFormById(newForm.Id)); }
public async void CreateNewFormWithInvalidModelStateShouldReturnBadRequest() { _fields.Append(new FieldCreateDto() { Name = "TestField", OptionsJson = "{\"id\":42 , \"name\":\"Rolando\"}", FieldType = DataSeeder.FieldTypeId1, }); var newForm = new FormCreateDto() { IsPublic = true, RestrictedAccess = false, FormHasField = _fields }; var serializedForm = JsonConvert.SerializeObject(newForm); var result = await _fixture.PostHttpResult(UrlPath, serializedForm); result.Should().NotBeNull(); result.StatusCode.Should().Be(HttpStatusCode.BadRequest); }