Ejemplo n.º 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                // string fname = Path.GetFileNameWithoutExtension(FileUpload1.FileName);
                string fextension = Path.GetExtension(FileUpload1.FileName);
                if (fextension == ".mp3")
                {
                    string artist_name = TextBox3.Text;
                    string album_name  = TextBox2.Text;
                    string genre_name  = TextBox4.Text;
                    string duration    = TextBox5.Text;
                    string trackname   = TextBox1.Text;
                    song   s           = new song();
                    s.album       = album_name;
                    s.artist      = artist_name;
                    s.duration    = duration;
                    s.count       = 0;
                    s.song_rating = 0;
                    s.track       = trackname;
                    s.counttoday  = 0;
                    db.songs.Add(s);
                    db.SaveChanges();
                    songgenre sg = new songgenre();
                    sg.genre_id = Int32.Parse(genre_name);
                    sg.song_id  = s.song_id;
                    db.songgenres.Add(sg);
                    db.SaveChanges();
                    song_add sa = new song_add();
                    sa.song_id     = s.song_id;
                    sa.path        = s.song_id + ".mp3";
                    sa.upload_time = System.DateTime.Now;
                    sa.admin_id    = db.admins.Where(a => a.username == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault().admin_id;
                    db.song_add.Add(sa);
                    db.SaveChanges();
                    FileUpload1.SaveAs(Server.MapPath("~/") + s.song_id + ".mp3");
                    Response.Write("<script>alert('Upload Successful')</script>");
                }
            }



            if (!FileUpload1.HasFile)
            {
                Response.Write("<script>alert('Select atleast one file')</script>");
            }
        }
Ejemplo n.º 2
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = GridView1.SelectedRow;
            int         id  = Int32.Parse(row.Cells[5].Text);

            song_add songid = db.song_add.Where(s => s.song_id == id).FirstOrDefault();
            song     sg     = db.songs.Where(s => s.song_id == id).FirstOrDefault();

            if (mode == 1)
            {
                Response.ContentType = "audio/mpeg";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + sg.track);//The third argument represents the name of the file to be downloaded
                Response.WriteFile(songid.path);
                Response.End();
            }
            if (mode == 0)
            {
                string path = "play.aspx?id=";
                path += sg.song_id;
                Response.Redirect(path);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            BeatsEntities db = new BeatsEntities();

            user usr = db.users.Where(u => u.username == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault();

            if (usr == null)
            {
                Response.Redirect("index.aspx");
            }

            var p = from c in db.correlations
                    where c.user1 == usr.user_id//&&c.factor>0
                    select new { User = c.user2, Correlation = c.factor };
            var q = from c in db.correlations
                    where c.user2 == usr.user_id //&&c.factor>0
                                                 //orderby c.factor descending
                    select new { User = c.user1, Correlation = c.factor };
            var       alluserswithfactormorethanzero = p.Union(q);
            List <sg> ls = new List <sg>();
            //getting history of loggged in user
            var historyloggeduser = from g in db.histories
                                    where g.user_id == usr.user_id
                                    select new { Id = g.song_id, Ratings = g.ratings };

            //getting songlist,userid,ratings as given by the user,and correlation with everyuser of song i haven't heard
            foreach (var s in alluserswithfactormorethanzero)
            {
                var historyuser = from g in db.histories
                                  where g.user_id == s.User
                                  select new { Id = g.song_id, Ratings = g.ratings };
                foreach (var hist in historyuser)
                {
                    //checking if the song is heard by the logged in user
                    var s1 = db.histories.Where(h => h.song_id == hist.Id && h.user_id == usr.user_id).FirstOrDefault();
                    if (s1 == null)
                    {
                        sg sg1 = new sg();
                        sg1.sgid       = hist.Id;       //this is songid
                        sg1.correlid   = s.Correlation; //this is correl factor
                        sg1.usrratings = (int)hist.Ratings;
                        ls.Add(sg1);
                    }
                }
                double totalratings    = 0;
                double finalratings    = 0;
                var    songidwithcount = from l in ls
                                         group l by l.sgid into songID
                                         select new { Count = songID.Count(), identity = songID.Key };
                //getting list of songs with their songid
                List <sgg> finalsongs = new List <sgg>();
                foreach (var z in songidwithcount)
                {
                    totalratings = 0;
                    var n = from l in ls
                            where l.sgid == z.identity
                            select new { rate = l.usrratings, fact = l.correlid };
                    foreach (var g in n)
                    {
                        totalratings = totalratings + g.rate * g.fact;
                    }
                    finalratings = totalratings / z.Count;
                    if (finalratings > 0)
                    {
                        sgg s1 = new sgg();
                        s1.songid   = z.identity;
                        s1.songrate = finalratings;

                        finalsongs.Add(s1);
                    }
                }
                List <track> tnew = new List <track> ();
                foreach (var fs in finalsongs)
                {
                    song  ss = db.songs.Where(sn => sn.song_id == fs.songid).FirstOrDefault();
                    track tr = new track();
                    if (ss != null)
                    {
                        tr.SongId            = fs.songid;
                        tr.Trackname         = ss.track;
                        tr.Artist            = ss.artist;
                        tr.RecommendedRating = fs.songrate;
                    }
                    tnew.Add(tr);
                }
                GridView1.DataSource = tnew;

                GridView1.DataBind();
            }
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BeatsEntities db    = new BeatsEntities();
            string        user1 = System.Web.HttpContext.Current.User.Identity.Name;

            if (Request.QueryString["rating"] != null)
            {
                int songid = Int32.Parse(Request.QueryString["songid"]);
                int rating = Int32.Parse(Request.QueryString["rating"]);
                //getting user name
                //to get song s of songid id so that we can update count,counttoday,and ratings of that song
                if (rating <= 10 && rating >= 0)
                {
                    song s1 = db.songs.Where(y => y.song_id == songid).FirstOrDefault();
                    s1.count++;
                    s1.counttoday++;
                    s1.song_rating = (s1.song_rating * (s1.count - 1) + Int32.Parse(Request.QueryString["rating"])) / s1.count;
                    db.SaveChanges();
                    user us = db.users.Where(s => s.username == user1).FirstOrDefault();
                    if (us != null)
                    {
                        history h = db.histories.Where(s => s.user_id == us.user_id && s.song_id == songid).FirstOrDefault();

                        //checking if user has previously listened the song and then updating the count only else updating the database
                        if (h == null)
                        {
                            history h1 = new history();
                            h1.song_id = songid;
                            h1.user_id = us.user_id;
                            h1.count   = 1;
                            h1.ratings = Int32.Parse(Request.QueryString["rating"]);
                            h1.time    = DateTime.Now;
                            db.histories.Add(h1);
                        }
                        if (h != null)
                        {
                            h.count   = h.count + 1;
                            h.time    = DateTime.Now;
                            h.ratings = Int32.Parse(Request.QueryString["rating"]);
                        }
                        db.SaveChanges();
                        List <double> r1 = new List <double>();
                        List <double> r2 = new List <double>();

                        int primary = 0, secondary = 0;
                        foreach (user u in db.users)
                        {
                            if (u.user_id != us.user_id)
                            {
                                if (u.user_id > us.user_id)
                                {
                                    secondary = u.user_id;
                                    primary   = us.user_id;
                                }
                                if (u.user_id < us.user_id)
                                {
                                    secondary = us.user_id;
                                    primary   = u.user_id;
                                }
                                //getting histories
                                var p1 = (from h1 in db.histories
                                          where h1.user_id == primary
                                          select new { Song = h1.song_id, rating = h1.ratings }).ToList();
                                var p2 = (from h1 in db.histories
                                          where h1.user_id == secondary
                                          select new { Song = h1.song_id, rating = h1.ratings }).ToList();
                                //getting rating of common songs
                                foreach (var p in p1)
                                {
                                    foreach (var q in p2)
                                    {
                                        if (p.Song == q.Song)
                                        {
                                            r1.Add((double)p.rating);
                                            r2.Add((double)q.rating);
                                        }
                                    }
                                }
                                if (!(r1.Count == 0 || r2.Count == 0))
                                {
                                    double correl1 = Correlation.Pearson(r1, r2);
                                    if (!(Double.IsNaN(correl1)))
                                    {
                                        r1.Clear();
                                        r2.Clear();

                                        correlation c = db.correlations.Where(c1 => c1.user1 == primary && c1.user2 == secondary).FirstOrDefault();

                                        if (c == null)
                                        {
                                            correlation c2 = new correlation();
                                            c2.user1  = primary;
                                            c2.user2  = secondary;
                                            c2.factor = (float)correl1;
                                            db.correlations.Add(c2);
                                        }
                                        if (c != null)
                                        {
                                            c.factor = (float)correl1;
                                        }
                                    }
                                }
                            }
                        }
                        db.SaveChanges();


                        Response.Redirect("index.aspx");
                    }

                    else
                    {
                        Response.Redirect("index.aspx");
                    }
                }
            }
        }