Exemplo n.º 1
0
        public async Task <IActionResult> UpdateResourceCategory(int id,
                                                                 [FromBody] UpdateResourceCategoryViewModel model)
        {
            var result = await _resourceCategoryService.UpdateResourceCategory(id, model);

            return(result.ToJsonResult());
        }
Exemplo n.º 2
0
        public async Task <RequestResult <ResourceCategoryViewModel> > UpdateResourceCategory(int catId,
                                                                                              UpdateResourceCategoryViewModel categoryViewModel)
        {
            var resCategory = await _resourceCategoryRepository.FindResourceCategory(catId, true);

            if (resCategory == null)
            {
                return(RequestResult <ResourceCategoryViewModel> .Failed("Категория не найдена"));
            }

            var existingCategory = await _resourceCategoryRepository.FindResourceCategoryByName(categoryViewModel.Name);

            if (existingCategory != null && existingCategory.ResourceCategoryId != resCategory.ResourceCategoryId)
            {
                return(RequestResult <ResourceCategoryViewModel> .Failed("Категория с таким именем уже существует"));
            }

            resCategory.ResourceCategoryName = categoryViewModel.Name;

            await _resourceCategoryRepository.UpdateResourceCategory(resCategory);

            return(RequestResult <ResourceCategoryViewModel> .Success(new ResourceCategoryViewModel(resCategory)));
        }