public async Task <string> CreatePost(NewPostDTO newPost) { ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal; var userName = ClaimsPrincipal.Current.Identity.Name; return(await postService.CreatePost(newPost, userName)); }
public async Task <string> ApprovalPost(NewPostDTO approvePost) { ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal; string userName = ClaimsPrincipal.Current.Identity.Name; return(await postService.UpdatePost(approvePost, userName)); }
public void Should_Throw_If_There_Is_No_Wall_To_Add_Posts_To() { // Setup var walls = new List <Wall>(); _wallsDbSet.SetDbSetData(walls.AsQueryable()); var posts = new List <Post>(); _postsDbSet.SetDbSetData(posts.AsQueryable()); var users = new List <ApplicationUser> { new ApplicationUser { Id = "testUser" } }; _usersDbSet.SetDbSetData(users.AsQueryable()); var newPostDto = new NewPostDTO { MessageBody = "test", OrganizationId = 2, PictureId = "pic", UserId = "testUser", WallId = 1 }; // Act // Assert var ex = Assert.Throws <ValidationException>(() => _postService.CreateNewPost(newPostDto)); Assert.AreEqual(ErrorCodes.ContentDoesNotExist, ex.ErrorCode); }
public async Task <string> UpdatePost(NewPostDTO updatePost, string userName) { try { User user = await _userManager.FindByNameAsync(userName); Post post = Mapper.Map <Post>(updatePost); Post beUpdatePost = _repository.Find(post.Id); beUpdatePost.Title = post.Title; beUpdatePost.Description = post.Description; beUpdatePost.IsActived = post.IsActived; beUpdatePost.UpdatedUserId = post.Title; beUpdatePost.UpdatedDate = DateTime.UtcNow; beUpdatePost.UpdatedUserId = user.Id; // Will be update for update more properties of this Entity _repository.Update(beUpdatePost); await _unitOfWork.SaveChangesAsync(); return(ResponseCodeString.Action_Success); } catch (Exception ex) { throw new Exception(ResponseCodeString.PostUpdate_Error, ex.InnerException); } }
public NewlyCreatedPostDTO CreateNewPost(NewPostDTO newPostDto) { var wall = _wallsDbSet .Where(x => x.Id == newPostDto.WallId && x.OrganizationId == newPostDto.OrganizationId). FirstOrDefault(); if (wall == null) { throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Wall not found"); } var post = new Post { AuthorId = newPostDto.UserId, Created = DateTime.UtcNow, LastEdit = DateTime.UtcNow, CreatedBy = newPostDto.UserId, MessageBody = newPostDto.MessageBody, PictureId = newPostDto.PictureId, SharedEventId = newPostDto.SharedEventId, LastActivity = DateTime.UtcNow, WallId = newPostDto.WallId, Likes = new LikesCollection() }; _postsDbSet.Add(post); _uow.SaveChanges(newPostDto.UserId); var postCreator = _usersDbSet.Single(user => user.Id == newPostDto.UserId); var postCreatorDto = MapUserToDto(postCreator); var newlyCreatedPostDto = MapNewlyCreatedPostToDto(post, postCreatorDto, wall.Type); _postNotificationService.NotifyAboutNewPost(post, postCreator); return(newlyCreatedPostDto); }
public async Task Put(int postId, NewPostViewModel postModel) { var newPostData = new NewPostDTO { Body = postModel.Body }; await postService.Update(newPostData, postId); }
public async Task <Post> SaveNewPost(NewPostDTO newPost) { var post = ConvertPostRequestDTOToPost(newPost); var saveNewPost = await _postRepository.SaveNewPost(post); await mappingTag(newPost.Tags, saveNewPost.IdPost); return(saveNewPost); }
public async Task Post(string userId, NewPostViewModel postModel) { var newPostData = new NewPostDTO { Body = postModel.Body, UserId = userId }; await postService.Create(newPostData); }
public async Task <bool> Update(NewPostDTO data, int postId) { var post = db.Posts.Find(postId); post.Body = data.Body; db.Posts.Update(post); await db.SaveChangesAsync(); return(true); }
public async Task <string> CreatePost(NewPostDTO newPost, string userName) { try { //bool isAutoApproved = ClaimsPrincipal.Current.Claims.Any(c => c.Value == "Admin") //|| ClaimsPrincipal.Current.Claims.Any(c => c.Value == "SuperAdmin") //|| ClaimsPrincipal.Current.Claims.Any(c => c.Value == "Mod"); //User user = await _userManager.FindByNameAsync(userName); Post post = Mapper.Map <Post>(newPost); //post.CreatedUserId = user.Id; post.CreatedDate = DateTime.UtcNow; //post.UpdatedUserId = user.Id; //post.UpdatedDate = DateTime.UtcNow; post.PublishedDate = DateTime.UtcNow; post.IsActived = true; _repository.Insert(post); await _unitOfWork.SaveChangesAsync(); foreach (var image in newPost.Images) { //image.CreatedUserId = user.Id; image.CreatedDate = DateTime.UtcNow; //image.UpdatedUserId = user.Id; image.UpdatedDate = DateTime.UtcNow; var newImage = Mapper.Map <Image>(image); newImage.Post = post; newImage.PostId = post.Id; _repository.GetRepository <Image>().Insert(newImage); } foreach (var video in newPost.Videos) { //video.CreatedUserId = user.Id; video.CreatedDate = DateTime.UtcNow; //video.UpdatedUserId = user.Id; video.UpdatedDate = DateTime.UtcNow; var newVideo = Mapper.Map <Video>(video); newVideo.Post = post; newVideo.PostId = post.Id; _repository.GetRepository <Video>().Insert(newVideo); } await _unitOfWork.SaveChangesAsync(); return(ResponseCodeString.GagCreate_Success); } catch (Exception ex) { throw new Exception(ResponseCodeString.PostCreate_Error, ex.InnerException); } }
public async Task <bool> Create(NewPostDTO data) { var newPost = new Post { Body = data.Body, UserId = data.UserId, Time = DateTime.Now }; db.Posts.Add(newPost); await db.SaveChangesAsync(); return(true); }
public void AddPost_InvalidTopicAlias_ThrowsTopicNotFoundException(string topicAlias, string content) { var testDatabaseContext = DbContextFactory.Create(); var post = new NewPostDTO { Content = content, AuthorID = 1 }; var service = new TopicService(testDatabaseContext); var exception = Record.Exception(() => service.AddPost(topicAlias, post)); Assert.IsType <TopicNotFoundException>(exception); }
public Post ConvertPostRequestDTOToPost(NewPostDTO newPost) { var post = new Post { Title = newPost.Title, Content = newPost.Content, DateOfPublication = newPost.DateOfPublication, Writer = newPost.Writer, Project = newPost.Project, Attachment = newPost.Attachment }; return(post); }
public ActionResult NewPost(NewPostDTO model) { if (!ModelState.IsValid) { return(Content("Fallaron las validaciones.")); } if (Account.CreateNewPostSL(model, ActiveSession.GetPersonID(), Server)) { TempData["message"] = "El post se ha publicado."; return(RedirectToAction("Timeline", "Account")); } return(RedirectToAction("Index", "Home")); }
public ActionResult NewReply(NewPostDTO model) { if (!ModelState.IsValid) { return(Content("Fallaron las validaciones.")); } if (Account.CreateNewPostSL(model, ActiveSession.GetPersonID(), Server)) { var newModel = Account.ViewPostCollectionDataSL(Convert.ToInt32(model.InReplyTo)); return(PartialView("_RepliesToPost", newModel.RepliesToPost)); } return(RedirectToAction("Timeline", "Account")); }
public async Task <string> DeletePost(NewPostDTO deletePost) { try { var beDeletePost = _repository.Find(deletePost.Id); _repository.Delete(beDeletePost); await _unitOfWork.SaveChangesAsync(); return(ResponseCodeString.Action_Success); } catch (Exception ex) { throw new Exception(ResponseCodeString.PostDelete_Error, ex.InnerException); } }
/// <inheritdoc /> public void AddPost(string topicAlias, NewPostDTO post) { if (!Exists(topicAlias)) { throw new TopicNotFoundException(); } var topic = _databaseContext.Topics.First(p => p.Alias == topicAlias); var postToAdd = Mapper.Map <Post>(post); postToAdd.CreationTime = DateTime.Now; postToAdd.ModificationTime = null; topic.Posts.Add(postToAdd); _databaseContext.SaveChanges(); }
public void AddPost_ValidTopicAlias_PostAdded(string topicAlias, string content) { var testDatabaseContext = DbContextFactory.Create(); var post = new NewPostDTO { Content = content, AuthorID = 1 }; var service = new TopicService(testDatabaseContext); service.AddPost(topicAlias, post); var topicData = service.GetTopicWithPosts(topicAlias); Assert.Contains(topicData.Posts, p => p.AuthorID == post.AuthorID && p.Content == post.Content); }
public async Task <string> DeletePost(NewPostDTO deletePost) { Account account = new Account( "doua5pgdi", "696442329793211", "7eVrRtWC2xJ68tiNIAmBPb93bOU"); Cloudinary cloudinary = new Cloudinary(account); DelResParams delRes = new DelResParams() { PublicIds = deletePost.Images.Where(i => i.Url != null).Select(i => i.Url.Split('/').Last()).ToList() }; DelResResult results = await cloudinary.DeleteResourcesAsync(delRes); return(await postService.DeletePost(deletePost)); }
public void Should_Create_New_Wall_Post() { // Setup var walls = new List <Wall> { new Wall { Id = 1, OrganizationId = 2 } }; _wallsDbSet.SetDbSetData(walls.AsQueryable()); // ReSharper disable once CollectionNeverUpdated.Local var posts = new List <Post>(); _postsDbSet.SetDbSetData(posts.AsQueryable()); var users = new List <ApplicationUser> { new ApplicationUser { Id = _userId } }; _usersDbSet.SetDbSetData(users.AsQueryable()); var newPostDto = new NewPostDTO { MessageBody = "test", OrganizationId = 2, PictureId = "pic", UserId = _userId, WallId = walls.First().Id }; // Act _postService.CreateNewPost(newPostDto); // Assert _postsDbSet.Received().Add( Arg.Is <Post>(x => x.MessageBody == newPostDto.MessageBody && x.WallId == newPostDto.WallId && x.AuthorId == newPostDto.UserId)); }
public bool CreateNewPostDL(NewPostDTO model, int personID, HttpServerUtilityBase localServer) { try { using (var context = new MiniBirdEntities()) { if (context.Person.Any(p => p.PersonID == personID)) { var post = new Post(); post.Comment = model.Comment; post.PublicationDate = DateTime.Now; post.ID_Person = personID; if (model.InReplyTo != null && model.InReplyTo > 0) { post.InReplyTo = model.InReplyTo; } List <Hashtag> hashtags = DiscoverHashtag(model.Comment, context); if (hashtags.Count > 0) { foreach (var hashtag in hashtags) { post.Hashtag.Add(hashtag); } } context.Post.Add(post); context.SaveChanges(); if (model.ImagesUploaded != null && model.ImagesUploaded.Length > 0) { int iteration = 1; foreach (string image in model.ImagesUploaded) { context.Thumbnail.Add(new Thumbnail() { FilePath = SaveThumbnailOnServer(image, post.PostID, localServer, iteration), ID_Post = post.PostID }); context.SaveChanges(); iteration++; } } else if (model.GifImage != null && model.GifImage.ContentLength > 0) { post.GIFImage = SaveGifOnServer(post.PostID, model.GifImage, localServer); context.SaveChanges(); } else if (model.VideoFile != null && model.VideoFile.ContentLength > 0) { post.VideoFile = SaveGifOnServer(post.PostID, model.VideoFile, localServer); context.SaveChanges(); } return(true); } return(false); } } catch { return(false); } }
public async Task <IActionResult> CreatePost(NewPostDTO newPost) { var newPostSaved = await _postService.SaveNewPost(newPost); return(StatusCode(201, newPostSaved)); }
public bool CreateNewPostSL(NewPostDTO model, int personID, HttpServerUtilityBase localServer) { return(Account.CreateNewPostDL(model, personID, localServer)); }