Exemplo n.º 1
0
        public static FieldDefinitionDto UpdateFieldDefinition(NebulaDbContext dbContext, int FieldDefinitionTypeID,
                                                               FieldDefinitionDto FieldDefinitionUpdateDto)
        {
            var fieldDefinition = dbContext.FieldDefinition
                                  .Include(x => x.FieldDefinitionType)
                                  .SingleOrDefault(x => x.FieldDefinitionTypeID == FieldDefinitionTypeID);

            // null check occurs in calling endpoint method.
            fieldDefinition.FieldDefinitionValue = FieldDefinitionUpdateDto.Definition;

            dbContext.SaveChanges();

            return(fieldDefinition.AsDto());
        }
Exemplo n.º 2
0
        public ActionResult <FieldDefinitionDto> UpdateFieldDefinition([FromRoute] int fieldDefinitionTypeID,
                                                                       [FromBody] FieldDefinitionDto fieldDefinitionUpdateDto)
        {
            var fieldDefinitionDto = FieldDefinition.GetByFieldDefinitionTypeID(_dbContext, fieldDefinitionTypeID);

            if (ThrowNotFound(fieldDefinitionDto, "FieldDefinition", fieldDefinitionTypeID, out var actionResult))
            {
                return(actionResult);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updatedFieldDefinitionDto =
                FieldDefinition.UpdateFieldDefinition(_dbContext, fieldDefinitionTypeID, fieldDefinitionUpdateDto);

            return(Ok(updatedFieldDefinitionDto));
        }