예제 #1
0
        public async Task <ActionResult <CategoryDetailResource> > DeleteCategory(int id)
        {
            CategoryResponse response = await _categoryService.DeleteAsync(id);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            CategoryDetailResource deletedResource = _mapper.Map <CategoryDetailResource>(response.Category);

            return(Ok(deletedResource));
        }
예제 #2
0
        public async Task <ActionResult <CategoryDetailResource> > GetCategory(int id)
        {
            CategoryResponse response = await _categoryService.FindByIdAsync(id);

            if (!response.Success)
            {
                return(NotFound(response.Message));
            }

            CategoryDetailResource resource = _mapper.Map <CategoryDetailResource>(response.Category);

            return(Ok(resource));
        }
예제 #3
0
        public async Task <ActionResult <CategoryDetailResource> > PutCategory(int id, CategorySaveResource resource)
        {
            Category         category = _mapper.Map <Category>(resource);
            CategoryResponse response = await _categoryService.UpdateAsync(id, category);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            CategoryDetailResource updatedResource = _mapper.Map <CategoryDetailResource>(response.Category);

            return(Ok(updatedResource));
        }
예제 #4
0
        public async Task <ActionResult <CategoryDetailResource> > PostCategory(CategorySaveResource resource)
        {
            Category         category = _mapper.Map <Category>(resource);
            CategoryResponse response = await _categoryService.SaveAsync(category);

            if (!response.Success)
            {
                return(BadRequest(response.Message));
            }

            CategoryDetailResource savedResource = _mapper.Map <CategoryDetailResource>(response.Category);

            return(CreatedAtAction(nameof(GetCategory), new { id = savedResource.Id }, savedResource));
        }