Ejemplo n.º 1
0
        public ActionResult addtoPlaylist(FormCollection form)
        {
            String uname = User.Identity.GetUserName();
            String pname = form["Playlists"].ToString();

            if (pname != null)
            {
                //S["pname"] = pname;
                Session["uname"] = uname;
                //  return RedirectToAction("errord");
            }

            var id = db.playlists.Where(x => x.UserName == uname && x.PlaylistName == pname).Select(x => x.Playlistid).First();
            //  Console.WriteLine(id);
            int id2  = Convert.ToInt32(id);                 //changes
            int sid  = Convert.ToInt32(TempData["songid"]); //    var id2 = id.ToString();
            var item = new UserPlaylist
            {
                songid = sid,

                //playlistid = Int32.Parse(id)
                playlistid = id2 //changes
            };

            var existiong = db.userplaylists.Where(x => x.songid == item.songid && x.playlistid == item.playlistid).FirstOrDefault();

            if (existiong == null)
            {
                db.userplaylists.Add(item);
                db.SaveChanges();
                return(RedirectToAction("DisplaySong"));
            }
            TempData["Message"] = "Song is already added in this playlist";
            return(RedirectToAction("DisplaySong"));
        }
Ejemplo n.º 2
0
        public async Task ImportTracks(IEnumerable <FileInfo> files, UserPlaylist playlist)
        {
            if (_isEnabled)
            {
                throw new InvalidOperationException("The TrackImporter is already running");
            }
            _isEnabled = true;

            var extensions    = _musicDataManager.MusicManager.AudioEngine.SupportedExtensions;
            var filesToImport = files.Where(fileInfo => fileInfo.Exists && !string.IsNullOrEmpty(fileInfo.Extension)).ToList();
            var allFilesCount = (double)filesToImport.Count;

            for (int i = 0; i < filesToImport.Count; i++)
            {
                var fileInfo = filesToImport[i];
                ProgressMessageChanged?.Invoke(this, $"\"{fileInfo.Name}\"");
                ProgressChanged?.Invoke(this, i / allFilesCount);

                var track = await GetTrack(fileInfo, extensions);

                if (track != null && playlist != null && !playlist.Tracks.Contains(track))
                {
                    playlist.AddTrack(track);
                }

                if (_cancel)
                {
                    break;
                }
            }
            Finished?.Invoke(this, EventArgs.Empty);
            _isEnabled = false;
            _cancel    = false;
        }
Ejemplo n.º 3
0
        public int removefromplaylist(UserPlaylist p)
        {
            var playlistsong = new UserPlaylist
            {
                playlistid = Convert.ToInt32(Request.QueryString["PlaylistId"]),
                songid     = Convert.ToInt32(Request.QueryString["SongId"])
            };
            var obj = db.userplaylists.Where(x => x.playlistid == p.playlistid && x.songid == p.songid).FirstOrDefault();

            db.userplaylists.Remove(obj);

            db.SaveChanges();
            ViewBag.obj = obj;
            ViewBag.sid = p.songid;
            ViewBag.pid = p.playlistid;
            if (ViewBag.sid == null)
            {
                return(ViewBag.sid);
            }
            if (ViewBag.pid == null)
            {
                return(ViewBag.pid);
            }
            return(p.playlistid);
        }
Ejemplo n.º 4
0
        public async Task <bool> ChangeNameAsync(UserPlaylist playlist, string name)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Changing name for playlist with Id '{0}' to '{1}'.", playlist.ProviderPlaylistId, name);
            }

            bool result = await this.webService.ChangeNameAsync(playlist.ProviderPlaylistId, name);

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("The result of name changing for playlist with id '{0}' is '{1}'.", playlist.ProviderPlaylistId, result);
            }

            if (result)
            {
                playlist.Title     = name;
                playlist.TitleNorm = name.Normalize();
                await this.repository.UpdateAsync(playlist);

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddUpdatedPlaylists(playlist));
            }

            return(result);
        }
Ejemplo n.º 5
0
        public async Task <BaseResponse <Playlist> > CreatePlaylist(int userId, Playlist playlist)
        {
            var response = await Add(playlist);

            if (!response.Success)
            {
                return(response);
            }

            var user = await _userService.GetByKeys(userId);

            UserPlaylist userPlaylist = new UserPlaylist
            {
                PlaylistId = response.Resource.Id,
                Playlist   = response.Resource,
                UserId     = userId,
                User       = user,
                IsOwner    = true
            };

            try
            {
                await _userPlaylistRepository.Add(userPlaylist);

                await _unitOfWork.CompleteAsync();

                return(response);
            }
            catch (Exception e)
            {
                return(new BaseResponse <Playlist>($"An error occurred when adding the playlist: {e.Message}"));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UserPlaylistCreate(UserPlaylist userPlaylist)
        {
            // Request.Cookies.
            // PlaylistId = context.TblUserPlaylist.Count() +1,
            if (ModelState.IsValid)
            {
                UserPlaylist playlist = new UserPlaylist
                {
                    PlaylistName = userPlaylist.PlaylistName,
                    PlaylistDesc = userPlaylist.PlaylistDesc,
                    UserId       = userPlaylist.UserId
                };
                //   string id = Request.Cookies["UserName"];

                //playlist.UserId = 1;

                bool result = await repo.CreateUserPlaylist(userPlaylist);

                if (result)
                {
                    //return View("Index");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "An error occured while creating the UserPlaylist");
                }
            }
            return(View(userPlaylist));
        }
Ejemplo n.º 7
0
        private PlaylistsHolder()
        {
            playlists = new List <IPlaylist>();
            var          bitrates      = new StationsCollection();
            UserPlaylist smallPlaylist = new UserPlaylist();
            UserPlaylist largePlaylist = new UserPlaylist();
            Composition  song          = new Composition()
            {
                Name = "song"
            };
            Composition theme = new Composition()
            {
                Name = "theme"
            };
            Composition melody = new Composition()
            {
                Name = "melody"
            };

            smallPlaylist.Playlist.Add(song);
            smallPlaylist.Playlist.Add(theme);
            largePlaylist.Playlist.Add(song);
            largePlaylist.Playlist.Add(theme);
            largePlaylist.Playlist.Add(melody);



            playlists.Add(smallPlaylist);
            playlists.Add(largePlaylist);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("PlaylistId,PlaylistCreator,PlaylistName")] UserPlaylist userPlaylist)
        {
            if (id != userPlaylist.PlaylistId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userPlaylist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserPlaylistExists(userPlaylist.PlaylistId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userPlaylist));
        }
 public AddToSongMusicPlaylist(
     UserPlaylist userPlaylist,
     IEnumerable <Tuple <Song, IList <UserPlaylistEntry> > > addingSongs)
 {
     this.Playlist          = userPlaylist;
     this.SongContainsCount = addingSongs.Count(x => x.Item2.Any(e => e.PlaylistId == userPlaylist.PlaylistId));
 }
Ejemplo n.º 10
0
        public async Task RemovePlaylist(UserPlaylist playlist)
        {
            Playlists.Remove(playlist);
            PlaylistRemoved?.Invoke(this, playlist);

            using (
                var command =
                    new SQLiteCommand(
                        "DELETE FROM `Playlists` WHERE Guid=@guid", _connection))
            {
                command.Parameters.AddGuid("@guid", playlist.Id);

                await command.ExecuteNonQueryAsync();
            }

            using (
                var command =
                    new SQLiteCommand(
                        "DELETE FROM `PlaylistTracks` WHERE PlaylistId=@guid", _connection))
            {
                command.Parameters.AddGuid("@guid", playlist.Id);

                await command.ExecuteNonQueryAsync();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 更新歌单信息,只允许对歌单名字,是否公开,封面进行修改
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="listId"></param>
        /// <param name="playlist"></param>
        /// <returns></returns>
        public async Task <Result> UpdatePlaylist(long userId, string listId, UserPlaylist playlist)
        {
            if (!await ValidPlaylistOwner(userId, listId))
            {
                return(Result.FailResult("您不是歌单的拥有者哦", 403));
            }
            var updates = new List <UpdateDefinition <UserMusic> >();

            if (playlist.Name != null)
            {
                updates.Add(Builders <UserMusic> .Update.Set("playlists.$.name", playlist.Name));
            }
            if (playlist.Public.HasValue)
            {
                updates.Add(Builders <UserMusic> .Update.Set("playlists.$.public", playlist.Public.Value));
            }
            if (playlist.PicUrl != null)
            {
                updates.Add(Builders <UserMusic> .Update.Set("playlists.$.picUrl", playlist.PicUrl));
            }
            var update = Builders <UserMusic> .Update.Combine(updates);

            var filter = Builders <UserMusic> .Filter.ElemMatch(usr => usr.UserPlaylists,
                                                                Builders <UserPlaylist> .Filter.Eq(list => list.Id, listId));

            var updateResult = await this.userMusicCollection.UpdateOneAsync(filter, update);

            return(updateResult.MatchedCount > 0
                 ? Result.SuccessReuslt("更新成功") : Result.FailResult("更新失败,目标不存在!"));
        }
Ejemplo n.º 12
0
        public async Task <GoogleMusicPlaylistEntriesBatchResponse> AddSongsAsync(UserPlaylist userPlaylist, IDictionary <string, Song> songs)
        {
            if (songs == null)
            {
                throw new ArgumentNullException("songs");
            }

            var json = new
            {
                mutations = songs.Select(song =>
                                         new
                {
                    create = new
                    {
                        clientId              = song.Key,
                        creationTimestamp     = "-1",
                        deleted               = false,
                        lastModifiedTimestamp = "0",
                        playlistId            = userPlaylist.PlaylistId,
                        source  = song.Value.TrackType == StreamType.EphemeralSubscription ? 2 : 1,
                        trackId = song.Value.SongId
                    }
                }
                                         ).ToArray()
            };

            return(await this.googleMusicApisService.PostAsync <GoogleMusicPlaylistEntriesBatchResponse>(PlEntriesBatch, json));
        }
Ejemplo n.º 13
0
 public async Task <IActionResult> AddFile(IFormFile uploadedFile)
 {
     if (uploadedFile != null)
     {
         // путь к папке Files
         string path = "/Songs/" + RemoveSpaces(uploadedFile.FileName);
         // сохраняем файл в папку Files в каталоге wwwroot
         using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
         {
             await uploadedFile.CopyToAsync(fileStream);
         }
         Song file = new Song {
             Name = uploadedFile.FileName, URL = path
         };
         _context.Songs.Add(file);
         _context.SaveChanges();
         var          user         = from s in _context.Users where s.Name == User.Identity.Name select s.ID;
         int          id           = user.FirstOrDefault();
         UserPlaylist userPlaylist = new UserPlaylist {
             SongID = file.ID, UserID = id
         };
         _context.UserPlaylist.Add(userPlaylist);
         _context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 14
0
        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Playlists`", connection))
            {
                var reader = await command.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    var playlist = new UserPlaylist {
                        Name = reader.GetString(0), Id = reader.GetGuid(1)
                    };
                    using (var trackCommando = new SQLiteCommand("SELECT * FROM `PlaylistTracks` WHERE PlaylistId=@guid", connection))
                    {
                        trackCommando.Parameters.AddGuid("@guid", playlist.Id);
                        var trackReader = trackCommando.ExecuteReader();
                        while (await trackReader.ReadAsync())
                        {
                            playlist.Tracks.Add(_trackProvider.Collection[trackReader.GetGuid(1)]);
                        }
                    }
                    playlist.TrackAdded   += Playlist_TrackAdded;
                    playlist.TrackRemoved += Playlist_TrackRemoved;

                    Playlists.Add(playlist);
                }
            }

            _connection = connection;
        }
Ejemplo n.º 15
0
        private async Task LoadPlaylistsAsync(IProgress <double> progress)
        {
            await progress.SafeReportAsync(0.0d);

            this.logger.Debug("LoadPlaylistsAsync: loading playlists.");
            var playlists = await this.playlistsWebService.GetAllAsync();

            await progress.SafeReportAsync(0.6d);

            this.logger.Debug("LoadPlaylistsAsync: inserting playlists into database.");
            if (playlists.Playlists != null)
            {
                var entries = new List <UserPlaylistEntry>();

                foreach (var googleUserPlaylist in playlists.Playlists)
                {
                    var userPlaylist = new UserPlaylist
                    {
                        ProviderPlaylistId = googleUserPlaylist.PlaylistId,
                        Title     = googleUserPlaylist.Title,
                        TitleNorm = googleUserPlaylist.Title.Normalize()
                    };

                    await this.userPlaylistsRepository.InsertAsync(userPlaylist);

                    if (googleUserPlaylist.Playlist != null)
                    {
                        for (int index = 0; index < googleUserPlaylist.Playlist.Count; index++)
                        {
                            GoogleMusicSong googleSong = googleUserPlaylist.Playlist[index];

                            Song song;
                            if (!this.songEntities.TryGetValue(googleSong.Id, out song))
                            {
                                song           = googleSong.ToSong();
                                song.IsLibrary = false;
                                await this.songsRepository.InsertAsync(new[] { song });

                                this.songEntities.Add(googleSong.Id, song);
                            }

                            var entry = new UserPlaylistEntry
                            {
                                ProviderEntryId = googleSong.PlaylistEntryId,
                                PlaylistOrder   = index,
                                SongId          = song.SongId,
                                PlaylistId      = userPlaylist.PlaylistId
                            };

                            entries.Add(entry);
                        }
                    }
                }

                await this.userPlaylistsRepository.InsertEntriesAsync(entries);
            }

            await progress.SafeReportAsync(1.0d);
        }
Ejemplo n.º 16
0
        public static UserPlaylist ToUserPlaylist(this GoogleMusicPlaylist googleMusicPlaylist)
        {
            var userPlaylist = new UserPlaylist();

            Mapper(googleMusicPlaylist, userPlaylist);

            return(userPlaylist);
        }
Ejemplo n.º 17
0
 public Task DeleteAsync(UserPlaylist playlist)
 {
     return(this.Connection.RunInTransactionAsync(
                (connection) =>
     {
         connection.Execute(SqlDeletePlaylistEntries, playlist.Id);
         connection.Delete <UserPlaylist>(playlist.Id);
     }));
 }
Ejemplo n.º 18
0
        public async Task <bool> AddSongsAsync(UserPlaylist playlist, IEnumerable <Song> songs)
        {
            if (songs == null)
            {
                throw new ArgumentNullException("songs");
            }

            List <Song> list = songs.ToList();

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Adding {0} songs to playlist '{1}'.", list.Count, playlist.ProviderPlaylistId);
            }

            var result = await this.webService.AddSongsAsync(playlist.ProviderPlaylistId, list.Select(s => s.ProviderSongId).ToArray());

            if (result != null)
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug(
                        "Successfully added '{0}' songs to playlist {1}.",
                        list.Count,
                        playlist.ProviderPlaylistId);
                }

                IList <UserPlaylistEntry> entries = new List <UserPlaylistEntry>();

                int index = 0;

                foreach (var songIdResp in result.SongIds)
                {
                    var storedSong = list.FirstOrDefault(x => string.Equals(x.ProviderSongId, songIdResp.SongId, StringComparison.OrdinalIgnoreCase));

                    if (storedSong.SongId <= 0)
                    {
                        await this.songsRepository.InsertAsync(new[] { storedSong });
                    }

                    entries.Add(new UserPlaylistEntry()
                    {
                        SongId          = storedSong.SongId,
                        ProviderEntryId = songIdResp.PlaylistEntryId,
                        PlaylistOrder   = playlist.SongsCount + index,
                        PlaylistId      = playlist.PlaylistId
                    });

                    index++;
                }

                await this.repository.InsertEntriesAsync(entries);

                return(true);
            }

            return(false);
        }
        public async Task UpdateAsync(UserPlaylist playlist, BaseItem[] newItems)
        {
            using (PerfLogger.Create("UpdatePlaylistItems",
                                     () => new { playlistName = playlist.Name, newItemsCount = newItems.Length }))

            {
                await _decorated.UpdateAsync(playlist, newItems).ConfigureAwait(false);
            }
        }
Ejemplo n.º 20
0
        public async Task <bool> AddSongsAsync(UserPlaylist playlist, IEnumerable <Song> songs)
        {
            if (songs == null)
            {
                throw new ArgumentNullException("songs");
            }

            var dictionary = songs.ToDictionary(x => Guid.NewGuid().ToString().ToLowerInvariant(), x => x);

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Adding {0} songs to playlist '{1}'.", dictionary.Count, playlist.PlaylistId);
            }

            List <UserPlaylistEntry> toInsert = new List <UserPlaylistEntry>();

            var result = await this.webService.AddSongsAsync(playlist, dictionary);

            if (result != null)
            {
                for (int index = 0; index < result.MutateResponse.Length; index++)
                {
                    var mutation = result.MutateResponse[index];
                    if (string.Equals(mutation.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
                    {
                        var song = dictionary[mutation.ClientId];
                        toInsert.Add(
                            new UserPlaylistEntry()
                        {
                            Id            = mutation.Id,
                            CliendId      = mutation.ClientId,
                            SongId        = song.SongId,
                            CreationDate  = DateTime.UtcNow,
                            LastModified  = DateTime.UtcNow,
                            Source        = song.TrackType == StreamType.EphemeralSubscription ? 2 : 1,
                            PlaylistOrder = ((1729000000000000000L) + DateTime.UtcNow.Millisecond * 1000L + index).ToString("G"),
                            PlaylistId    = playlist.PlaylistId
                        });
                    }
                    else
                    {
                        this.logger.Debug(
                            "Could not add song to playlist {1} because {2}.",
                            playlist.Id,
                            mutation.ResponseCode);
                    }
                }
            }

            if (toInsert.Count > 0)
            {
                await this.repository.InsertEntriesAsync(toInsert);
            }

            return(toInsert.Count > 0);
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("PlaylistId,PlaylistCreator,PlaylistName")] UserPlaylist userPlaylist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userPlaylist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userPlaylist));
        }
Ejemplo n.º 22
0
        public async Task <bool> RemoveSongsAsync(UserPlaylist playlist, IEnumerable <Song> songs)
        {
            if (playlist == null)
            {
                throw new ArgumentNullException("playlist");
            }

            if (songs == null)
            {
                throw new ArgumentNullException("songs");
            }

            List <UserPlaylistEntry> list = songs.Select(x => x.UserPlaylistEntry).ToList();

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Removing entries from playlist '{0}'.", playlist.PlaylistId);
            }

            var resp = await this.webService.RemoveSongsAsync(playlist, list);

            List <UserPlaylistEntry> toDelete = new List <UserPlaylistEntry>();

            foreach (var mutation in resp.MutateResponse)
            {
                if (string.Equals(mutation.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
                {
                    var entry =
                        list.FirstOrDefault(x => string.Equals(x.Id, mutation.Id, StringComparison.OrdinalIgnoreCase));
                    if (entry != null)
                    {
                        toDelete.Add(entry);
                    }
                }
                else
                {
                    this.logger.Debug(
                        "Entry '{0}' was NOT deleted from server with response '{1}'.",
                        mutation.Id,
                        mutation.ResponseCode);
                }
            }

            if (toDelete.Count > 0)
            {
                await this.repository.DeleteEntriesAsync(toDelete);
            }

            return(toDelete.Count > 0);
        }
Ejemplo n.º 23
0
        public int removeplaylist(UserPlaylist p)
        {
            var playlistsong = new UserPlaylist
            {
                playlistid = Convert.ToInt32(Request.QueryString["PlaylistId"]),
            };
            var uname = User.Identity.GetUserName();
            var obj   = db.playlists.Where(x => x.Playlistid == p.playlistid && x.UserName == uname).FirstOrDefault();

            db.playlists.Remove(obj);

            db.SaveChanges();
            return(p.playlistid);
        }
 public PlaylistEditPopupViewPresenter(
     ISearchService searchService,
     IUserPlaylistsService userPlaylistsService,
     UserPlaylist userPlaylist)
 {
     this.searchService        = searchService;
     this.userPlaylistsService = userPlaylistsService;
     this.userPlaylist         = userPlaylist;
     this.SaveCommand          = new DelegateCommand(this.Save, this.CanSave);
     this.CancelCommand        = new DelegateCommand(this.Cancel);
     this.Title = !string.IsNullOrEmpty(this.userPlaylist.PlaylistId)
                ? this.userPlaylist.Title
                : DateTime.Now.ToString(CultureInfo.CurrentCulture);
 }
Ejemplo n.º 25
0
        public async Task <bool> RemoveSongsAsync(UserPlaylist playlist, IEnumerable <Song> songs)
        {
            if (playlist == null)
            {
                throw new ArgumentNullException("playlist");
            }

            if (songs == null)
            {
                throw new ArgumentNullException("songs");
            }

            List <Song> list = songs.ToList();

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Removing entries from playlist '{0}'.", playlist.ProviderPlaylistId);
            }

            string[] songIds  = new string[list.Count];
            string[] entryIds = new string[list.Count];

            for (int index = 0; index < list.Count; index++)
            {
                var song = list[index];
                songIds[index] = song.ProviderSongId;

                if (song.UserPlaylistEntry == null)
                {
                    throw new ArgumentException("Songs should be collection of songs with playlist entries.", "songs");
                }

                entryIds[index] = song.UserPlaylistEntry.ProviderEntryId;
            }

            var result = await this.webService.RemoveSongsAsync(playlist.ProviderPlaylistId, songIds, entryIds);

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Result of entry removing entries from playlist '{0}' is '{1}'.", playlist.ProviderPlaylistId, result);
            }

            if (result)
            {
                await this.repository.DeleteEntriesAsync(list.Select(s => s.UserPlaylistEntry));
            }

            return(result);
        }
Ejemplo n.º 26
0
        public async Task UpdateUserPlaylist()
        {
            var userId     = 4;
            var listId     = "5edb579918e5443984d76a12";
            var updateList = new UserPlaylist()
            {
                Name   = "不爱我就放了我",
                Public = false
            };
            var result = await Client.PutAsync <UserPlaylist, TestResult <object> >
                             ($"/api/playlist/user/update?loginUserId={userId}&id={listId}", updateList);

            // Assert
            Assert.Equal(200, result.Code);
        }
Ejemplo n.º 27
0
 private void PlaylistProvider_PlaylistRemoved(object sender, UserPlaylist e)
 {
     foreach (var viewItem in ViewItems)
     {
         var playlistView = viewItem as PlaylistView;
         if (playlistView == null)
         {
             continue;
         }
         if (playlistView.Playlist == e)
         {
             ViewItems.Remove(viewItem);
             break;
         }
     }
 }
Ejemplo n.º 28
0
        public Task AddPlaylist(UserPlaylist playlist)
        {
            Playlists.Add(playlist);
            PlaylistAdded?.Invoke(this, playlist);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Playlists` (Name, Guid) VALUES (@name, @guid)", _connection))
            {
                command.Parameters.AddWithValue("@name", playlist.Name);
                command.Parameters.AddGuid("@guid", playlist.Id);

                return(command.ExecuteNonQueryAsync());
            }
        }
Ejemplo n.º 29
0
 public static void Mapper(GoogleMusicPlaylist googleMusicPlaylist, UserPlaylist userPlaylist)
 {
     userPlaylist.PlaylistId   = googleMusicPlaylist.Id;
     userPlaylist.Title        = googleMusicPlaylist.Name;
     userPlaylist.TitleNorm    = googleMusicPlaylist.Name.Normalize();
     userPlaylist.CreationDate =
         DateTimeExtensions.FromUnixFileTime(googleMusicPlaylist.CreationTimestramp / 1000);
     userPlaylist.LastModified =
         DateTimeExtensions.FromUnixFileTime(googleMusicPlaylist.LastModifiedTimestamp / 1000);
     userPlaylist.RecentDate           = DateTimeExtensions.FromUnixFileTime(googleMusicPlaylist.RecentTimestamp / 1000);
     userPlaylist.Type                 = googleMusicPlaylist.Type;
     userPlaylist.ShareToken           = googleMusicPlaylist.ShareToken;
     userPlaylist.OwnerName            = googleMusicPlaylist.OwnerName;
     userPlaylist.OwnerProfilePhotoUrl = googleMusicPlaylist.OwnerProfilePhotoUrl;
     userPlaylist.AccessControlled     = googleMusicPlaylist.AccessControlled;
 }
Ejemplo n.º 30
0
        public async Task CreateUserPlaylist()
        {
            // Arrange
            var userId = 32;
            var list   = new UserPlaylist()
            {
                Name   = "一人一首成名曲",
                PicUrl = "https://p2.music.126.net/W6cLGyzro66Q2MYy3TYU8w==/109951162869093110.jpg",
                Tracks = new List <DataAbstract.MusicInfo>(),
                Public = true
            };

            var result = await Client.PostAsync <UserPlaylist, TestResult <UserPlaylist> >
                             ($"/api/playlist/user/create?loginUserId={userId}", list);

            Assert.Equal(200, result.Code);
            Assert.NotNull(result.Content.Id);
        }