Пример #1
0
        /// <summary>
        /// code for properties updation
        /// </summary>

        void updateproperties()
        {
            string s1 = "";

            try
            {
                string FileName = "";
                string FilePath = "~/Admin/img/Properties/";

                if (txtimg.PostedFile.ContentLength > 0 && txtimg.PostedFile != null)
                {
                    FileName = Guid.NewGuid().ToString() + Path.GetExtension(txtimg.FileName);
                    string Extension = Path.GetExtension(txtimg.FileName);
                    int    Length    = txtimg.PostedFile.ContentLength;
                    s1 = FilePath + FileName;
                    #region checking out File Length

                    if (Length <= 1000000)
                    {
                        #region Checking file Extensions
                        switch (Extension.ToLower())
                        {
                            #region When File Extension Is .JPG

                        case ".jpg":
                            txtimg.SaveAs(Server.MapPath(FilePath + FileName));
                            property.FlatId   = Convert.ToInt32(ddlflats.SelectedValue);
                            property.Image    = s1;
                            property.For      = ddlfor.SelectedValue;
                            property.Bathroom = Convert.ToInt32(txtwashrooms.Value);
                            property.Bedroom  = Convert.ToInt32(txtbed.Value);
                            property.Address  = txtaddress.Value;
                            property.Area     = Convert.ToInt64(txtarea.Value);
                            property.Price    = Convert.ToInt32(txtprice.Value);
                            InsertionLayer.PropertyUpdation(property);
                            lblmsg.Text      = "Property Uploaded Successfully.";
                            lblmsg.ForeColor = System.Drawing.Color.BlueViolet;
                            clearsection();
                            // img1.ImageUrl = FilePath + FileName;


                            break;

                            #endregion


                            #region When File Extension Is .JPEG

                        case ".jpeg":
                            txtimg.SaveAs(Server.MapPath(FilePath + FileName));
                            property.Image    = s1;
                            property.FlatId   = Convert.ToInt32(ddlflats.SelectedValue);
                            property.For      = ddlfor.SelectedValue;
                            property.Bathroom = Convert.ToInt32(txtwashrooms.Value);
                            property.Bedroom  = Convert.ToInt32(txtbed.Value);
                            property.Address  = txtaddress.Value;
                            property.Area     = Convert.ToInt64(txtarea.Value);
                            property.Price    = Convert.ToInt32(txtprice.Value);
                            InsertionLayer.PropertyUpdation(property);
                            lblmsg.Text      = "Property Uploaded Successfully.";
                            lblmsg.ForeColor = System.Drawing.Color.BlueViolet;
                            clearsection();
                            // img1.ImageUrl = FilePath + FileName;
                            break;

                            #endregion


                            #region When File Extension Is .PNG

                        case ".png":
                            txtimg.SaveAs(Server.MapPath(FilePath + FileName));
                            property.Image    = s1;
                            property.FlatId   = Convert.ToInt32(ddlflats.SelectedValue);
                            property.For      = ddlfor.SelectedValue;
                            property.Bathroom = Convert.ToInt32(txtwashrooms.Value);
                            property.Bedroom  = Convert.ToInt32(txtbed.Value);
                            property.Address  = txtaddress.Value;
                            property.Area     = Convert.ToInt64(txtarea.Value);
                            property.Price    = Convert.ToInt32(txtprice.Value);
                            InsertionLayer.PropertyUpdation(property);
                            lblmsg.Text      = "Property Uploaded Successfully.";
                            lblmsg.ForeColor = System.Drawing.Color.BlueViolet;
                            clearsection();
                            // img1.ImageUrl = FilePath + FileName;
                            break;

                            #endregion

                        default:
                            lblmsg.Text      = "Only jpg jpeg and png file accepted";
                            lblmsg.ForeColor = System.Drawing.Color.Red;
                            break;
                        }

                        #endregion
                    }
                    else
                    {
                        lblmsg.Text      = "File must be  less than 1 mb";
                        lblmsg.ForeColor = System.Drawing.Color.Red;
                    }
                    #endregion
                }
                else
                {
                    lblmsg.Text      = "please choose the file";
                    lblmsg.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                lblmsg.Text      = ex.Message;
                lblmsg.ForeColor = System.Drawing.Color.Red;
            }
        }