public async Task <IActionResult> AddTask(Guid id, [FromBody] TodoTask value) { if (id == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Add new task to TODO list try { await _service.AddTaskAsync(id, value); var result = new CreatedAtActionResult("createdobjectresult", "statuscodeobjects", "", new { message = "201 Item Created", currentDate = DateTime.Now }); return(result); } catch (Exception ex) { string text = ex.InnerException.ToString(); if (text.Contains("Violation of PRIMARY KEY constraint")) { return(StatusCode(409)); } return(BadRequest("Something went wrong " + ex.Message)); } }