WebApplication1/Controllers/TodoController.cs
/// <summary>
/// Creates a new TodoItem at the provided API Key
/// </summary>
/// <param name="apiKey">The API key to host this TodoItem</param>
/// <param name="task">The TodoItem model minus the ID</param>
/// <returns>The create TodoItem and a new ID associated to it</returns>
/// <response code="200">The TodoItem was created successfully</response>
/// <response code="400">The request was invalid</response>
Creates a new TodoItem at the provided API Key
Creates a new TodoItem at the provided API Key
[HttpPost]
        [ProducesResponseType(typeof(TodoItem), (int)HttpStatusCode.OK)]
        [ProducesResponseType(typeof(void), (int)HttpStatusCode.BadRequest)]
        public IActionResult Post([FromQuery] string apiKey, [FromBody] TodoItem task)
        {
            if (string.IsNullOrWhiteSpace(task.Task)) return BadRequest();
            if (string.IsNullOrWhiteSpace(apiKey)) return BadRequest();
            if (task.Task.Length > 256) return BadRequest();
            if (apiKey.Length > 128) return BadRequest();
            if (GetTodoItem(apiKey).Count > 64) return BadRequest();
            var item = new TodoItem(Guid.NewGuid(), task.Task) { Completed = task.Completed };
            GetTodoItem(apiKey).Add(item);
            return Ok(item);
        }
[ HttpPost ] [ ProducesResponseType ( typeof ( TodoItem ) , ( int ) HttpStatusCode . OK ) ] [ ProducesResponseType ( typeof ( void ) , ( int ) HttpStatusCode . BadRequest ) ] public IActionResult Post ( [ FromQuery ] string apiKey , [ FromBody ] TodoItem task ) { if ( string . IsNullOrWhiteSpace ( task . Task ) ) return BadRequest ( ) ; if ( string . IsNullOrWhiteSpace ( apiKey ) ) return BadRequest ( ) ; if ( task . Task . Length > 256 ) return BadRequest ( ) ; if ( apiKey . Length > 128 ) return BadRequest ( ) ; if ( GetTodoItem ( apiKey ) . Count > 64 ) return BadRequest ( ) ; var item = new TodoItem ( Guid . NewGuid ( ) , task . Task ) { Completed = task . Completed } ; GetTodoItem ( apiKey ) . Add ( item ) ; return Ok ( item ) ; }
Creates a new TodoItem at the provided API Key
Creates a new TodoItem at the provided API Key
// Validation // - Null Checks // - Length Checks // Create the TodoItem
The create TodoItem and a new ID associated to it
The create TodoItem and a new ID associated to it
string
[FromQuery]
TodoItem
[FromBody]
apiKey
The API key to host this TodoItem
The API key to host this TodoItem
task
The TodoItem model minus the ID
The TodoItem model minus the ID
response
The TodoItem was created successfully
The TodoItem was created successfully
response
The request was invalid
The request was invalid