Пример #1
0
        private async Task <JsonResult> NotifyClientsAndGenerateVoteResultAsync(long countdownId, int currentUserAccountId)
        {
            CountdownAggregate countdownAggregate = await _countdownRepository.GetAggregateAsync(countdownId, currentUserAccountId);

            await _notificationService.ClearCountdownVoteNotificationsAsync(countdownId, countdownAggregate.CreatedByAccountId, currentUserAccountId);

            if (countdownAggregate.CurrentUserVote != 0)
            {
                var notificationChange = new NotificationChange {
                    CreatedByAccountId     = currentUserAccountId,
                    CreatedOn              = _systemClock.UtcNow,
                    NotificationActionType = countdownAggregate.CurrentUserVote > 0 ? NotificationActionType.Upvoted : NotificationActionType.Downvoted
                };
                await _notificationService.NotifyCountdownOwnerAsync(countdownId, notificationChange);
            }

            _notificationService.UpdateClientsAfterVote(countdownAggregate);

            var model = new CountdownVoteViewModel {
                CountdownId     = countdownId,
                VoteScore       = countdownAggregate.VoteScore,
                CurrentUserVote = countdownAggregate.CurrentUserVote
            };

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public async Task <ActionResult> Create(CommentCreateViewModel model)
        {
//            await Task.Delay(3000);
            if (ModelState.IsValid)
            {
                var comment = new Comment {
                    CountdownId        = model.CountdownId,
                    Text               = model.Text,
                    CreatedOn          = _systemClock.UtcNow,
                    CreatedByAccountId = (int)_contextService.CurrentUserAccountId
                };
                await _commentRepository.CreateAsync(comment);

                _notificationService.UpdateClientsAfterCreate(comment);

                var notificationChange = new NotificationChange {
                    CreatedByAccountId     = (int)_contextService.CurrentUserAccountId,
                    CreatedOn              = _systemClock.UtcNow,
                    NotificationActionType = NotificationActionType.Commented
                };
                await _notificationService.NotifyCountdownOwnerAsync(comment.CountdownId, notificationChange);

                return(new EmptyResult());
            }
            return(new HttpStatusCodeResult(400, "Bad Request"));
        }
Пример #3
0
        public async Task NotifyCommentOwnerAsync(long commentId, NotificationChange notificationChange)
        {
            Comment comment = await _commentRepository.GetAsync(commentId);

            Notification notification = await _notificationRepository.GetByCommentIdAsync(comment.Id, comment.CreatedByAccountId);

            if (notification == null)
            {
                notification = new Notification {
                    CountdownId      = comment.CountdownId,
                    CommentId        = comment.Id,
                    OwnedByAccountId = comment.CreatedByAccountId
                };
                await _notificationRepository.CreateAsync(notification, notificationChange);

                _notificationHub.BroadcastNotificationCreate(notification);
            }
            else
            {
                notificationChange.NotificationId = notification.Id;
                await _notificationRepository.CreateAsync(notificationChange);

                Notification notificationUpdated = await _notificationRepository.GetByCommentIdAsync(comment.Id, notification.OwnedByAccountId);

                _notificationHub.BroadcastNotificationUpdate(notificationUpdated);
            }
        }
Пример #4
0
        public void DeleteNotiChangeById(int notiChangeId)
        {
            NotificationChange nChange = findNotificationChange(notiChangeId);

            if (nChange != null)
            {
                notificationChangeRepository.Delete(nChange);
            }
        }
Пример #5
0
        public void deleteNoticByNchangeID(int nChangeID)
        {
            NotificationChange nChange = findNotificationChange(nChangeID);

            if (nChange != null)
            {
                notificationChangeRepository.Delete(nChange);
            }
        }
Пример #6
0
 public async Task CreateAsync(NotificationChange notificationChange)
 {
     using (IDbConnection connection = Connection) {
         const string sql =
             @"INSERT INTO NotificationChanges (NotificationId, CreatedByAccountId, CreatedOn, NotificationActionTypeId)
             OUTPUT INSERTED.Id
             VALUES (@NotificationId, @CreatedByAccountId, @CreatedOn, @NotificationActionType)";
         notificationChange.Id = await connection.QuerySingleOrDefaultAsync <long>(sql, notificationChange);
     }
 }
Пример #7
0
 protected bool SetValue <T>(ref T storage, T newValue, [CallerMemberName] string property = null)
 {
     if (newValue?.Equals(storage) ?? storage == null)
     {
         return(false);
     }
     NotificationChange?.Invoke(this.Id, GetAttributeNamespace(property), ChangeType.Update, storage, newValue);
     storage = newValue;
     return(true);
 }
Пример #8
0
        public ActionResult ReadNotification(int notificationChangeID)
        {
            NotificationChange item = NotificationDataHelpers.Instance.GetNotificationChangeByID(notificationChangeID);
            User user     = UserHelpers.GetCurrentUser(Session);
            int  notiType = NotificationDataHelpers.Instance.GetNotificationObjectByID(item.NotificationObjectID).Type;

            if (notiType == EventZoneConstants.FollowingUserAddNewEvent)
            {
                NotificationDataHelpers.Instance.ReadNotification(item);
            }
            else if (notiType == EventZoneConstants.CommentNotification)
            {
                NotificationDataHelpers.Instance.ReadNotifiComment(item, user.UserID);
            }
            else if (notiType == EventZoneConstants.NewFollower)
            {
                NotificationDataHelpers.Instance.ReadNotifiNewFollow(item, user.UserID);
            }
            else if (notiType == EventZoneConstants.RequestUploadImage)
            {
                NotificationDataHelpers.Instance.ReadNotifiRequestUploadImage(item);
            }
            else if (notiType == EventZoneConstants.EventHasBeenLocked)
            {
                NotificationDataHelpers.Instance.ReadNotification(item);
            }
            else if (notiType == EventZoneConstants.EventHasBeenUnLocked)
            {
                NotificationDataHelpers.Instance.ReadNotification(item);
                //<li>
                //    <a onlick="ReadNoty(@item.ID)" href="@Url.Action("Details", "Event", new {id = item.EventID})">Good new! Your event @EventDatabaseHelper.Instance.GetEventByID(item.EventID).EventName has been unlocked</a>
                //</li>
                //<li role="separator" class="divider"></li>
            }
            else if (notiType == EventZoneConstants.ReportNotification)
            {
                NotificationDataHelpers.Instance.ReadNotifiReport(item, user.UserID);
            }
            return(Json(new
            {
            }));
        }
Пример #9
0
        /// <summary>
        /// A notification is about something (object = event, friendship..) being changed (verb = added, requested..) by someone (actor) and reported to the user (subject).
        /// </summary>
        /// <param name="ObjectBeingChanged">Post,Comment,HelpdeskRequest,Add member request</param>
        /// <param name="userID">To user</param>
        /// <param name="verb">Change,Like,Comment,Approve</param>
        /// <param name="actor">By User</param>
        public void addNotification(String ObjectBeingChanged, int userID, String verb, int actor, int?targetObjectID)
        {
            NotificationObject nObject = findNotificationObject(userID, ObjectBeingChanged, targetObjectID);

            if (nObject == null)
            {
                nObject                = new NotificationObject();
                nObject.UserID         = userID;
                nObject.TargetObject   = ObjectBeingChanged;
                nObject.TargetObjectID = targetObjectID;
                addNotificationObject(nObject);
            }
            NotificationChange nChange = new NotificationChange();

            nChange.NotificationObjectID = nObject.ID;
            nChange.Actor = actor;
            nChange.Verb  = verb;

            nChange.CreatedDate = DateTime.Now;

            notificationChangeRepository.Add(nChange);
        }
Пример #10
0
        public async Task CreateAsync(Notification notification, NotificationChange notificationChange)
        {
            using (IDbConnection connection = Connection)
                using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) {
                    const string sqlNc =
                        @"INSERT INTO NotificationChanges (NotificationId, CreatedByAccountId, CreatedOn, NotificationActionTypeId)
                    OUTPUT INSERTED.Id
                    VALUES (@NotificationId, @CreatedByAccountId, @CreatedOn, @NotificationActionType)";

                    const string sqlN =
                        @"INSERT INTO Notifications (OwnedByAccountId, ViewedOn, CountdownId, CommentId)
                    OUTPUT INSERTED.Id
                    VALUES (@OwnedByAccountId, @ViewedOn, @CountdownId, @CommentId)";

                    notification.Id = await connection.QuerySingleOrDefaultAsync <long>(sqlN, notification);

                    notificationChange.NotificationId = notification.Id;
                    notificationChange.Id             = await connection.QuerySingleOrDefaultAsync <long>(sqlNc, notificationChange);

                    transactionScope.Complete();
                }
        }
Пример #11
0
 public Task NotifyCommentOwnerAsync(long commentId, NotificationChange notificationChange)
 {
     throw new System.NotImplementedException();
 }
 public Task CreateAsync(NotificationChange notificationChange)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 private void addNotificationChange(NotificationChange nChange)
 {
     notificationChangeRepository.Add(nChange);
 }
Пример #14
0
 private static SubscriptionNotification SetupExpectedNotification()
 {
     var subscription = new Subscription {Name = "a|b|c", SubscriptionHref = "http://my.url/svc", SubscriptionType = NotificationType.EntityUpdate};
     var change = new NotificationChange { Property = "title", NewValue = "new", OldValue = "old"} ;
     var notification = new SubscriptionNotification {RelativeHref = "foo/bar", SubscriptionArray = new[] {subscription}, ChangesArray = new[] { change }};
     WriteFile("expectedevent.txt", notification.NotificationType.ToString());
     WriteFile("expectedhref.txt", notification.RelativeHref);
     var subscriptionBuilder = new StringBuilder();
     subscriptionBuilder.AppendLine("\"Name\",\"SubscriptionType\",\"SubscriptionHref\"");
     subscriptionBuilder.AppendLine("\"" + subscription.Name + "\",\"" + subscription.SubscriptionType + "\",\"" + subscription.SubscriptionHref + "\"");
     WriteFile("expectedsubscriptions.txt", subscriptionBuilder.ToString().Trim());
     var changeBuilder = new StringBuilder();
     changeBuilder.AppendLine("\"Property\",\"OldValue\",\"NewValue\"");
     changeBuilder.AppendLine("\"" + change.Property + "\",\"" + change.OldValue + "\",\"" + change.NewValue + "\"");
     WriteFile("expectedchanges.txt", changeBuilder.ToString().Trim());
     return notification;
 }