Example #1
0
        protected void btnSubmitProperty_Click(object sender, EventArgs e)
        {
            DataAccessLayer dao = new DataAccessLayer();

            sessionUser = Session["userEmail"].ToString();

            string propertyName;
            string propertyLocation;
            string propertyDescription;
            string propertyAddress;
            string responseMessage;
            int    propertyType;
            int    propertyPrice;
            int    propertyBedroom;
            int    propertyBathroom;
            int    propertySquarefeet;
            int    isFeatured;
            int    userID;
            int    lastInsertedPropertyID;

            propertyName        = txtPropertyName.Text;
            propertyLocation    = txtPropertyLocation.Text;
            propertyDescription = txtPropertyDescription.InnerText;
            propertyAddress     = txtPropertyAddress.Text;
            propertyType        = int.Parse(ddlPropertyType.SelectedItem.Value);
            propertyPrice       = int.Parse(txtPropertyPrice.Text);
            propertyBedroom     = int.Parse(txtBedRoom.Text);
            propertyBathroom    = int.Parse(txtBathRoom.Text);
            propertySquarefeet  = int.Parse(txtSquareFeet.Text);

            if (cbFeatured.Checked == true)
            {
                isFeatured = Constants.isFeatured;
            }
            else
            {
                isFeatured = Constants.isNotFeatured;
            }

            userID = dao.getUserID(sessionUser);

            if (dao.InsertProperty(propertyType, propertyName, propertyLocation, propertyAddress, propertySquarefeet, propertyBedroom, propertyBathroom, propertyDescription, isFeatured, Constants.isNotApproved, Constants.propertyEnabled, propertyPrice, userID) == true)
            {
                List <string> imageFiles = new List <string>();

                lastInsertedPropertyID = dao.getLastInsertedPropertyID();
                string applicationPath = Constants.path;

                foreach (var postedFile in uploadwidget.PostedFiles)
                {
                    string imageName = System.IO.Path.GetFileName(postedFile.FileName);
                    string location  = applicationPath + "userassets" + @"\" + sessionUser + @"\propertyImages\" + lastInsertedPropertyID;
                    imageFiles.Add((string)imageName);

                    if (!Directory.Exists(location))
                    {
                        Directory.CreateDirectory(location);
                    }

                    string SaveLocation = location + "\\" + imageName;
                    try
                    {
                        postedFile.SaveAs(SaveLocation);
                        dao.InsertPropertyImages(lastInsertedPropertyID, userID, imageName);
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }

                dao.UpdateImagetoPropertyTable(lastInsertedPropertyID, imageFiles[0]);

                responseMessage  = "Property Submitted";
                respMessage.Text = responseMessage;
            }
            else
            {
                Console.WriteLine("Error");
            }
        }