Esempio n. 1
0
        public async Task <IActionResult> Post(BlogCreationModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var user = await _userManager.GetUserAsync(User);

                Post post = new Post
                {
                    Permitted        = true,
                    Title            = model.Title,
                    ShortDescription = model.ShortDescription,
                    Type             = model.Type,
                    PostContent      = new PostContent
                    {
                        Content = model.Content
                    },
                    UserId          = user.Id,
                    PostLikeAndView = new PostLikeAndView(),
                };
                post = _postRepository.Create(post);
                if (post != null)
                {
                    List <int> uPosts = user.PostsId == null ? new List <int>() : user.PostsId.ToList();
                    uPosts.Add(post.Id);
                    user.PostsId = uPosts.ToArray();
                    await _userManager.UpdateAsync(user);

                    return(RedirectToAction("Item", new { id = post.Id }));
                }
                return(View(model));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(View(model));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Post()
        {
            BlogCreationModel model = new BlogCreationModel();

            return(View(model));
        }