Exemple #1
0
        public virtual async Task KickUserFromToDoGroup(KickAnotherUserFromMyToDoGroupArge args, CancellationToken cancellationToken)
        {
            Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId());

            ToDoGroup toDoGroupsToBeKickFrom = await ToDoGroupsRepository.GetAll()
                                               .Where(tdg => tdg.Id == args.toDoGroupId)
                                               .Select(tdg => new ToDoGroup
            {
                Id          = tdg.Id,
                CreatedById = tdg.CreatedById,
                Items       = tdg.Items.Select(tdi => new ToDoItem
                {
                    Id      = tdi.Id,
                    Options = tdi.Options.Where(tdio => tdio.UserId == args.userId).Select(tdio => new ToDoItemOptions
                    {
                        Id     = tdio.Id,
                        UserId = tdio.UserId
                    }).ToList()
                }).ToList()
            }).FirstOrDefaultAsync(cancellationToken);;

            if (toDoGroupsToBeKickFrom == null)
            {
                throw new ResourceNotFoundException("ToDoGroupCouldNotBeFound");
            }

            if (toDoGroupsToBeKickFrom.CreatedById != userId)
            {
                throw new DomainLogicException("OnlyOwnerCanKickOtherUsers");
            }

            User kickedUser = await UsersRepository.GetByIdAsync(cancellationToken, args.userId);

            if (kickedUser == null)
            {
                throw new ResourceNotFoundException("UserCouldNotBeFoundToBeKicked");
            }

            foreach (ToDoItemOptions toDoItemOptionsToBeDeleted in toDoGroupsToBeKickFrom.Items.SelectMany(tdi => tdi.Options) /* We've loaded options of to be kicked user only! */)
            {
                await ToDoItemOptionsListRepository.DeleteAsync(toDoItemOptionsToBeDeleted, cancellationToken);
            }

            ToDoGroupOptions toDoGroupOptionsToBeDeleted = await ToDoGroupOptionsListRepository.GetAll().FirstOrDefaultAsync(tdo => tdo.ToDoGroupId == args.toDoGroupId && tdo.UserId == args.userId);

            await ToDoGroupOptionsListRepository.DeleteAsync(toDoGroupOptionsToBeDeleted, cancellationToken);
        }
Exemple #2
0
        public virtual async Task <ToDoGroupDto> ShareToDoGroupWithAnotherUser(ShareToDoGroupWithAnotherUserArgs args, CancellationToken cancellationToken)
        {
            Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId());

            ToDoGroup toDoGroup = await ToDoGroupsRepository.GetAll()
                                  .Where(tdg => tdg.CreatedById == userId && tdg.Id == args.toDoGroupId)
                                  .Select(tdg => new ToDoGroup
            {
                Id    = tdg.Id,
                Items = tdg.Items.Select(tdi => new ToDoItem
                {
                    Id = tdi.Id
                }).ToList()
            }).FirstOrDefaultAsync(cancellationToken);

            if (toDoGroup == null)
            {
                throw new ResourceNotFoundException("ToDoGroupCouldNotBeFound");
            }

            await ToDoGroupOptionsListRepository.AddAsync(new ToDoGroupOptions
            {
                HideCompletedToDoItems = false,
                Id          = Guid.NewGuid(),
                SortedBy    = SortBy.CreatedDate,
                Theme       = "Green",
                ToDoGroupId = args.toDoGroupId,
                UserId      = args.anotherUserId
            }, cancellationToken);

            foreach (ToDoItem toDoItem in toDoGroup.Items)
            {
                await ToDoItemOptionsListRepository.AddAsync(new ToDoItemOptions
                {
                    Id            = Guid.NewGuid(),
                    ToDoItemId    = toDoItem.Id,
                    UserId        = args.anotherUserId,
                    ShowInMyDayOn = null
                }, cancellationToken);
            }

            return(await GetMyToDoGroups().FirstAsync(tdg => tdg.Id == args.toDoGroupId, cancellationToken));
        }