Exemplo n.º 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.Equals(page.Slug));

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

                    return(View(page));
                }

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

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

                return(RedirectToAction("Index"));
            }

            return(View(page));
        }
Exemplo n.º 2
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.Equals(category.Slug));

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

                    return(View(category));
                }

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

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

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("PageID,Content,Title")] Page page)
        {
            if (ModelState.IsValid)
            {
                _context.Add(page);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(page));
        }
Exemplo n.º 4
0
 public bool AddPage(Page page)
 {
     _context.Add(page);
     _context.SaveChangesAsync();
     return(true);
 }