Example #1
0
        public HttpResponseMessage AddTodo([FromBody] TodoDTO todo)
        {
            if (todo == null)
            {
                var exception = new Exception("Requested todo object is invalid");
                logger.Log(LogLevel.Error, exception);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception));
            }

            int id = _todoDal.Insert(todo);

            if (id == 0)
            {
                var exception = new Exception("Error creating todo");
                logger.Log(LogLevel.Error, exception);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, id));
            }
        }