示例#1
0
        public ActionResult DeletePostInDb(IFormCollection collection)
        {
            var postId   = Convert.ToInt32(collection["PostId"]);
            var post     = dataService.GetPost(postId);
            var threadId = post.ThreadId;

            _db.Posts.Remove(post);
            _db.SaveChanges();
            return(RedirectToAction("Posts", new { threadId }));
        }
        public ActionResult RegisterForm(IFormCollection collection)
        {
            var name     = collection["AccountName"];
            var password = collection["AccountPassword"];
            var user     = userService.RegisterUser(name, password);

            try
            {
                db.UserAccounts.Add(user);
                db.SaveChanges();
            }
            catch
            {
                RedirectToAction(nameof(Register));
            }
            return(RedirectToAction(nameof(Login)));
        }