public void Activity_NewCommentCreation() { //arrange int notificationCount = notificationRepository.GetCount(); var projects = projectService.GetNew(1, 10, false, false).ToList(); var project = projects.Where(p => p.Files.Count > 0).FirstOrDefault(); if (project == null) { throw new Exception("please create a project with files and comments before running this test"); } //act Comment c = new Comment() { Creator = project.Creator, File = project.Files.First(), ProjectId = project.Id }; commentService.Create(c); //activityService.LogCommentCreation( c); //assert Assert.IsTrue(notificationCount < notificationRepository.GetCount(), @"there is no new notification created, please check if someone follows " + projects[0].Creator.DisplayName); }
public JsonResult Create(int fileId, string body) { Comment newComment = new Comment(); newComment.Body = body; newComment.Creator = CurrentUser; newComment.CreatedOn = DateTime.Now; newComment.FileId = fileId; newComment = serviceComment.Create(newComment); var model = new VMComment() { Body = newComment.Body, CreatedOn = newComment.CreatedOn, Creator = newComment.Creator, CreatorName = newComment.CreatorName, DeleteUrl = Url.Action("Delete",new {id = newComment.Id}), Id = newComment.Id }; var result = new JsonResult() { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return result; }
private void notifyCommentCreation(Comment newComment) { List<Notification> notifications = new List<Notification>(); string message = String.Format("a new comment was posted by {0} on {1} ", newComment.Creator.DisplayName , newComment.File.DisplayName); // get all the followers of the uploader var followers = serviceFollow.GetFollowerUsers(newComment.Creator.Id); foreach (var follower in followers) { //TODO : message translation + Url management Notification n = new Notification() { Message = message, UserId = follower.Id, PictureUrl = newComment.Creator.PictureUrl, Url = "/File/Display/" + newComment.FileId }; notifications.Add(n); } //get all the followers of the project var interrestedPeoples = serviceFollow.GetFollowsByProject(newComment.File.ProjectId); foreach (var follower in interrestedPeoples) { // do not add the notification if it was already added if (!notifications.Any(n => n.UserId == follower.FollowerId)) { //TODO : message translation + Url management Notification n = new Notification() { Message = message, UserId = follower.FollowerId, PictureUrl = newComment.Creator.PictureUrl, Url = "/File/Display/" + newComment.FileId }; notifications.Add(n); } } repoNotification.Create(notifications); }
public void LogCommentCreation(Comment newComment) { Activity act = new Activity(); act.Who = newComment.Creator; act.CommentId = newComment.Id; act.ProjectId = newComment.ProjectId; act.FileId = newComment.FileId; act.When = DateTime.Now; act.Type = ActivityType.Create | ActivityType.Comment; repoActivity.Create(act); notifyCommentCreation(newComment); }
public bool Edit(Comment comment) { comment.ModifiedOn = DateTime.Now; var result = this.repoComment.SaveChanges(comment); return result.Id>0; }