public async Task <OperationResult <bool> > ReorderPlaylist(data.Playlist playlist) { var sw = new Stopwatch(); sw.Start(); var result = false; var now = DateTime.UtcNow; if (playlist != null) { var looper = 0; foreach (var playlistTrack in this.DbContext.PlaylistTracks.Where(x => x.PlayListId == playlist.Id).OrderBy(x => x.CreatedDate)) { looper++; playlistTrack.ListNumber = looper; playlistTrack.LastUpdated = now; } await this.DbContext.SaveChangesAsync(); result = true; } return(new OperationResult <bool> { IsSuccess = result, Data = result }); }
public async Task <OperationResult <PlaylistList> > AddNewPlaylist(User user, Playlist model) { var playlist = new data.Playlist { IsPublic = model.IsPublic, Description = model.Description, Name = model.Name, UserId = user.Id }; this.DbContext.Playlists.Add(playlist); await this.DbContext.SaveChangesAsync(); var r = await this.AddTracksToPlaylist(playlist, model.Tracks.OrderBy(x => x.ListNumber).Select(x => x.Track.Id)); var request = new PagedRequest { FilterToPlaylistId = playlist.RoadieId }; var result = await this.List(request, user); return(new OperationResult <PlaylistList> { Data = result.Rows.First(), IsSuccess = true }); }
public async Task <OperationResult <bool> > AddTracksToPlaylist(data.Playlist playlist, IEnumerable <Guid> trackIds) { var sw = new Stopwatch(); sw.Start(); var result = false; var now = DateTime.UtcNow; var existingTracksForPlaylist = (from plt in this.DbContext.PlaylistTracks join t in this.DbContext.Tracks on plt.TrackId equals t.Id where plt.PlayListId == playlist.Id select t); var newTracksForPlaylist = (from t in this.DbContext.Tracks where (from x in trackIds select x).Contains(t.RoadieId) where !(from x in existingTracksForPlaylist select x.RoadieId).Contains(t.RoadieId) select t).ToArray(); foreach (var newTrackForPlaylist in newTracksForPlaylist) { this.DbContext.PlaylistTracks.Add(new data.PlaylistTrack { TrackId = newTrackForPlaylist.Id, PlayListId = playlist.Id }); } playlist.LastUpdated = now; await this.DbContext.SaveChangesAsync(); result = true; var r = await this.ReorderPlaylist(playlist); result = result && r.IsSuccess; await base.UpdatePlaylistCounts(playlist.Id, now); sw.Stop(); return(new OperationResult <bool> { IsSuccess = result, Data = result, OperationTime = sw.ElapsedMilliseconds }); }