WebApplication1/Controllers/TodoController.cs
/// <summary>
/// Updates a TodoItem at the provided API key and TodoItems ID
/// </summary>
/// <param name="id">The UUID / GUID of the TodoItem</param>
/// <param name="apiKey">The API key that hosts this TodoItem</param>
/// <param name="task">The Updated TodoItem model</param>
/// <returns>The updated TodoItem</returns>
/// <response code="200">The TodoItem was updated successfully</response>
/// <response code="400">The request was invalid</response>
/// <response code="404">The TodoItem was not found</response>
Updates a TodoItem at the provided API key and TodoItems ID
Updates a TodoItem at the provided API key and TodoItems ID
[HttpPut("{id}")]
        [ProducesResponseType(typeof(TodoItem), 200)]
        [ProducesResponseType(typeof(void), (int)HttpStatusCode.BadRequest)]
        [ProducesResponseType(typeof(void), (int)HttpStatusCode.NotFound)]
        public IActionResult Put(Guid id, [FromQuery] string apiKey, [FromBody] TodoItem task)
        {
            if (string.IsNullOrWhiteSpace(apiKey)) return BadRequest();
            if (id == default(Guid)) return NotFound();
            if (!string.IsNullOrWhiteSpace(task.Task) && task.Task.Length > 256) return BadRequest();
            if (apiKey.Length > 128) return BadRequest();
            var item = GetTodoItem(apiKey).FirstOrDefault(x => x.Id == id);
            if (item == null) return NotFound();
            if(!string.IsNullOrWhiteSpace(task.Task))
                item.Task = task.Task;
            else
                item.Completed = task.Completed;
            return Ok(item);
        }
[ HttpPut ( " " ) ] [ ProducesResponseType ( typeof ( TodoItem ) , 200 ) ] [ ProducesResponseType ( typeof ( void ) , ( int ) HttpStatusCode . BadRequest ) ] [ ProducesResponseType ( typeof ( void ) , ( int ) HttpStatusCode . NotFound ) ] public IActionResult Put ( Guid id , [ FromQuery ] string apiKey , [ FromBody ] TodoItem task ) { if ( string . IsNullOrWhiteSpace ( apiKey ) ) return BadRequest ( ) ; if ( id == default ( Guid ) ) return NotFound ( ) ; if ( ! string . IsNullOrWhiteSpace ( task . Task ) && task . Task . Length > 256 ) return BadRequest ( ) ; if ( apiKey . Length > 128 ) return BadRequest ( ) ; var item = GetTodoItem ( apiKey ) . FirstOrDefault ( x => x . Id == id ) ; if ( item == null ) return NotFound ( ) ; if ( ! string . IsNullOrWhiteSpace ( task . Task ) ) item . Task = task . Task ; else item . Completed = task . Completed ; return Ok ( item ) ; }
Updates a TodoItem at the provided API key and TodoItems ID
Updates a TodoItem at the provided API key and TodoItems ID
// Validation // - Null Checks // - Length Checks // Find the TodoItem // Update the TodoItem
The updated TodoItem
The updated TodoItem
id
Guid
The UUID / GUID of the TodoItem
The UUID / GUID of the TodoItem
string
[FromQuery]
TodoItem
[FromBody]
apiKey
The API key that hosts this TodoItem
The API key that hosts this TodoItem
task
The Updated TodoItem model
The Updated TodoItem model
response
The TodoItem was updated successfully
The TodoItem was updated successfully
response
The request was invalid
The request was invalid
response
The TodoItem was not found
The TodoItem was not found