Beispiel #1
0
        public async Task <IActionResult> GetTodoDetails(int id)
        {
            var todo = await _todosService.GetById(id);

            if (todo == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound("Todo was not found"));
            }
            return(StatusCodeAndDtoWrapper.BuildSuccess(TodoDetailsDto.Build(todo)));
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> GetTodoDetails(int id)
        {
            var todo = await _todosService.GetById(id);

            if (todo != null)
            {
                return(StatusCodeAndDtoWrapper.BuildSuccess(TodoDetailsDto.Build(todo)));
            }
            return(StatusCodeAndDtoWrapper.BuildNotFound("Requested todo not found"));
        }
Beispiel #3
0
        public async Task <IActionResult> GetProductById(long id)
        {
            var product = await _productsService.FetchById(id);

            if (product == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound(new ErrorDtoResponse("Not Found")));
            }

            return(StatusCodeAndDtoWrapper.BuildGeneric(ProductDetailsDto.Build(product)));
        }
Beispiel #4
0
        public async Task <IActionResult> GetProductBySlug(string slug)
        {
            var product = await _productsService.GetProductBySlug(slug);

            if (product == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound(new ErrorDtoResponse("Not Found")));
            }

            return(new StatusCodeAndDtoWrapper(ProductDetailsDto.Build(product)));
        }
Beispiel #5
0
        public async Task <IActionResult> GetTodoDetails(int id)
        {
            var todo = await _mediator.Send(new GetTodoCommand { Id = id });

            if (todo == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound(id));
            }

            return(StatusCodeAndDtoWrapper.BuildSuccess(TodoDetailsDto.Build(todo)));
        }
Beispiel #6
0
        public async Task <IActionResult> DeleteTodo(int id)
        {
            var todoFromDb = await _todosService.GetProxyById(id);

            if (todoFromDb == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound("Specified Todo was not found"));
            }
            await _todosService.Delete(id);

            return(StatusCodeAndDtoWrapper.BuildSuccess("Todo Deleted Successfully"));
        }
Beispiel #7
0
        public async Task <HttpResponseMessage> UpdateTodo(int id, [FromBody] Todo todo)
        {
            var todoFromDb = await _todosService.GetProxyById(id);

            if (todoFromDb != null)
            {
                return(StatusCodeAndDtoWrapper.BuildSuccess(
                           TodoDetailsDto.Build(await _todosService.Update(todoFromDb, todo)),
                           "Todo Updated Successfully"));
            }
            return(StatusCodeAndDtoWrapper.BuildNotFound("Todo Was not found"));
        }
Beispiel #8
0
        public async Task <IActionResult> UpdateTodo(int id, [FromBody] Todo todo)
        {
            var todoFromDb = await _todosService.GetProxyById(id);

            if (todoFromDb == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound("Specified Todo was not found"));
            }

            return(StatusCodeAndDtoWrapper.BuildSuccess(
                       TodoDetailsDto.Build(await _todosService.Update(todoFromDb, todo)),
                       "Todo Updated Successfully"));
        }
Beispiel #9
0
        public async Task <IActionResult> DeleteTodo(int id)
        {
            var todoFromDb = await _mediator.Send(new GetTodoCommand { Id = id });

            if (todoFromDb == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound(id));
            }

            var success = await _mediator.Send(new DeleteTodoCommand { Id = id });

            return(StatusCodeAndDtoWrapper.BuildSuccess("Todo Deleted Successfully"));
        }
Beispiel #10
0
        public async Task <IActionResult> UpdateTodo(int id, [FromBody] Todo todo)
        {
            var todoFromDb = await _mediator.Send(new GetTodoCommand { Id = id });

            if (todoFromDb == null)
            {
                return(StatusCodeAndDtoWrapper.BuildNotFound(id));
            }

            var updatedTodo = await _mediator.Send(new UpdateTodoCommand
                                                   { TodoFromDb = todoFromDb, UpdatedTodo = todo });

            return(StatusCodeAndDtoWrapper.BuildSuccess(TodoDetailsDto.Build(updatedTodo),
                                                        "Todo Updated Successfully"));
        }