Ejemplo n.º 1
0
        public async Task <IActionResult> AddCategory(CategoryInformation categoryInformation)
        {
            var category = await _validator.ValidateAsync(categoryInformation);

            if (!category.IsValid)
            {
                return(BadRequest(category.Errors));
            }

            await _repository.AddCategory(categoryInformation);

            return(Ok());
        }
        public async Task <ActionResult> AddCategory(CategoryDetailViewModel model)
        {
            var validator = new CategoryValidator();
            var result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                var map = mapper.Map <CreateCategoryDTO>(model);
                await categoryService.AddCategory(map);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                foreach (ValidationFailure _error in result.Errors)
                {
                    ModelState.AddModelError(_error.PropertyName, _error.ErrorMessage);
                }
                return(View(model));
            }
        }