public async Task <HttpResponseMessage> PostAndReturnIdAsync([FromBody] TaskDto value) { try { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int?result = await taskService.AddAndGetIdAsync(value); if (result != null) { var log = $"Succesfully created task {value.Name} with id = {result} by user with id = {value.CreatorId}"; tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, log); return(Request.CreateResponse(HttpStatusCode.OK, result)); } } catch (EntityException e) { tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on creating task"); const string message = "Incorrect request syntax."; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); }
public async Task <ActionResult> PostAndReturnIdAsync([FromBody] TaskDTO value) { try { if (!ModelState.IsValid) { return(BadRequest()); } int?result = await taskService.AddAndGetIdAsync(value); if (result != null) { var log = $"Succesfully created task {value.Name} with id = {result} by user with id = {value.CreatorId}"; logger.LogInformation("Error : {0}", log); return(Ok(result)); } } catch (Exception e) { logger.LogInformation("Error : {0}", e.Message); return(BadRequest(e)); } const string message = "Incorrect request syntax."; logger.LogInformation("Error : {0}", message); return(BadRequest(message)); }