コード例 #1
0
        public ListSharingState Resolve(ToDoList source, object dest, ListSharingState destMember, ResolutionContext context)
        {
            var userId = (int)context.Items["UserId"];

            if (source.Shares.Any())
            {
                bool someRequestsAccepted = source.Shares.Any(x => x.IsAccepted == true);
                if (someRequestsAccepted)
                {
                    if (source.UserId == userId)
                    {
                        return(ListSharingState.Owner);
                    }

                    ListShare userShare = source.Shares.Single(x => x.UserId == userId);
                    return(userShare.IsAdmin ? ListSharingState.Admin : ListSharingState.Member);
                }

                bool someRequestsPending = source.Shares.Any(x => !x.IsAccepted.HasValue);
                if (someRequestsPending)
                {
                    return(ListSharingState.PendingShare);
                }
            }

            return(ListSharingState.NotShared);
        }
コード例 #2
0
        public async Task <bool> LeaveAsync(int id, int userId)
        {
            ListShare share = await _listsRepository.LeaveAsync(id, userId);

            await _notificationsRepository.DeleteForUserAndListAsync(userId, id);

            return(share.IsAccepted.Value != false);
        }