示例#1
0
        public static async Task <Domain.Entities.Group> CheckUserGroupInviteValidAsync(
            string groupInviteIdentifier,
            Guid userId,
            IRepositoryManager repositoryManager)
        {
            groupInviteIdentifier = groupInviteIdentifier.ToUpperInvariant();

            try
            {
                var groupInviteExists = await CheckGroupInviteExistsByIdentifierAsync(
                    groupInviteIdentifier,
                    repositoryManager.GroupInviteRepository).ConfigureAwait(false);

                if (groupInviteExists)
                {
                    var groupInvite = await repositoryManager.GroupInviteRepository.GetByIdentifierAsync(groupInviteIdentifier);

                    var groupInviteIsValid = ValidateGroupInvite(groupInvite);

                    if (groupInviteIsValid)
                    {
                        var userIsMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync(
                            groupInvite.GroupId,
                            userId,
                            repositoryManager.GroupMemberRepository);

                        if (!userIsMemberOfGroup)
                        {
                            var group = await repositoryManager.GroupRepository.GetByIdForDownloadAsync(groupInvite.GroupId);

                            return(group);
                        }
                        else
                        {
                            throw new UserAlreadyGroupMemberException(
                                      "You are already a member of this group",
                                      "You are already a member of this group");
                        }
                    }
                    else
                    {
                        throw new InvalidTokenException(InvalidTokenType.TokenExpired, "This Group Invite has expired");
                    }
                }
                else
                {
                    throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "This Group Invite is invalid");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public static async Task <GroupPlaylist> GetGroupPlaylistAsync(
            string groupIdentifier,
            string groupPlaylistIdentifier,
            Guid userId,
            IRepositoryManager repositoryManager)
        {
            groupIdentifier         = groupIdentifier.ToUpperInvariant();
            groupPlaylistIdentifier = groupPlaylistIdentifier.ToUpperInvariant();

            try
            {
                var group = await repositoryManager.GroupRepository.GetByIdentifierAsync(groupIdentifier);

                if (group != null)
                {
                    var isUserMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync(
                        groupIdentifier,
                        userId,
                        repositoryManager);

                    if (isUserMemberOfGroup)
                    {
                        return(await repositoryManager.GroupPlaylistRepository.GetByIdentifierAndGroupIdAsync(groupPlaylistIdentifier, group.Id));
                    }
                    else
                    {
                        throw new UserNotGroupMemberException(
                                  "You are not able to perform this action",
                                  "You are not able to perform this action");
                    }
                }
                else
                {
                    throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group was not found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
        public static async Task <string> CreateNewGroupInviteAsync(
            string groupIdentifier,
            Guid userId,
            IRepositoryManager repositoryManager)
        {
            groupIdentifier = groupIdentifier.ToUpperInvariant();

            try
            {
                var group = await repositoryManager.GroupRepository.GetByIdentifierAsync(groupIdentifier);

                if (group != null)
                {
                    var isUserMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync(
                        groupIdentifier,
                        userId,
                        repositoryManager);

                    if (isUserMemberOfGroup)
                    {
                        var existingGroupInviteIdentifierByUser = (await repositoryManager.GroupInviteRepository.FindAsync(gi =>
                                                                                                                           gi.GroupId == group.Id &&
                                                                                                                           gi.CreatedBy == userId &&
                                                                                                                           gi.ExpiryDate > DateTime.Now)).FirstOrDefault();

                        if (existingGroupInviteIdentifierByUser == null)
                        {
                            var newGroupInviteIdentifier = await GenerateNewGroupInviteIdentifierAsync(
                                group.Id,
                                repositoryManager.GroupInviteRepository).ConfigureAwait(false);

                            var newGroupInviteExpiryDate = DateTime.Now.AddDays(IdentifierConsts.GroupInviteIdentifierExpiryOffsetDays);

                            var newGroupInvite = new GroupInvite
                            {
                                GroupId       = group.Id,
                                Identifier    = newGroupInviteIdentifier,
                                ExpiryDate    = newGroupInviteExpiryDate,
                                CreatedOn     = DateTime.Now,
                                CreatedBy     = userId,
                                LastUpdatedOn = DateTime.Now,
                                LastUpdatedBy = userId
                            };

                            await repositoryManager.GroupInviteRepository.AddAsync(newGroupInvite);

                            return(newGroupInviteIdentifier);
                        }
                        else
                        {
                            return(existingGroupInviteIdentifierByUser.Identifier);
                        }
                    }
                    else
                    {
                        throw new UserNotGroupMemberException(
                                  "You are not able to perform this action",
                                  "You are not able to perform this action");
                    }
                }
                else
                {
                    throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group was not found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static async Task <GroupPlaylistRating> CreateNewGroupPlaylistRatingAsync(
            string groupIdentifier,
            string groupPlaylistIdentifier,
            GroupPlaylistRating groupPlaylistRating,
            Guid userId,
            IRepositoryManager repositoryManager)
        {
            groupIdentifier         = groupIdentifier.ToUpperInvariant();
            groupPlaylistIdentifier = groupPlaylistIdentifier.ToUpperInvariant();

            try
            {
                var group = await repositoryManager.GroupRepository.GetByIdentifierAsync(groupIdentifier);

                if (group != null)
                {
                    var isUserMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync(
                        groupIdentifier,
                        userId,
                        repositoryManager);

                    if (isUserMemberOfGroup)
                    {
                        var groupPlaylist = await repositoryManager.GroupPlaylistRepository.GetByIdentifierAndGroupIdAsync(
                            groupPlaylistIdentifier,
                            group.Id);

                        if (groupPlaylist != null)
                        {
                            var existingGroupPlaylistRating = (await repositoryManager.GroupPlaylistRatingRepository.FindAsync(gsr =>
                                                                                                                               gsr.GroupPlaylistId == groupPlaylist.Id &&
                                                                                                                               gsr.CreatedBy == userId)).FirstOrDefault();

                            if (existingGroupPlaylistRating != null)
                            {
                                existingGroupPlaylistRating.OverallRating = groupPlaylistRating.OverallRating;
                                existingGroupPlaylistRating.Comment       = groupPlaylistRating.Comment;
                                groupPlaylistRating.LastUpdatedOn         = DateTime.Now;
                                groupPlaylistRating.LastUpdatedBy         = userId;

                                return(await repositoryManager.GroupPlaylistRatingRepository.UpdateAsync(existingGroupPlaylistRating));
                            }
                            else
                            {
                                groupPlaylistRating.GroupPlaylistId = groupPlaylist.Id;
                                groupPlaylistRating.CreatedOn       = DateTime.Now;
                                groupPlaylistRating.CreatedBy       = userId;
                                groupPlaylistRating.LastUpdatedOn   = DateTime.Now;
                                groupPlaylistRating.LastUpdatedBy   = userId;

                                return(await repositoryManager.GroupPlaylistRatingRepository.AddAsync(groupPlaylistRating));
                            }
                        }
                        else
                        {
                            throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group Playlist was not found");
                        }
                    }
                    else
                    {
                        throw new UserNotGroupMemberException(
                                  "You are not able to perform this action",
                                  "You are not able to perform this action");
                    }
                }
                else
                {
                    throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group was not found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        public static async Task <string> CreateNewGroupPlaylistAsync(
            GroupPlaylistUploadModel groupPlaylistUploadModel,
            Guid userId,
            IRepositoryManager repositoryManager,
            IMapper mapper,
            SpotifyAPICredentials spotifyAPICredentials)
        {
            var groupIdentifier = groupPlaylistUploadModel.GroupIdentifier.ToUpperInvariant();

            try
            {
                var group = await repositoryManager.GroupRepository.GetByIdentifierAsync(groupIdentifier);

                if (group != null)
                {
                    var isUserMemberOfGroup = await GroupMemberModel.CheckGroupMemberExistsAsync(
                        groupPlaylistUploadModel.GroupIdentifier,
                        userId,
                        repositoryManager);

                    if (isUserMemberOfGroup)
                    {
                        var newGroupPlaylistIdentifier = await GenerateNewGroupPlaylistIdentifierAsync(
                            group.Id,
                            repositoryManager.GroupPlaylistRepository).ConfigureAwait(false);

                        var newGroupPlaylist = new GroupPlaylist
                        {
                            GroupId       = group.Id,
                            Identifier    = newGroupPlaylistIdentifier,
                            CreatedOn     = DateTime.Now,
                            CreatedBy     = userId,
                            LastUpdatedOn = DateTime.Now,
                            LastUpdatedBy = userId
                        };

                        var existingPlaylist = await repositoryManager.PlaylistRepository.CheckExistsBySpotifyIdAsync(
                            groupPlaylistUploadModel.PlaylistIdentifier);

                        if (existingPlaylist != null)
                        {
                            newGroupPlaylist.PlaylistId = existingPlaylist.Id;
                        }
                        else
                        {
                            var newPlaylist = await PlaylistModel.IndexNewPlaylistAsync(
                                groupPlaylistUploadModel.PlaylistIdentifier,
                                userId,
                                repositoryManager,
                                mapper,
                                spotifyAPICredentials);

                            newGroupPlaylist.PlaylistId = newPlaylist.Id;
                        }

                        await repositoryManager.GroupPlaylistRepository.AddAsync(newGroupPlaylist);

                        return(newGroupPlaylistIdentifier);
                    }
                    else
                    {
                        throw new UserNotGroupMemberException(
                                  "You are not able to perform this action",
                                  "You are not able to perform this action");
                    }
                }
                else
                {
                    throw new InvalidTokenException(InvalidTokenType.TokenNotFound, "The requested Group was not found");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }