Example #1
0
 public void PlaySong(SongBindingModel songBindingModel)
 {
     if (songBindingModel != null)
     {
         int songIndex = this.BindingModel.SongsBindingModel.Songs.IndexOf(songBindingModel);
         this.Logger.LogTask(this.playQueueService.PlayAsync(this.BindingModel.Playlist, this.BindingModel.SongsBindingModel.Songs.Select(s => s.Metadata), songIndex));
         this.MainFrame.IsBottomAppBarOpen = true;
     }
 }
Example #2
0
 public async Task ScrollIntoCurrentSongAsync(SongBindingModel songBindingModel)
 {
     await Task.Run(
         async() =>
     {
         if (this.presenter != null && songBindingModel != null)
         {
             SongsBindingModel songsBindingModel = this.presenter.BindingModel;
             if (songsBindingModel != null &&
                 songsBindingModel.Songs != null)
             {
                 await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, this.UpdateLayout);
                 await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => this.ListView.ScrollIntoView(songBindingModel));
             }
         }
     });
 }
Example #3
0
        public IHttpActionResult UpdateSong([FromUri] int id, [FromBody] SongBindingModel song)
        {
            var existingSong = this.Data.Songs.Find(id);

            if (existingSong == null)
            {
                return(this.NotFound());
            }

            var currentUser = this.Data.Users.Find(this.User.Identity.GetUserId());

            if (currentUser.Id != existingSong.UploaderId)
            {
                return(this.Unauthorized());
            }

            if (song == null)
            {
                return(this.BadRequest("Cannot create an empty song model."));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            existingSong.Title               = song.Title;
            existingSong.Artist              = song.Artist;
            existingSong.DateAdded           = DateTime.Now;
            existingSong.TrackNumber         = song.TrackNumber == null ? (int?)null : int.Parse(song.TrackNumber);
            existingSong.OriginalAlbumTitle  = song.OriginalAlbumTitle;
            existingSong.OriginalAlbumArtist = song.OriginalAlbumArtist;
            existingSong.OriginalDate        = song.OriginalDate == null ? (DateTime?)null : DateTime.Parse(song.OriginalDate);
            existingSong.Genre               = song.Genre;
            existingSong.Composer            = song.Composer;
            existingSong.Publisher           = song.Publisher;
            existingSong.Bpm = song.Bpm == null ? (int?)null : int.Parse(song.Bpm);

            this.Data.SaveChanges();

            var songToReturn = Mapper.Map <SongViewModel>(existingSong);

            return(this.Ok(songToReturn));
        }
        public void PlaySong(SongBindingModel songBindingModel)
        {
            int songIndex = this.BindingModel.Songs.IndexOf(songBindingModel);

            this.Logger.LogTask(this.playQueueService.PlayAsync(songIndex));
        }
 public void PlaySong(SongBindingModel songBindingModel)
 {
     this.Logger.LogTask(this.queueService.PlayAsync(this.BindingModel.SongsBindingModel.Songs.IndexOf(songBindingModel)));
 }
Example #6
0
        public IHttpActionResult AddSong([FromUri] int id, [FromBody] SongBindingModel song)
        {
            var album = this.Data.MusicAlbums.Find(id);

            if (album == null)
            {
                return(this.NotFound());
            }

            if (song == null)
            {
                return(this.BadRequest("Cannot create an empty song model."));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var user = this.Data.Users.Find(this.User.Identity.GetUserId());

            if (user.Id != album.AuthorId)
            {
                return(this.Unauthorized());
            }

            if (!this.ValidateAudioFileType(song.FileDataUrl))
            {
                return(this.BadRequest("Invalid file type. Valid file type includes .mp3 only"));
            }

            if (!this.ValidateFileSize(song.FileDataUrl, SongKilobyteLimit))
            {
                return(this.BadRequest(string.Format("Song size should be less than {0} kB.", SongKilobyteLimit)));
            }

            var metadataStart = song.FileDataUrl.IndexOf("data:audio/mp3;base64,", StringComparison.Ordinal);

            if (metadataStart != -1)
            {
                song.FileDataUrl = song.FileDataUrl.Remove(metadataStart, metadataStart + 22);
            }

            string googleDriveFileName = song.Artist + " - " + song.Title + ".mp3";

            string[] uploadResults = this.UploadSongToGoogleDrive(song.FileDataUrl, googleDriveFileName);

            if (uploadResults[0] == "success")
            {
                song.FileDataUrl = uploadResults[1];

                var newSong = new Song
                {
                    Title        = song.Title,
                    Artist       = song.Artist,
                    FilePath     = song.FileDataUrl,
                    MusicAlbumId = album.Id,
                    UploaderId   = album.AuthorId,
                    DateAdded    = DateTime.Now,
                    TrackNumber  =
                        song.TrackNumber == null ? (int?)null : int.Parse(song.TrackNumber),
                    OriginalAlbumTitle  = song.OriginalAlbumTitle,
                    OriginalAlbumArtist = song.OriginalAlbumArtist,
                    OriginalDate        =
                        song.OriginalDate == null
                                              ? (DateTime?)null
                                              : DateTime.Parse(song.OriginalDate),
                    Genre     = song.Genre,
                    Composer  = song.Composer,
                    Publisher = song.Publisher,
                    Bpm       = song.Bpm == null ? (int?)null : int.Parse(song.Bpm)
                };

                if (album.Songs.Contains(newSong))
                {
                    return(this.BadRequest("This song already exists in album."));
                }

                this.Data.Songs.Add(newSong);
                this.Data.SaveChanges();

                var userFollowers  = user.FollowedBy.Select(u => u.Id);
                var albumFollowers = album.Followers.Where(u => !userFollowers.Contains(u.Id)).Select(u => u.Id);

                foreach (var userId in userFollowers)
                {
                    var notification = new Notification()
                    {
                        SongId           = newSong.Id,
                        RecipientId      = userId,
                        NotificationType = NotificationType.AddedSong,
                        DateCreated      = DateTime.Now,
                        Message          = user.UserName + " added song."
                    };

                    this.Data.Notifications.Add(notification);
                }

                foreach (var userId in albumFollowers)
                {
                    var notification = new Notification()
                    {
                        SongId           = newSong.Id,
                        RecipientId      = userId,
                        NotificationType = NotificationType.AddedSong,
                        DateCreated      = DateTime.Now,
                        Message          = album.Title + " new song."
                    };

                    this.Data.Notifications.Add(notification);
                }

                this.Data.SaveChanges();

                var songToReturn = Mapper.Map <SongViewModel>(newSong);

                return(this.Ok(songToReturn));
            }
            else
            {
                return(this.BadRequest(uploadResults[1]));
            }
        }
 public IHttpActionResult AddSong([FromBody] SongBindingModel song)
 {
     this.Data.Songs.AddSong(song.Title, song.Genre, song.Year, song.ArtistName, song.AlbumTitle);
     this.Data.SaveChanges();
     return(this.Ok());
 }