//method for user login  
        public int LoginUser(UserPhotoGalleryMaster objUserPhotoGalleryMaster, out int userid, out string username)
        {
            using (SqlCommand scmd = new SqlCommand())
            {
                int ret = 0;
                userid = 0;
                username = "";
                scmd.Connection = scon;
                scmd.CommandType = CommandType.Text;
                scmd.CommandText = "Select Userid, UserName from tbl_User where Email=@Email and Password=@Password";
                scmd.Parameters.AddWithValue("@Email", objUserPhotoGalleryMaster.Email);
                scmd.Parameters.AddWithValue("@Password", objUserPhotoGalleryMaster.Password);
                scon.Open();
                SqlDataReader sdr = scmd.ExecuteReader();
                while (sdr.Read())
                {
                    userid = Convert.ToInt32(sdr.GetValue(0));
                    username = sdr.GetString(1);
                    ret = 1;
                }
                if (sdr != null)
                {
                    sdr.Dispose();
                    sdr.Close();
                }

                return ret;
            }
        }
 //method For upload the image in the database.  
 public int UploadAlbums(UserPhotoGalleryMaster objUserPhotoGalleryMaster)
 {
     using (SqlCommand scmd = new SqlCommand())
     {
         scmd.Connection = scon;
         scmd.CommandType = CommandType.Text;
         scmd.CommandText = "INSERT INTO tbl_Gallery(ImageName,Photo, Fk_Userid) VALUES(@ImageName,@Photo, @Fk_Userid)";
         scmd.Parameters.AddWithValue("@ImageName", objUserPhotoGalleryMaster.ImageName);
         scmd.Parameters.AddWithValue("@Photo", objUserPhotoGalleryMaster.Image);
         scmd.Parameters.AddWithValue("@Fk_Userid", objUserPhotoGalleryMaster.Fk_UserId);
         scon.Open();
         int status = scmd.ExecuteNonQuery();
         scon.Close();
         return status;
     }
 }
 //method for the user registration  
 public int RegisterUser(UserPhotoGalleryMaster objUserPhotoGalleryMaster)
 {
     using (SqlCommand scmd = new SqlCommand())
     {
         scmd.Connection = scon;
         scmd.CommandType = CommandType.Text;
         scmd.CommandText = "INSERT INTO tbl_User(UserName,Email, Password) VALUES(@UserName,@Email, @Password)";
         scmd.Parameters.AddWithValue("@UserName", objUserPhotoGalleryMaster.UserName);
         scmd.Parameters.AddWithValue("@Email", objUserPhotoGalleryMaster.Email);
         scmd.Parameters.AddWithValue("@Password", objUserPhotoGalleryMaster.Password);
         scon.Open();
         int status = scmd.ExecuteNonQuery();
         scon.Close();
         return status;
     }
 }
        //method for the get photo album from the database using userid  
        public IList<Gallery.Models.UserPhotoGalleryMaster> GetAlbums(int userid)
        {
            List<UserPhotoGalleryMaster> objUserPhotoGalleryMaster = new List<UserPhotoGalleryMaster>();
            using (SqlCommand scmd = new SqlCommand())
            {
                scmd.Connection = scon;
                scmd.CommandType = System.Data.CommandType.Text;
                scmd.CommandText = "SELECT * FROM tbl_Gallery where Fk_Userid=@userid";
                scmd.Parameters.AddWithValue("@userid", userid);
                scon.Open();
                SqlDataReader sdr = scmd.ExecuteReader();
                while (sdr.Read())
                {
                    UserPhotoGalleryMaster objAlbumMaster = new UserPhotoGalleryMaster();
                    objAlbumMaster.ImageId = Convert.ToInt32(sdr["ImageId"]);
                    objAlbumMaster.ImageName = sdr["ImageName"].ToString();
                    objAlbumMaster.Image = (byte[])sdr["Photo"];
                    objUserPhotoGalleryMaster.Add(objAlbumMaster);
                }

                if (sdr != null)
                {
                    sdr.Dispose();
                    sdr.Close();
                }
                scon.Close();
                return objUserPhotoGalleryMaster.ToList(); ;
            }
        }
 // method for the photo using image id  
 public byte[] GetImageFromDataBase(int id)
 {
     using (SqlCommand scmd = new SqlCommand())
     {
         scmd.Connection = scon;
         scmd.CommandType = System.Data.CommandType.Text;
         scmd.CommandText = "SELECT Photo FROM tbl_Gallery where ImageId=@ImageId";
         scmd.Parameters.AddWithValue("@ImageId", id);
         scon.Open();
         SqlDataReader sdr = scmd.ExecuteReader();
         UserPhotoGalleryMaster objUserPhotoGalleryMaster = new UserPhotoGalleryMaster();
         while (sdr.Read())
         {
             objUserPhotoGalleryMaster.Image = (byte[])sdr["Photo"];
         }
         return objUserPhotoGalleryMaster.Image;
     }
 }