示例#1
0
        public Task<string> GetSharedPlaylist(List<long> tracksId)
        {
            var currentUser = AzimuthIdentity.Current;

            return Task.Run(() =>
            {
                string guid;

                using (var unitOfWork = _unitOfWorkFactory.NewUnitOfWork())
                {
                    var trackRepository = unitOfWork.GetRepository<Track>();
                    var sharedPlaylistRepository = unitOfWork.GetRepository<SharedPlaylist>();

                    var tracks = trackRepository.Get(tr => tracksId.Contains(tr.Id)).ToList();
                    guid = Guid.NewGuid().ToString();

                    var sysUser = unitOfWork.UserRepository
                        .GetOne(p => p.Name.FirstName == "Azimuth" && p.Name.LastName == "Azimuth");

                    var fakePlaylist = new Playlist
                    {
                        Name = "Share_" + guid,
                        Creator = sysUser,
                        Accessibilty = Accessibilty.Shared
                    };

                    foreach (var track in tracks)
                    {
                        fakePlaylist.Tracks.Add(track);
                    }

                    unitOfWork.PlaylistRepository.AddItem(fakePlaylist);

                    var sharedPlaylist = new SharedPlaylist
                    {
                        Guid = guid,
                        Playlist = fakePlaylist
                    };

                    sharedPlaylistRepository.AddItem(sharedPlaylist);

                    var user = unitOfWork.UserRepository.GetOne(u => u.Id == currentUser.UserCredential.Id);

                    var notification = _notificationService.CreateNotification(Notifications.PlaylistShared, user,
                        recentlyPlaylist: fakePlaylist);

                    fakePlaylist.Notifications.Add(notification);
                    unitOfWork.NotificationRepository.AddItem(notification);
                    
                    unitOfWork.Commit();
                }
                
                return guid;
            });
        }
示例#2
0
        public void AddSharing()
        {
            using (var unitOfWork = _kernel.Get<IUnitOfWork>())
            {
                var playlistRepo = unitOfWork.GetRepository<Playlist>();
                var userRepo = unitOfWork.GetRepository<User>();

                var sysUser = new User
                {
                    Name = new Name{FirstName = "Admin", LastName = "Admin"}
                };
                userRepo.AddItem(sysUser);

                var playlist = playlistRepo.GetAll().First();

                var fakePlaylist = new Playlist
                {
                    Creator = sysUser, Name = "Fake", Accessibilty = Accessibilty.Public
                };

                foreach (var track in playlist.Tracks)
                {
                    fakePlaylist.Tracks.Add(track);
                }

                playlistRepo.AddItem(fakePlaylist);

                var sharedPlaylist = new SharedPlaylist
                {
                    Guid = Guid.NewGuid().ToString(), Playlist = fakePlaylist
                };

                var spRepo = unitOfWork.GetRepository<SharedPlaylist>();

                spRepo.AddItem(sharedPlaylist);

                unitOfWork.Commit();
            }
        }
示例#3
0
        public Task<string> GetSharedPlaylist(int playlistId)
        {
            return Task.Run(() =>
            {
                string guid;
                using (var unitOfWork = _unitOfWorkFactory.NewUnitOfWork())
                {
                    var sharedPlaylistRepository = unitOfWork.GetRepository<SharedPlaylist>();

                    var currentPlaylist = unitOfWork.PlaylistRepository.GetOne(p => p.Id == playlistId);
                    if (currentPlaylist == null)
                    {
                        return "";
                    }

                    var sysUser = unitOfWork.UserRepository
                        .GetOne(p => p.Name.FirstName == "Azimuth" && p.Name.LastName == "Azimuth");                                

                    guid = Guid.NewGuid().ToString();
                    var fakePlaylist = new Playlist
                    {
                        Name = "Share_" + guid,
                        Creator = sysUser,
                        Accessibilty = Accessibilty.Shared
                    };

                    foreach (var track in currentPlaylist.Tracks)
                    {
                        fakePlaylist.Tracks.Add(track);
                    }

                    unitOfWork.PlaylistRepository.AddItem(fakePlaylist);

                    var sharedPlaylist = new SharedPlaylist
                    {
                        Guid = guid,
                        Playlist = fakePlaylist
                    };
                    sharedPlaylistRepository.AddItem(sharedPlaylist);

                    var notification = _notificationService.CreateNotification(Notifications.PlaylistShared, currentPlaylist.Creator,
                        recentlyPlaylist: fakePlaylist);

                    fakePlaylist.Notifications.Add(notification);
                    unitOfWork.NotificationRepository.AddItem(notification);

                    unitOfWork.Commit();
                }

                return guid;
            });
        }