예제 #1
0
        public async Task <CategoryResponse> UpdateAsync(int id, Category category)
        {
            var existingCategory = await _categoryRepository.FindByIdAsync(id);

            if (existingCategory == null)
            {
                return(new CategoryResponse("Category not found"));
            }

            existingCategory.Name = category.Name;

            try
            {
                _categoryRepository.Update(existingCategory);
                await _unitOfWork.CompleteAsync();

                return(new CategoryResponse(existingCategory));
            }
            catch (Exception ex)
            {
                return(new CategoryResponse($"An error occurred when updating the category: {ex.Message}"));
            }
        }
예제 #2
0
 public void Update(Category category)
 {
     categoryRespository.Update(category);
 }