public async Task <IActionResult> Create([Bind("CourseId,Name,Prefix,Number")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("PostId,Topic,Text,ParentPostId")] Post post)
        {
            if (ModelState.IsValid)
            {
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParentPostId"] = new SelectList(_context.Posts, "PostId", "PostId", post.ParentPostId);
            return(View(post));
        }
        public IActionResult Index([Bind("Topic,Text,ParentPostId", Prefix = "Post")] Post newpost)
        {
            ModelState.AddModelError("badness", "bad crap a happenin'");
            if (ModelState.IsValid)
            {
                _ctx.Add(newpost);
                _ctx.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var model = new HomeIndexVM();

            model.Comments = _ctx.Posts
                             .Include(p => p.Replies)
                             .Where(p => p.ParentPost == null)
                             .ToList();
            return(View(model));
        }