Пример #1
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));
        }
Пример #2
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));
        }