Пример #1
0
        public void GetTaskByID_ExistingIDPassed_ReturnsRightTask()
        {
            //Arrange
            var testTasks = TasksCRUD.getInstance().getTaskById(1);

            //Act
            var okResponse = controller.GetTaskById(1) as OkObjectResult;
            var result     = okResponse.Value as Tasks;

            //Assert
            Assert.IsType <OkObjectResult>(okResponse);
            Assert.Equal("Contact Plumber", result.title);
        }
Пример #2
0
        public ActionResult GetTaskById(int id)
        {
            Tasks task = TasksCRUD.getInstance().getTaskById(id);

            if (task is null)
            {
                return(NotFound(new {
                    status = HttpStatusCode.NotFound,
                    error = string.Format("No task found with ID = {0}", id)
                }));
            }
            else
            {
                return(Ok(task));
            }
        }
Пример #3
0
        public ActionResult Delete(int id)
        {
            Boolean status = TasksCRUD.getInstance().DeleteTask(id);

            if (status is true)
            {
                return(Ok(new {
                    message = "Successfully deleted"
                }));
            }
            else
            {
                return(NotFound(new {
                    status = HttpStatusCode.NotFound,
                    error = string.Format("No task found with ID = {0}", id)
                }));
            }
        }
Пример #4
0
        public ActionResult Update(int id, [FromBody] Tasks request)
        {
            Tasks updatedTask = TasksCRUD.getInstance().UpdateTask(request, id);

            if (updatedTask is null)
            {
                return(NotFound(new {
                    status = HttpStatusCode.NotFound,
                    error = string.Format("No task found with ID = {0}", id)
                }));
            }
            else
            {
                return(Ok(new {
                    message = "Successfully updated",
                    details = updatedTask
                }));
            }
        }
Пример #5
0
        public ActionResult PostNewTask([FromBody] Tasks request)
        {
            //Checking if any required fields are missing
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PostTaskResponse response = new PostTaskResponse();

            response = TasksCRUD.getInstance().AddTask(request);
            if (response is null)
            {
                return(BadRequest(new {
                    status = HttpStatusCode.BadRequest,
                    error = (string.Format("Task with id {0} is already found", request.id)),
                }));
            }
            return(CreatedAtAction("GetTaskById", new { id = response.details.id }, response));
        }
Пример #6
0
        //Get api/Tasks
        public List <Tasks> GetAllTasks()
        {
            List <Tasks> taskList = TasksCRUD.getInstance().getAllTasks();

            return(taskList);
        }