Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Title")] Category category)
        {
            category.Created = DateTime.Now;
            category.Updated = DateTime.Now;
            if (ModelState.IsValid)
            {
                category.Slug = _slugger.Sluggify(category.Title);
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,CategoryId")] Post post)
        {
            post.Created = DateTime.Now;
            post.Updated = DateTime.Now;
            if (ModelState.IsValid)
            {
                post.Slug = _slugger.Sluggify(post.Title);
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Title", post.CategoryId);
            return(View(post));
        }