public async Task <HttpResponseMessage> PostAndReturnIdAsync([FromBody] PlanDto value) { try { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int?result = await planService.AddAndGetIdAsync(value); if (result != null) { var log = $"Succesfully created plan {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 plan"); const string message = "Incorrect request syntax."; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); }
public async Task <ActionResult> PostAndReturnIdAsync([FromBody] PlanDTO value) { try { if (ModelState.IsValid) { return(BadRequest(ModelState)); } int?result = await planService.AddAndGetIdAsync(value); if (result != null) { return(Ok(result)); } } catch (Exception e) { return(BadRequest()); } string message = "Incorrect request syntax."; return(BadRequest(message)); }