예제 #1
0
        public HttpResponseMessage PostAndReturnId([FromBody] TaskDTO value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                var result = taskService.AddAndGetId(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));
        }