Пример #1
0
        // if mode =0 that means play the song else if  is 1 means download the song
        protected void Page_Load(object sender, EventArgs e)
        {
            //beacuse when a user is sucessfully created it is redirected and we need to display the message
            if (Request.QueryString["Login"] != null)
            {
                Response.Write("Sucesssfully created");
            }
            //checking if user is authenticated and then displaying the options
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                HyperLink5.Visible   = false;
                HyperLink2.Visible   = false;
                LoginStatus1.Visible = false;
                HyperLink1.Visible   = false;
                HyperLink3.Visible   = false;
            }
            //checking if the authenticated user is admin and if he is admin then redirect to admin.aspx
            string usr = System.Web.HttpContext.Current.User.Identity.Name;
            admin  ad  = db.admins.Where(a => a.username == usr).FirstOrDefault();

            if (ad != null)
            {
                Response.Redirect("admin.aspx");
            }
            ValidationSettings.UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            LoginStatus1.LoginText = "";
            if (Request.QueryString["search"] != null)
            {
                DropDownList2.Visible = false;
                string query = Request.QueryString["search"];
                string mode  = Request.QueryString["mode"];

                if (mode == "" + 1)
                {
                    var result = (from st in db.songs
                                  where st.artist.Contains(query)
                                  select new { ID = st.song_id, Artist = st.artist, Track = st.track, Album = st.album, Duration = st.duration, Rating = st.song_rating }).ToList();
                    GridView2.DataSource = result;
                }
                if (mode == "" + 3)
                {
                    var result = (from st in db.songs
                                  where st.track.Contains(query)
                                  select new { ID = st.song_id, Artist = st.artist, Track = st.track, Album = st.album, Duration = st.duration, Rating = st.song_rating }).ToList();
                    GridView2.DataSource = result;
                }
                if (mode == "" + 2)
                {
                    var result = (from st in db.songs
                                  join sg in db.songgenres on st.song_id equals sg.song_id
                                  join g in db.genres on sg.genre_id equals g.Id

                                  where g.name.Contains(query)
                                  select new { ID = st.song_id, Artist = st.artist, Track = st.track, Album = st.album, Duration = st.duration, Rating = st.song_rating, Genre = g.name }).ToList();
                    GridView2.DataSource = result;
                }

                GridView1.Visible = false;

                GridView2.DataBind();
            }
        }