예제 #1
0
        public async Task CreatePostAsync(PostAdminCreateViewModel inputModel)
        {
            if (!this.dbContext.Users.Any(u => u.Id == inputModel.AuthorId))
            {
                throw new ArgumentNullException(string.Format(ServicesConstants.InvalidUserId, inputModel.AuthorId));
            }

            if (!this.dbContext.BlogCategories.Any(u => u.Id == inputModel.CategoryId))
            {
                throw new ArgumentNullException(string.Format(ServicesConstants.InvalidPostCategoryId, inputModel.CategoryId));
            }

            var post = new Post
            {
                Title       = inputModel.Title,
                Description = inputModel.Description,
                AuthorId    = inputModel.AuthorId,
                CategoryId  = inputModel.CategoryId,
                Rating      = inputModel.Rating,
                Type        = inputModel.Type,
                VideoUrl    = inputModel.VideoUrl,
            };

            await this.dbContext.Post.AddAsync(post);

            await this.dbContext.SaveChangesAsync();
        }
예제 #2
0
        public async Task <IActionResult> Create(PostAdminCreateViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.postsService.CreatePostAsync(inputModel);

            return(this.RedirectToAction("All"));
        }
예제 #3
0
        public async Task <IActionResult> Create()
        {
            var categories = this.categoriesService.GetAllPostCategories();

            var adminId = await this.usersService.GetAdminIdAsync();

            var postViewModel = new PostAdminCreateViewModel
            {
                AuthorId   = adminId,
                Categories = categories,
            };

            return(this.View(postViewModel));
        }