示例#1
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 alreay exists");
                    return(View(page));
                }

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

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


                return(RedirectToAction("Index"));
            }
            return(View(page));
        }
示例#2
0
        public async Task <IActionResult> Create(EventPost eventPost)
        //Here is where I realized I messed up naming this event *Fixed
        {
            if (ModelState.IsValid)
            {
                eventPost.Slug = eventPost.Name.ToLower().Replace(" ", "-");

                var slug = await context.EventPosts.FirstOrDefaultAsync(x => x.Slug == eventPost.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "This event alreay exists");
                    return(View(eventPost));
                }

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

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


                return(RedirectToAction("Index"));
            }
            return(View(eventPost));
        }
示例#3
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 alreay exists");
                    return(View(category));
                }

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

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


                return(RedirectToAction("Index"));
            }
            return(View(category));
        }