Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["username"] != null && !string.IsNullOrEmpty((string)Session["username"]))
     {
         string username = (string)Session["username"];
         User   user     = new User(SqlUtilities.GetUserId(username));
         if (user.IsAdmin)
         {
             IsAdmin.Visible = true;
         }
         else
         {
             if (Request.UrlReferrer != null)
             {
                 Response.Redirect(Request.UrlReferrer.ToString());
             }
             else
             {
                 Response.Redirect("Profile.aspx?username=" + username);
             }
         }
     }
     if (SqlUtilities.GetAdmins() == null)
     {
         IsAdmin.Visible = true;
     }
     if (!IsPostBack)
     {
         Populate_MonthList();
         Populate_YearList();
     }
 }
Example #2
0
        public void FillUserAlbums()
        {
            User user = new User(SqlUtilities.GetUserId((string)Session["username"]));

            SqlConnection conn      = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            string        selectTxt = "SELECT a.name, a.id FROM users u JOIN albums a ON u.id = a.id_user AND u.id = @id ORDER BY name";

            conn.Open();
            SqlCommand cmd = new SqlCommand(selectTxt, conn);

            cmd.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int));
            cmd.Parameters["@id"].Value = user.Id;

            SqlDataReader result = cmd.ExecuteReader();

            while (result.Read())
            {
                string   album = result.GetValue(0).ToString();
                string   id    = result.GetValue(1).ToString();
                ListItem item  = new ListItem(album, id);
                UserAlbums.Items.Add(item);
            }
            result.Close();
            conn.Close();
            int      newAlbumValue = -1;
            ListItem lastItem      = new ListItem("New album", newAlbumValue.ToString());

            UserAlbums.Items.Add(lastItem);
        }