コード例 #1
0
ファイル: PostService.cs プロジェクト: Eifersuuucht/WebBlog
        public int CreatePost(CreatePostBindModel bindModel)
        {
            var post = bindModel.ToPost();

            _context.Add(post);
            _context.SaveChanges();
            return(post.PostId);
        }
コード例 #2
0
        public IActionResult Create(CreatePostBindModel bindModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int id = _service.CreatePost(bindModel);
                    return(RedirectToAction(nameof(View), new { id = id }));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty, "An Error occured saving the post");
            }

            return(View(bindModel));
        }