コード例 #1
0
        public async Task <IActionResult> Create(UseFullCategoryWithImageViewModel model)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/Identity/Account/AccessDenied"));
            }

            if (this.ModelState.IsValid)
            {
                bool useFullCategoryExists = await this.useFullCategoryService.CheckIfExistsAsync(model.Name);

                if (useFullCategoryExists)
                {
                    var existError = new UseFullCategoryError
                    {
                        ErrorMessage = GlobalConstants.UseFullCategoryExistErrorMessage
                    };
                    return(this.RedirectToAction("Error", "UseFullCategory", existError));
                }

                await this.useFullCategoryService.CreateUseFullCategoryByNameAsync(model.Name, model.ImageAddress);

                return(this.Redirect("/UseFullCategory/All"));
            }

            var error = new UseFullCategoryError
            {
                ErrorMessage = GlobalConstants.UseFullCategoryModelValidationMessаge
            };

            return(this.RedirectToAction("Error", "UseFullCategory", error));
        }
コード例 #2
0
        public List <UseFullCategoryWithImageViewModel> GetAllUseFullCategoriesWithParams()
        {
            var allUseFullCategories = this.useFullCategories.All();
            List <UseFullCategoryWithImageViewModel> useFullCategoryWithImages = new List <UseFullCategoryWithImageViewModel>();

            foreach (var item in allUseFullCategories)
            {
                UseFullCategoryWithImageViewModel viewModel = new UseFullCategoryWithImageViewModel
                {
                    Name         = item.Name,
                    ImageAddress = item.ImageAddress,
                };

                useFullCategoryWithImages.Add(viewModel);
            }

            return(useFullCategoryWithImages);
        }
コード例 #3
0
        public async Task <IActionResult> Create(UseFullCategoryWithImageViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/UseFullCategory/Create"));
            }
            else
            {
                bool useFullCategoryExists = this.useFullCategoryService.CheckIfExists(model.Name);
                if (useFullCategoryExists)
                {
                    return(this.Redirect("/UseFullCategory/Create"));
                }
                else
                {
                    await this.useFullCategoryService.CreateUseFullCategoryByNameAsync(model.Name, model.ImageAddress);

                    return(this.Redirect("/UseFullCategory/All"));
                }
            }
        }