public async Task <IActionResult> Comment([FromRoute] Domain.Post.Post postModel) { var viewModel = new CommentViewModel(); var user = AccountService.GetAccountByUsername(User.Identity.Name); var postRequest = JsonConvert.SerializeObject(postModel.Id); var contentRequest = new StringContent(postRequest, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("api/post/get", contentRequest); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Post>(content); viewModel.Post = post; } var commentRequest = JsonConvert.SerializeObject(postModel.Id); var contentCommentRequest = new StringContent(commentRequest, Encoding.UTF8, "application/json"); var responseComment = await httpClient.PostAsync("api/comment/get", contentCommentRequest); if (responseComment.StatusCode == System.Net.HttpStatusCode.OK) { var content = await responseComment.Content.ReadAsStringAsync(); var comments = JsonConvert.DeserializeObject <List <Comment> >(content); viewModel.Comments = comments; } viewModel.UserLoggedIn = user; return(View(viewModel)); }
public async Task <IdentityResult> CreatePost(Domain.Post.Post post, CancellationToken cancellationToken) { this.Context.Posts.Add(post); await this.Context.SaveChangesAsync(); return(IdentityResult.Success); }
public async Task <Domain.Post.Post> CreatePost(CreatePost createPost) { var post = new Domain.Post.Post(createPost.UserId, createPost.CreationDate, createPost.OfferDescription, createPost.OfferCountry, createPost.OfferCity, createPost.OfferCost, createPost.HotelName, createPost.DeparturePlace, createPost.DateOfDeparture, createPost.DateOfReturn, createPost.IsActivePost, createPost.IsBannedPost, createPost.OfferPhotoHref); post.PostId = await _postRepository.AddPost(post); return(post); }
public Comment(Domain.Post.Post post, ApplicationUser author, string content, Comment parent = null) : this() { Post = post; Author = author; Content = content; Parent = parent; parent.AddChildrenComment(this); }
public void CreatePost_Returns_Correct_Response() { var post = new Domain.Post.Post(1, "Polska", "Mazury", 2500.00, "Bardzo fajna wycieczka na Mazurach!", "img/offerMazury.jpg"); Assert.Equal(1, post.UserId); Assert.Equal("Polska", post.OfferCountry); Assert.Equal("Mazury", post.OfferCity); Assert.Equal(2500.00, post.OfferCost); Assert.Equal("Bardzo fajna wycieczka na Mazurach!", post.OfferDescription); Assert.Equal("img/offerMazury.jpg", post.OfferPhotoHref); }
public async Task AddPost_Returns_Correct_Response() { var post = new Domain.Post.Post(1, "Polska", "Mazury", 2500.00, "Bardzo fajna wycieczka na Mazurach!", "img/offerMazury.jpg"); var postId = await _postRepository.AddPost(post); var createdPost = await _context.Post.FirstOrDefaultAsync(x => x.PostId == postId); Assert.NotNull(createdPost); _context.Post.Remove(createdPost); await _context.SaveChangesAsync(); }
public async Task EditPost(Domain.Post.Post post) { var editPost = await _context.Post.FirstOrDefaultAsync(x => x.PostId == post.PostId); editPost.OfferCountry = post.OfferCountry; editPost.OfferCity = post.OfferCity; editPost.OfferCost = post.OfferCost; editPost.OfferDescription = post.OfferDescription; editPost.HotelName = post.HotelName; editPost.DeparturePlace = post.DeparturePlace; editPost.DateOfDeparture = post.DateOfDeparture; editPost.DateOfReturn = post.DateOfReturn; editPost.IsActivePost = post.IsActivePost; editPost.IsBannedPost = post.IsBannedPost; editPost.OfferPhotoHref = post.OfferPhotoHref; await _context.SaveChangesAsync(); }
public void Create(string userName, string message, string imageUrl, DateTime publishDateTime) { var user = PostRepository.GetAccountByName(userName); var post = new Domain.Post.Post(); post.AccountId = user.Id; post.Message = message; if (string.IsNullOrEmpty(imageUrl)) { post.ImageUrl = null; } else { post.ImageUrl = imageUrl; } post.PublishDateTime = publishDateTime; PostRepository.CreatePost(post, CancellationToken.None); }
public async Task <int> AddPost(Domain.Post.Post post) { var postDAO = new DAO.Post { UserId = post.UserId, CreationDate = post.CreationDate, OfferCountry = post.OfferCountry, OfferCity = post.OfferCity, OfferDescription = post.OfferDescription, OfferCost = post.OfferCost, HotelName = post.HotelName, DeparturePlace = post.DeparturePlace, DateOfDeparture = post.DateOfDeparture, DateOfReturn = post.DateOfReturn, IsActivePost = post.IsActivePost, IsBannedPost = post.IsBannedPost, OfferPhotoHref = post.OfferPhotoHref }; await _context.AddAsync(postDAO); await _context.SaveChangesAsync(); return(postDAO.PostId); }
public static PostViewModel PostToPostViewModel(Domain.Post.Post post) { var postViewModel = new PostViewModel { PostId = post.PostId, UserId = post.UserId, CreationDate = post.CreationDate, EditionDate = post.EditionDate, OfferCountry = post.OfferCountry, OfferCity = post.OfferCity, OfferDescription = post.OfferDescription, OfferCost = post.OfferCost, HotelName = post.HotelName, DeparturePlace = post.DeparturePlace, DateOfDeparture = post.DateOfDeparture, DateOfReturn = post.DateOfReturn, IsActivePost = post.IsActivePost, IsBannedPost = post.IsBannedPost, OfferPhotoHref = post.OfferPhotoHref }; return(postViewModel); }