Пример #1
0
        public async void AddPost_ShouldPass(string text)
        {
            var post = await _repository.AddPost(new Post { Text = text });

            Assert.NotNull(post.Id);
            Assert.Equal(text, post.Text);
        }
Пример #2
0
        public ActionResult AddPost(string description, string subject, string content)
        {
            User user = CheckAuthentication(Request.Cookies[id]);

            if (user == null)
            {
                return(RedirectToAction("Authorize"));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(description) && !string.IsNullOrWhiteSpace(subject) && !string.IsNullOrWhiteSpace(content))
                {
                    try
                    {
                        Guid    subjKey = Guid.Parse(subject);
                        Subject subj    = subjectRepo.GetSubject(subjKey);
                        content = Uri.UnescapeDataString(content);
                        Post newPost = new Post(user.UserKey, subj.SubjectKey, description, content);

                        postRepo.AddPost(newPost);

                        return(new EmptyResult());
                    }
                    catch
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
        }
Пример #3
0
 public async Task <Post> AddPost(Post post)
 {
     if (post == null)
     {
         throw new ArgumentNullException(nameof(post), "Post cannot be null.");
     }
     if (string.IsNullOrWhiteSpace(post.Text))
     {
         throw new ArgumentNullException(nameof(post.Text), "Text cannot be null.");
     }
     return(await _repository.AddPost(post));
 }
Пример #4
0
        public async void AddComment_ShouldPass(string postText, string commentText)
        {
            var post = await _postrepository.AddPost(new Post { Text = postText });

            var firstComments = post.Comments?.ToList();

            await _commentsRepository.AddComment(new Comment { Post = post, Text = commentText });

            var secondComments = post.Comments.First();

            Assert.Null(firstComments);
            Assert.Equal(commentText, secondComments.Text);
        }
Пример #5
0
 public IActionResult AddPost(AddPostVM viewModel, string command)
 {
     if (command.Equals("submit2"))
     {
         _postsRepository.AddNewCategory(viewModel);
         return(RedirectToAction("addpost", "admin"));
     }
     else
     {
         if (!ModelState.IsValid)
         {
             return(View(viewModel));
         }
         _postsRepository.AddPost(viewModel, "Administrator");
         return(RedirectToAction("index", "home"));
     }
 }
Пример #6
0
        public string Posted([FromBody] Posts post)
        {
            if (post == null)
            {
                return("nulled");
            }
            Posts newPost = postRepo.AddPost(new Posts()
            {
                UserId    = post.UserId,
                Locations = post.Locations,
                PostText  = post.PostText,
                PostDate  = post.PostDate,
                PostTime  = post.PostTime,
                PostImage = post.PostImage
            });

            return(ToJson(new PostComponent(newPost)));
        }
Пример #7
0
        public async Task AddPost(Guid UserId, string Text)
        {
            Post post = new Post()
            {
                Author = new User()
                {
                    Id = UserId
                },
                Text = Text
            };

            if (post.IsValidData())
            {
                await _postsRepository.AddPost(post);
            }
            else
            {
                throw new ArgumentException("Invalid arguments");
            }
        }
Пример #8
0
        public string AddPost(string blogid, string username, string password, MetaPost post, bool publish)
        {
            EnsureUser(username, password).Wait();

            var newStory = new Data.Post();

            try
            {
                newStory.Title         = post.title;
                newStory.Content       = post.description;
                newStory.DatePublished = post.dateCreated == DateTime.MinValue ? DateTime.UtcNow : post.dateCreated;
                newStory.Tags          = string.Join(",", post.categories);
                newStory.IsPublished   = publish;
                newStory.Slug          = newStory.GetStoryUrl();

                _repo.AddPost(newStory);
                _repo.SaveAll();
            }
            catch (Exception)
            {
                throw new MetaWeblogException("Failed to save the post.");
            }
            return(newStory.Id.ToString());
        }
Пример #9
0
 public void AddPost(Post post)
 {
     repository.AddPost(post);
 }