コード例 #1
0
        public async Task <IActionResult> CreateCategory()
        {
            var categories = await this.service.GetAllCategoryNamesAsync();

            var model = new InsertCategoryModel {
                ExistingCategories = categories
            };

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> CreateCategory(InsertCategoryModel category)
        {
            var categories = await this.service.GetAllCategoryNamesAsync();

            if (categories.Contains(category.CategoryName))
            {
                this.ModelState.AddModelError("Category", "Category already exists");
            }

            if (!this.ModelState.IsValid)
            {
                category.ExistingCategories = categories;
                return(this.View(category));
            }

            await this.service.CreateCategoryAsync(category.CategoryName);

            return(this.RedirectToAction("Success", "Blacksmith", new { message = $"Successfully Created Category with name {category.CategoryName}" }));
        }