Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CategoryWithImageViewModel categoryModel)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/Identity/Account/AccessDenied"));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Category/Create"));
            }

            bool existCategogy = await this.categoryService.IfCategoryExists(categoryModel.Name);

            if (existCategogy)
            {
                var error = new CategoryError();
                error.ErrorMessage = GlobalConstants.CategotyCreateErrorMessage;
                return(this.RedirectToAction("Error", "Model", error));
            }

            var categoryToCreate = CategoryCreateMapper.Map(categoryModel);

            await this.categoryService.CreateCategoryAsync(categoryToCreate);

            return(this.Redirect("~/Category/All"));
        }
Ejemplo n.º 2
0
        public static CategoryCreateDtoModel Map(CategoryWithImageViewModel categoryModel)
        {
            var category = new CategoryCreateDtoModel
            {
                CategoryName = categoryModel.Name,
                ImageAddress = categoryModel.ImageAddress,
            };

            return(category);
        }