コード例 #1
0
        public async Task <IActionResult> Add()
        {
            var categories = await this.forumService.GetAllCategoriesAsync <CategoryDropDownViewModel>();

            var viewModel = new AddForumPostInputModel()
            {
                ForumCategories = categories,
            };

            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Add(AddForumPostInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var userId          = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var forumCategoryId = await this.forumService.AddForumPostAsync(model, userId);

            return(this.RedirectToAction("Details", "ForumCategories", new { id = forumCategoryId }));
        }
コード例 #3
0
        public async Task <string> AddForumPostAsync(AddForumPostInputModel model, string userId)
        {
            var post = new ForumPost
            {
                ForumCategoryId = model.ForumCategoryId,
                Content         = model.Content,
                Title           = model.Title,
                UserId          = userId,
            };

            await this.postRepository.AddAsync(post);

            await this.postRepository.SaveChangesAsync();

            return(post.ForumCategoryId);
        }
コード例 #4
0
        public async Task EditPostAsync(string id, AddForumPostInputModel model)
        {
            var post = await this.postRepository.All()
                       .FirstOrDefaultAsync(x => x.Id == id);

            if (post == null)
            {
                throw new ArgumentException("Post does not exist.");
            }

            post.Title           = model.Title;
            post.Content         = model.Content;
            post.ForumCategoryId = model.ForumCategoryId;

            await this.postRepository.SaveChangesAsync();
        }
コード例 #5
0
        public async Task <IActionResult> Edit(string id, AddForumPostInputModel model)
        {
            await this.forumService.EditPostAsync(id, model);

            return(this.RedirectToAction("Details", "ForumCategories", new { id = model.ForumCategoryId }));
        }