Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                Response.Redirect("index.aspx");
            }

            BeatsEntities db = new BeatsEntities();

            GridView1.Visible = true;
            GridView2.Visible = false;
            if (Request.QueryString["mode"] == null)
            {
                var res = (from ch in db.channels
                           select new { Name = ch.channel_name, ID = ch.channel_id, Description = ch.channel_description, Followers = ch.follow }).ToList();
                GridView1.DataSource = res;
                GridView1.DataBind();
            }
            if (Request.QueryString["mode"] != null)
            {
                string query = Request.QueryString["mode"];
                var    res   = (from ch in db.channels
                                where ch.channel_name.Contains(query)
                                select new { Name = ch.channel_name, ID = ch.channel_id, Description = ch.channel_description, Followers = ch.follow }).ToList();
                GridView2.DataSource = res;
                GridView2.DataBind();
                GridView2.Visible = true;
                GridView1.Visible = false;
            }
        }
Exemple #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (BeatsEntities db = new BeatsEntities())
     {
         if (Request.QueryString["id"] == null)
         {
             Response.Redirect("index.aspx");
         }
         if (Request.QueryString["id"] != null)
         {
             id = Int32.Parse(Request.QueryString["id"]);
             var path = from pt in db.song_add
                        join sg in db.songs
                        on pt.song_id equals sg.song_id
                        where pt.song_id == id
                        select new { album = sg.album, songpath = pt.path, name = sg.track, artist = sg.artist, ratings = sg.song_rating };
             foreach (var q in path)
             {
                 string str = "<audio controls onended ='callme()'>";
                 str += "<source src='" + q.songpath + "'type='audio/mpeg'";
                 str += "</audio>";
                 Response.Write("Track Name:" + q.name + "<br>");
                 Response.Write("Artist Name:" + q.artist + "<br>");
                 Response.Write("Album Name:" + q.album + "<br>");
                 Response.Write("Ratings:" + q.ratings + "<br>");
                 Response.Write(str);
                 //checking the rating and inserting into database
             }
         }
     }
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            BeatsEntities db  = new BeatsEntities();
            string        msg = "Please try another name";
            user          u2  = db.users.Where(u1 => u1.username == TextBox1.Text).FirstOrDefault();
            admin         ad  = db.admins.Where(a => a.username == TextBox1.Text).FirstOrDefault();

            if (u2 != null || ad != null)
            {
                Response.Redirect("register.aspx?res=" + msg);
            }

            user u = new user();

            u.username      = TextBox1.Text;
            u.password      = TextBox2.Text;
            u.security_ques = TextBox4.Text;
            u.security_ans  = TextBox5.Text;
            db.users.Add(u);
            db.SaveChanges();

            Response.Redirect("index.aspx?Login=" + true);
        }
        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();
            }
        }
Exemple #5
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");
                    }
                }
            }
        }