Exemplo n.º 1
0
        public async Task <IActionResult> AddCategory(CategoryDto categoryDto)
        {
            if (categoryDto == null)
            {
                return(RedirectToAction("Categories"));
            }

            var category = _mapper.Map <Category>(categoryDto);

            OperationResult result = await _shopManager.CreateCategoryAsync(category);

            if (!result.Succeeded)
            {
                TempData["Message"] = string.Join(Environment.NewLine, result.Errors.Select(x => x.Description));
            }
            else
            {
                TempData["Message"] = $"Категория \"{category.Name}\" успешно добавлена.";
            }

            return(RedirectToAction("Categories"));
        }