public ActionResult CreateOrEditBlogPost(Int32?id, String title, String[] authors, String content)
        {
            if (String.IsNullOrEmpty(title))
            {
                ModelState.AddModelError(nameof(title), "Title must have a value.");
            }

            if (String.IsNullOrEmpty(content))
            {
                ModelState.AddModelError(nameof(content), "Content must have a value.");
            }

            if (authors == null || authors.Length == 0)
            {
                ModelState.AddModelError(nameof(authors), "At least one author must be specified.");
            }

            if (!ModelState.IsValid)
            {
                return(View("BlogPostDetails", new BlogPostDetailsViewModel(null)));
            }

            if (!id.HasValue)
            {
                repository.AddBlogPost(title, authors, content);
            }
            else
            {
                repository.EditBlogPost(id.Value, title, authors, content);
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult AddBlogPost(String title, String[] author, String content)
        {
            if (String.IsNullOrEmpty(title))
            {
                ModelState.AddModelError("title", "Title cannot be blank.");
            }

            if (String.IsNullOrEmpty(content))
            {
                ModelState.AddModelError("content", "Content cannot be blank.");
            }

            if (author == null || author.Length == 0)
            {
                ModelState.AddModelError("author", "At least one author is required");
            }

            if (!ModelState.IsValid)
            {
                return(View("BlogPostDetails"));
            }

            repository.AddBlogPost(title, author, content);

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public async Task <IActionResult> Submit([FromBody] BlogPost post)
        {
            blogPostRepository.AddBlogPost(post);

            if (await blogPostRepository.SaveChangesAsync())
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            return(BadRequest("Failed to save blog post"));
        }
Exemple #4
0
        public async Task <IActionResult> AddBlogToUser(BlogPostForCreationDTO blogPost)
        {
            var entity = mapper.Map <BlogPost>(blogPost);
            var user   = await userManager.FindByNameAsync(User.Identity.Name);

            var userId = user.UserId;

            entity.UserId = userId;

            blogPostRepository.AddBlogPost(entity);
            await blogPostRepository.SaveChangesAsync();

            return(CreatedAtRoute("GetBlog", new { userId = userId, blogId = entity.Id }, entity));
        }
Exemple #5
0
        public async Task <IActionResult> AddPost(BlogPostViewModel model)
        {
            var createNewPostResult = BlogPost.CreateNewPost(model.Title, model.Content);

            if (createNewPostResult.Success)
            {
                await _blogPostRepository.AddBlogPost(createNewPostResult.CreatedEntity);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                foreach (var item in createNewPostResult.Notes)
                {
                    ModelState.AddModelError(item.Property, item.Message);
                }
                return(View());
            }
        }
Exemple #6
0
        public async Task <BlogPostResult> AddBlogPost(
            string title,
            string description,
            string content,
            string projectId
            )
        {
            var project = await _projectBL.GetProjectById(projectId);

            if (project.Details.ResultStatus == ResultStatus.Failure)
            {
                return new BlogPostResult
                       {
                           Data    = null,
                           Details = new ResultDetails
                           {
                               Message      = $"A project with id of {projectId} was not found.",
                               ResultStatus = ResultStatus.Failure
                           }
                       }
            }
            ;

            var blogPost = new BlogPost
            {
                Title       = title.Trim(),
                Description = description.Trim(),
                Content     = content.Trim(),
                ProjectId   = projectId.Trim()
            };
            var persistedBlogPost = await _blogPostRepository.AddBlogPost(blogPost);

            return(new BlogPostResult
            {
                Data = persistedBlogPost,
                Details = new ResultDetails {
                    ResultStatus = ResultStatus.Success
                }
            });
        }
Exemple #7
0
        public ActionResult Post(BlogPostVM newBlogPost)
        {
            if (ModelState.IsValid)
            {
                var blogId = _blogPostRepo.AddBlogPost(newBlogPost.BlogPost);

                foreach (var category in newBlogPost.CategoryArray)
                {
                    _blogCategoryRepo.AddCategoryToBlog(blogId, int.Parse(category));
                }

                string[] postTags = newBlogPost.Tag.TagName.ToLower().Split(' ');
                newBlogPost.Tags = _tagRepo.SelectAllTags(postTags);

                foreach (var tag in newBlogPost.Tags)
                {
                    _blogTagRepo.AddTagToBlog(blogId, tag.TagId);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(PopulatedCategorySelectListItem(newBlogPost)));
        }
        public async Task <IActionResult> CreatePost([FromBody] BlogPost value)
        {
            await _blogPostRepository.AddBlogPost(value);

            return(Ok());
        }
Exemple #9
0
        public int AddNewBlogPost(BlogPost newPost)
        {
            int newBlogId = _blogPostRepo.AddBlogPost(newPost);

            return(newBlogId);
        }