public async Task Handle(TrashedList notification, CancellationToken cancellationToken)
        {
            var todoList = await _todoListRepository.FindTodoListIdByIdAsync(notification.ListId);

            var contributorExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(todoList, _httpContextAccessor.HttpContext.User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value);

            await _hubContext.Clients.Users(contributorExceptYou).SendAsync("ListTrashed", notification.ListId);
        }
Esempio n. 2
0
        public async Task Handle(ItemChanged notification, CancellationToken cancellationToken)
        {
            var list = await _todoList.FindTodoListIdByIdAsync(notification.Item.ListId.GetValueOrDefault());

            var usersExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(list, _httpContextAccessor.HttpContext.User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value);

            await _context.Clients.Users(usersExceptYou).SendAsync("ItemUpdated", notification.Item);
        }
Esempio n. 3
0
        public async Task Handle(ContributorLeft notification, CancellationToken cancellationToken)
        {
            var list = await _todoListRepository.FindTodoListIdByIdAsync(notification.ListId.GetValueOrDefault());

            var account = await _accountRepository.FindAccountByIdAsync(notification.AccountId);

            var usersExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(list, account.Email);

            await _hubContext.Clients.Users(usersExceptYou).SendAsync("ContributorLeft", list);
        }
        public async Task Handle(SubItemMovedToTrash notification, CancellationToken cancellationToken)
        {
            var item = await _todoListItemRepository.FindToDoListItemByIdAsync(notification.ItemId.GetValueOrDefault());

            var list = await _todoListRepository.FindTodoListIdByIdAsync(item.ListId.GetValueOrDefault());

            var contributorExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(list, _httpContextAccessor.HttpContext.User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value);

            await _hubContext.Clients.Users(contributorExceptYou).SendAsync("SubItemTrashed", notification.ItemId, notification.SubItem);
        }
        public async Task Handle(PlanDowngraded notification, CancellationToken cancellationToken)
        {
            var accountPlan = await _accountPlanRepository.FindAccountPlanByAccountIdAsync(notification.Downgrade.AccountId);

            var plan = await _planRepository.FindPlanByIdAsync(accountPlan.PlanId);

            var myAccount = await _accountRepository.FindAccountByIdAsync(notification.Downgrade.AccountId);

            var unownedLists = await _todoListRepository.GetUnOwnedListsAsync(notification.Downgrade.AccountId);

            var ownedLists = await _todoListRepository.GetOwnedListsAsync(notification.Downgrade.AccountId);

            if (plan.MaxContributors == 0)
            {
                foreach (var ownedList in ownedLists)
                {
                    var contributors      = RemoveSelfFromContributorSignalRHelper.RemoveContributor(ownedList, myAccount.Email);
                    var contributorsCount = contributors.Count;

                    for (var i = 0; i < contributorsCount; i++)
                    {
                        var contributor = contributors[i];

                        var account = await _accountRepository.FindAccountByEmailAsync(contributor);

                        var contributorAccountList = await _accountsListsRepository.FindAccountsListsContributorByAccountIdAndListIdAsync(account.Id, ownedList.Id);

                        var contributorAccountPlan = await _accountPlanRepository.FindAccountPlanByAccountIdAsync(account.Id);

                        contributorAccountList.MakeLeft();
                        contributorAccountPlan.DecrementListCount();
                        ownedList.Contributors.Remove(contributor);
                        _todoListRepository.UpdateListAsync(ownedList);

                        await _todoListRepository.SaveChangesAsync();
                    }
                }

                foreach (var unownedList in unownedLists)
                {
                    var accountList = await _accountsListsRepository.FindAccountsListsContributorByAccountIdAndListIdAsync(notification.Downgrade.AccountId, unownedList.Id);

                    accountList.MakeLeft();
                    accountPlan.DecrementListCount();
                    unownedList.Contributors.Remove(myAccount.Email);
                    _todoListRepository.UpdateListAsync(unownedList);

                    await _todoListRepository.SaveChangesAsync();
                }
            }
            else
            {
                var contributorCount = ownedLists.Count;

                if (plan.MaxContributors < contributorCount)
                {
                    foreach (var ownedList in ownedLists)
                    {
                        var contributors = RemoveSelfFromContributorSignalRHelper.RemoveContributor(ownedList, myAccount.Email);

                        foreach (var contributor in contributors)
                        {
                            var accountContributor = await _accountRepository.FindAccountByEmailAsync(contributor);

                            var contributorAccountList = await _accountsListsRepository.FindAccountsListsContributorByAccountIdAndListIdAsync(notification.Downgrade.AccountId, ownedList.Id);

                            var contributorAccountPlan = await _accountPlanRepository.FindAccountPlanByAccountIdAsync(notification.Downgrade.AccountId);

                            contributorAccountList.MakeLeft();
                            contributorAccountPlan.DecrementListCount();
                            ownedList.Contributors.Remove(accountContributor.Email);
                            _todoListRepository.UpdateListAsync(ownedList);

                            await _accountsListsRepository.SaveChangesAsync();
                        }
                    }
                }
            }
        }
        public Task Handle(TodoListCompletedStateChanged notification, CancellationToken cancellationToken)
        {
            var contributorExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(notification.List, _httpContextAccessor.HttpContext.User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value);

            return(_hubContext.Clients.Users(contributorExceptYou).SendAsync("ListCompletedStateChanged", notification.List.Id, notification.List.Completed));
        }
Esempio n. 7
0
        public async Task Handle(InvitationAccepted notification, CancellationToken cancellationToken)
        {
            var contributorExceptYou = RemoveSelfFromContributorSignalRHelper.RemoveContributor(notification.List, _httpContextAccessor.HttpContext.User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value);

            await _hubContext.Clients.Users(contributorExceptYou).SendAsync("InvitationAccepted", notification.List);
        }