public int DeleteInformation(PhotoGalleryObject photogalleryObj)
        {
            SqlConnection con = GetConnection();

            con.Open();

            SqlCommand cmd = new SqlCommand("Delete_PhotoGallery", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@PhotoId", photogalleryObj.PhotoId);
            cmd.Parameters.AddWithValue("@UserId", photogalleryObj.UserId);

            try
            {
                return(cmd.ExecuteNonQuery());
            }
            catch
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }
        public int InsertInformation(PhotoGalleryObject photogalleryObj)
        {
            SqlConnection con = GetConnection();

            con.Open();

            SqlCommand cmd = new SqlCommand("Insert_PhotoGallery", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@PhotoPath", photogalleryObj.PhotoPath);
            cmd.Parameters.AddWithValue("@PhotoBrief", photogalleryObj.PhotoBrief);
            cmd.Parameters.AddWithValue("@PhotoDetail", photogalleryObj.PhotoDetail);
            cmd.Parameters.AddWithValue("@UserId", photogalleryObj.UserId);
            cmd.Parameters.AddWithValue("@Status", photogalleryObj.Status);

            try
            {
                return(cmd.ExecuteNonQuery());
            }
            catch
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }
Beispiel #3
0
        protected void btn_update_Click(object sender, EventArgs e)
        {
            PhotoGalleryObject photogalleryObj = new PhotoGalleryObject();

            photogalleryObj.PhotoId = int.Parse(Session["PhotoGallery_id"].ToString());
            DataTable dt = dal.SelectInformationById(photogalleryObj.PhotoId);

            photogalleryObj.PhotoBrief  = tbxPhotoBrief.Text;
            photogalleryObj.PhotoDetail = tbxPhotoDetail.Text;
            photogalleryObj.UserId      = Int32.Parse(Session["user_id"].ToString());

            if (ddlPhotoStatus.SelectedValue == "1")
            {
                photogalleryObj.Status = true;
            }
            else if (ddlPhotoStatus.SelectedValue == "0")
            {
                photogalleryObj.Status = false;
            }

            if (PhotoUpload.HasFile)
            {
                string extension    = Path.GetExtension(PhotoUpload.FileName);
                string photopath    = Guid.NewGuid().ToString() + extension;
                string uploadFolder = "~/Photo_gallery/";
                PhotoUpload.SaveAs(Server.MapPath(uploadFolder + photopath));
                photogalleryObj.PhotoPath = photopath;
            }
            else
            {
                photogalleryObj.PhotoPath = dt.Rows[0]["PhotoPath"].ToString();
            }

            try
            {
                int result = dal.UpdateInformation(photogalleryObj);
                if (result == 1)
                {
                    getPhotoGalleryById();
                    SuccessPanel.Visible = true;
                }
                else
                {
                    DangerPanel.Visible = true;
                }
            }
            catch
            {
                throw;
            }
        }