Exemplo n.º 1
0
        public async Task <IActionResult> AddPostAsync(NewPostModel model)
        {
            var userId = _userManager.GetUserId(User);
            var user   = await _userManager.FindByIdAsync(userId);

            var post = BuildPost(model, user);

            await _postService.AddAsync(post);

            return(RedirectToAction("Index", "Post", new { Id = post.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(Post post)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                if (user == null)
                {
                    return(NotFound());
                }
                post.Owner = user;
                post.Date  = DateTime.UtcNow;

                await _postRepository.AddAsync(post);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }