public IActionResult AddPost()
        {
            var viewModel = new NormalPostInputModel();

            viewModel.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair();
            return(this.View(viewModel));
        }
示例#2
0
        public async Task CreateNormalPostAsync(NormalPostInputModel input, string userId)
        {
            var postType = this.postTypeRepository.All().FirstOrDefault(x => x.Name == "Post");

            var post = new Post
            {
                AddedByUserId = userId,
                Caption       = input.Caption,
                Type          = postType,
                Dislikes      = 0,
                Likes         = 0,
            };

            var tags = await this.tagsService.GetTagsForPost(input.Tags);

            foreach (var tag in tags)
            {
                post.Tags.Add(new PostTag
                {
                    Tag  = tag,
                    Post = post,
                });
            }

            await this.postRepository.AddAsync(post);

            await this.postRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> AddPost(NormalPostInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair();

                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.postsService.CreateNormalPostAsync(input, user.Id);

            return(this.Redirect("/"));
        }