private async void DownloadSongBtn_Clicked(object sender, EventArgs e)
        {
            try
            {
                SongGetRequest obj = model.GetSongByIdOffline(model._songId);
                if (obj != null)
                {
                    UserDialogs.Instance.Toast(ValidationHelpers.MessagesResource.already_downloaded);
                    return;
                }
                else
                {
                    await model.DownloadSongOffline();

                    UserDialogs.Instance.Toast(ValidationHelpers.MessagesResource.download_success);
                }
            }
            catch (FlurlHttpException ex)
            {
                if (ex.Call.HttpStatus == System.Net.HttpStatusCode.Unauthorized)
                {
                    SecureStorage.Remove("username");
                    SecureStorage.Remove("password");
                    Application.Current.MainPage = new NavigationPage(new Views.LoginPage());
                }
                else
                {
                    await Navigation.PushAsync(new ErrorPage());
                }
            }
        }
Ejemplo n.º 2
0
        private async void btnEditSong_Click(object sender, EventArgs e)
        {
            HelperMethods.CloseForm("frmSongDetails");
            SongGetRequest song = await _songService.GetById <SongGetRequest>(_id, "GetSongById");

            frmEditSong frm = new frmEditSong(_id);

            frm.Show();
        }
        public List <SongGetRequest> GetRecommendedSongs(int songId)
        {
            int userId = _userService.GetMyProfile().Id;
            List <SongGetRequest> recommenededSongs = new List <SongGetRequest>();

            if (userId != 0)
            {
                SongGetRequest selectedSong    = _mapper.Map <SongGetRequest>(_context.Song.Include(x => x.Album).Include(x => x.Album.Genre).Where(x => x.Id == songId).FirstOrDefault());
                int            selectedSongId  = selectedSong.Id;
                int            selectedGenreId = selectedSong.Album.GenreId;

                //get average rates of all songs
                List <AverageRate> averageRates = _context.UsersSongRates.Where(x => x.UserId != userId)
                                                  .Join(
                    _context.Song,
                    rate => rate.SongId,
                    song => song.Id,
                    (rate, song) => new
                {
                    song.Title,
                    rate.Rate,
                    rate.SongId,
                })
                                                  .GroupBy(p => p.SongId)
                                                  .Select(g => new AverageRate {
                    Id = g.First().SongId, Title = g.First().Title, AvgRate = Math.Round(Convert.ToDouble(g.Sum(x => x.Rate)) / g.Count(), 1)
                }).OrderByDescending(x => x.AvgRate).ToList();

                List <AverageRate> avgRatesHigherThanPosRating = new List <AverageRate>();
                foreach (AverageRate item in averageRates)
                {
                    if (item.AvgRate > positiveRating)
                    {
                        avgRatesHigherThanPosRating.Add(item);
                    }
                }

                List <int> recommendedSongIds = new List <int>();
                recommendedSongIds = avgRatesHigherThanPosRating.Where(x => x.Id != songId).Select(x => x.Id).Distinct().ToList();

                if (recommendedSongIds.Count() > 0)
                {
                    foreach (int id in recommendedSongIds)
                    {
                        //list of songs where genre is the same as genre of selected song
                        SongGetRequest s = _mapper.Map <SongGetRequest>(_context.Song.Include(a => a.Album).Where(x => x.Id == id && x.Album.GenreId == selectedGenreId).FirstOrDefault());
                        if (s != null)
                        {
                            recommenededSongs.Add(s);
                        }
                    }
                }
            }
            return(recommenededSongs);
        }
Ejemplo n.º 4
0
        private async void FrmSongDetails_Load(object sender, EventArgs e)
        {
            if (!_id.Equals(null))
            {
                SongGetRequest song = await _songService.GetById <SongGetRequest>(_id, "GetSongById");

                txtboxLyrics.Text = song.Text;
                txtBoxTitle.Text  = song.Title;
                txtboxAlbum.Text  = song.Album.Name;
                txtboxGenre.Text  = song.Album.Genre.Name;
                picboxAlbum.Image = ImageHelperMethods.ResizeImage(ImageHelperMethods.PrepareImgForDisplayFromDB(song.Album.Image), 100, 100);
            }
        }
        private async void frmEditSong_Load(object sender, EventArgs e)
        {
            SongGetRequest song = await _songService.GetById <SongGetRequest>(_songId, "GetSongById");


            cmbPerformer.DataSource = await _performerService.Get <List <Performer> >(null, "GetPerformers");

            cmbPerformer.DisplayMember = "ArtisticName";
            cmbPerformer.ValueMember   = "Id";
            cmbPerformer.SelectedValue = song.Album.PerformerId;

            cmbAlbum.DataSource = await _albumService.Get <List <Album> >(cmbPerformer.SelectedValue, "GetAlbumsByPerformerId");

            cmbAlbum.DisplayMember = "Name";
            cmbAlbum.ValueMember   = "Id";
            cmbAlbum.SelectedValue = song.Album.Id;

            txtName.Text   = song.Title;
            txtLyrics.Text = song.Text;
        }
Ejemplo n.º 6
0
        public async static Task DownloadSong(SongGetRequest song)
        {
            string storedSongIds = await SecureStorage.GetAsync("SongIds");

            if (string.IsNullOrWhiteSpace(storedSongIds))
            {
                storedSongIds = song.Id.ToString();
            }
            else
            {
                storedSongIds += "," + song.Id.ToString();
            }

            await SecureStorage.SetAsync("SongIds", storedSongIds);

            string serialized_str = JsonConvert.SerializeObject(song);

            string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Song_" + song.Id + ".dat");

            File.WriteAllText(fileName, serialized_str);
        }
Ejemplo n.º 7
0
        //get all songs and their average rate
        //get top 10
        //koristi se
        public List <RateDetails> GetSongRates()
        {
            //get average rate
            List <AverageRate> list = _context.UsersSongRates
                                      .Join(
                _context.Song,
                rate => rate.SongId,
                song => song.Id,
                (rate, song) => new
            {
                song.Title,
                rate.Rate,
                rate.SongId,
            })
                                      .GroupBy(p => p.SongId)
                                      .Select(g => new AverageRate {
                Id = g.First().SongId, Title = g.First().Title, AvgRate = Math.Round(Convert.ToDouble(g.Sum(x => x.Rate)) / g.Count(), 1)
            }).OrderByDescending(x => x.AvgRate).Take(10).ToList();

            List <RateDetails> avgRateDetailList = new List <RateDetails>();

            foreach (AverageRate item in list)
            {
                SongGetRequest obj     = _mapper.Map <SongGetRequest>(_context.Song.Include(x => x.Album).Include(x => x.Album.Performer).Where(x => x.Id == item.Id).FirstOrDefault());
                RateDetails    rateDet = new RateDetails()
                {
                    Id        = obj.Id,
                    Image     = obj.Album.Image,
                    Title     = obj.Title,
                    Performer = obj.Album.Performer.ArtisticName,
                    AvgRate   = item.AvgRate
                };
                avgRateDetailList.Add(rateDet);
            }
            return(avgRateDetailList);
        }