示例#1
0
 public async Task <ActionResult> PostAsync(int planTaskId, CommentDTO comment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         if (await commentService.AddCommentToPlanTaskAsync(planTaskId, comment))
         {
             var log = $"Succesfully created comment with id = {comment.Id} by user id = {comment.CreatorId}";
             return(Ok(log));
         }
         return(NoContent());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
 public async Task <HttpResponseMessage> PostAsync(int planTaskId, CommentDto comment)
 {
     if (!ModelState.IsValid)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
     try
     {
         if (await commentService.AddCommentToPlanTaskAsync(planTaskId, comment))
         {
             var log = $"Succesfully created comment with id = {comment.Id} by user id = {comment.CreatorId}";
             tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, log);
             return(Request.CreateResponse(HttpStatusCode.OK, "Comment succesfully created"));
         }
         tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on creating comment");
         return(Request.CreateErrorResponse(HttpStatusCode.NoContent, "Not possibly to add comment: task in this plan does not exist"));
     }
     catch (EntityException e)
     {
         tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Internal creation error"));
     }
 }