Пример #1
0
        public async Task <IActionResult> Create(Category category)
        {
            if (ModelState.IsValid)
            {
                category.Slug    = category.Name.ToLower().Replace(' ', '-');
                category.Sorting = 100;

                var slug = await context.Categories.FirstOrDefaultAsync(x => x.Slug == category.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "The category already exists.");
                    return(View(category));
                }

                TempData["Success"] = "The category has been added!";

                context.Add(category);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Пример #2
0
        public async Task <IActionResult> Create(Page page)
        {
            if (ModelState.IsValid)
            {
                page.Slug    = page.Title.ToLower().Replace(' ', '-');
                page.Sorting = 100;

                var slug = await context.Pages.FirstOrDefaultAsync(x => x.Slug == page.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "The page already exists.");
                    return(View(page));
                }

                TempData["Success"] = "The page has been added!";

                context.Add(page);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(page));
        }