[HttpDelete("{messageId}")] // DELETE /QuickToDoComments/1
        public IActionResult DeleteQuickToDoComment([FromRoute] long messageId)
        {
            QuickTaskComment qtc = IQuickTodoCommentRepository.DeleteQuickTodoComment(messageId);

            if (qtc != null)
            {
                return(Ok(qtc)); // This is to inform our member.
            }
            return(NoContent()); // 404 resource not found, Microsoft docs use NotFound for this kind of behavior.
        }
        [HttpGet("{messageId}")]                                 // GET QuickToDoComments/1
        public IActionResult GetQuickToDoComment(long messageId) //Accepts from route parameters not JSON. You don't have to speficy [FromRoute], but you can..
        {
            QuickTaskComment quickTaskComment = IQuickTodoCommentRepository.GetQuickTodoComment(messageId);

            if (quickTaskComment != null)
            {
                return(Ok(quickTaskComment));
            }
            return(NoContent());  // 404 resource not found, Microsoft docs use NotFound for this kind of behavior.
        }
Пример #3
0
        public QuickTaskComment DeleteQuickTodoComment(long messageId)
        {
            QuickTaskComment qtComment = context.QuickTaskComment.Where(qtc => qtc.MessageId == messageId).FirstOrDefault();

            if (qtComment != null)
            {
                context.QuickTaskComment.Remove(qtComment);
                context.SaveChanges();
            }
            return(qtComment);
        }
Пример #4
0
 public ReturnModel AddQuickTodoComment(QuickTaskComment quickTaskComment)
 {
     try
     {
         context.QuickTaskComment.Add(quickTaskComment);
         context.SaveChanges();
     }
     catch { return(new ReturnModel {
             ErrorCode = ErrorCodes.DatabaseError
         }); }
     return(new ReturnModel {
         ErrorCode = ErrorCodes.OK, ReturnedId = quickTaskComment.MessageId
     });                                                                                            // Autoset in DB
 }
        [HttpPost()]                                                                           // POST /QuickToDoComments + JSON Object
        public IActionResult NewQuickToDoComment([FromBody] QuickTaskComment quickTaskComment) //Accepts JSON body, not x-www-form-urlencoded!
        {
            if (quickTaskComment == null)
            {
                return(BadRequest()); // 400 Bad Request
            }
            ReturnModel r = IQuickTodoCommentRepository.AddQuickTodoComment(quickTaskComment);

            if (r.ErrorCode == ErrorCodes.OK)
            {
                return(CreatedAtAction(nameof(GetQuickToDoComment), new { messageId = r.ReturnedId }, r.ReturnedId)); // 201 Created
            }
            return(new StatusCodeResult(StatusCodes.Status503ServiceUnavailable));                                    // 503 Service Unavailable Error.
        }
        [HttpPut("{messageId}")] // PUT QuickToDoComments/3 + JSON Object
        public IActionResult UpdateQuickToDoComment([FromRoute] long messageId, [FromBody] QuickTaskComment quickTaskComment)
        {
            if (quickTaskComment == null || messageId != quickTaskComment.MessageId)
            {
                return(BadRequest()); // 400 Bad Request
            }
            ReturnModel r = IQuickTodoCommentRepository.UpdateQuickTodoComment(quickTaskComment);

            if (r.ErrorCode == ErrorCodes.OK)
            {
                return(NoContent()); //204 No Content
            }
            else if (r.ErrorCode == ErrorCodes.ItemNotFoundError)
            {
                return(BadRequest());
            }
            return(new StatusCodeResult(StatusCodes.Status503ServiceUnavailable));  // 503 Service Unavailable Error.
        }
Пример #7
0
        public ReturnModel UpdateQuickTodoComment(QuickTaskComment quickTaskComment)
        {
            if (quickTaskComment.MessageId == 0)
            {
                return new ReturnModel {
                           ErrorCode = ErrorCodes.ItemNotFoundError
                }
            }
            ;
            try
            {
                context.Entry(quickTaskComment).State = EntityState.Modified;

                context.SaveChanges();
            }
            catch { return(new ReturnModel {
                    ErrorCode = ErrorCodes.DatabaseError
                }); }
            return(new ReturnModel {
                ErrorCode = ErrorCodes.OK
            });
        }
    }