Esempio n. 1
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow rw        = GridView1.SelectedRow;
            int         channelid = Int32.Parse(rw.Cells[2].Text);
            channel     ch        = db.channels.Where(c => c.channel_id == channelid).FirstOrDefault();

            ch.follow = ch.follow + 1;

            string             username = System.Web.HttpContext.Current.User.Identity.Name;
            user               us       = db.users.Where(u => u.username == username).FirstOrDefault();
            userfollowschannel uf       = db.userfollowschannels.Where(u => u.userid == us.user_id && u.channelid == ch.channel_id).FirstOrDefault();

            if (uf == null)
            {
                userfollowschannel ufc = new userfollowschannel();
                ufc.channelid = ch.channel_id;
                ufc.userid    = us.user_id;
                db.userfollowschannels.Add(ufc);
                db.SaveChanges();
                Response.Write("<script>alert('You have started following this channel')</script>");
            }
            else
            {
                Response.Write("<script>alert('You already follow this channel')</script>");
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            //adding channel and checking whether current channel name is available or not
            channel ch  = new channel();
            channel ch2 = db.channels.Where(c => c.channel_name == TextBox1.Text).FirstOrDefault();

            if (ch2 == null)
            {
                ch.channel_name = TextBox1.Text;

                ch.channel_description = TextBox2.Text;
                db.channels.Add(ch);
                db.SaveChanges();
                usercreatedchannel ucc2     = new usercreatedchannel();
                string             username = System.Web.HttpContext.Current.User.Identity.Name;
                user us = db.users.Where(u => u.username == username).FirstOrDefault();
                ucc2.userid = us.user_id;
                channel ch1 = db.channels.Where(c => c.channel_name == TextBox1.Text).FirstOrDefault();

                ucc2.channelid = ch1.channel_id;
                db.usercreatedchannels.Add(ucc2);
                db.SaveChanges();
                Response.Redirect("mychannels.aspx");
            }
            if (ch2 != null)
            {
                Response.Redirect("channels.aspx?msg=The channel name already exists.Please try another name");
            }
        }
        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>");
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //upadating the user with new password
            string username1 = System.Web.HttpContext.Current.User.Identity.Name;
            user   us        = db.users.Where(s => s.username == username1).FirstOrDefault();

            us.password = TextBox1.Text;

            db.SaveChanges();

            Response.Write("Password successfully changed");
        }
        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);
        }
Esempio n. 6
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");
                    }
                }
            }
        }