Exemple #1
0
        private string SavePhotoPath(string _adsId, int _order, int _photoId, string _photoPath)
        {
            //-- SavePhotoPath
            //-- Save Photo at the Server Folder and store filepath into Table
            //--    - if there is no parameter for PhotoId, it's meant for Existing Photos
            //-- Parameters:
            //--   _adsId (string)
            //--   _order (int)
            //--   _photoId (int)
            //--   _photoPath (string)
            //-- Return Value: bool

            FileUpload fupImageCurrent;

            try
            {
                //-- set current fupImage
                fupImageCurrent = (FileUpload)PostForm.FindControl("fupAdImg" + _order.ToString());

                string photoFileName = Path.GetFileName(fupImageCurrent.FileName);

                //-- if current filename and new filename are different, then update. else ignore.
                if (Common.pathPhotosAds + "/" + _adsId + "/" + photoFileName != _photoPath)
                {
                    //-- Validation on Photo Filetype
                    if (fupImageCurrent.PostedFile.ContentType != "image/jpeg")
                    {
                        throw new Exception("Only JPEG files are accepted!");
                    }

                    //-- Validation on Photo Filesize
                    if (fupImageCurrent.PostedFile.ContentLength >= 2097152)
                    {
                        throw new Exception("The file has to be less than 2MB");
                    }

                    //-- If AdsId folder does not exist in Ads Images folder, create
                    string adSpecificFolderPath = "~/" + Common.pathPhotosAds + "/" + _adsId;
                    if (!System.IO.Directory.Exists(Server.MapPath(adSpecificFolderPath)))
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(adSpecificFolderPath));
                    }

                    //-- Delete old photo
                    if (System.IO.File.Exists(Server.MapPath("~/" + _photoPath)))
                    {
                        System.IO.File.Delete(Server.MapPath("~/" + _photoPath));
                    }

                    //-- Save File into designated server folder, remove first if existing
                    if (System.IO.File.Exists(Server.MapPath(adSpecificFolderPath + "/" + photoFileName)))
                    {
                        System.IO.File.Delete(Server.MapPath(adSpecificFolderPath + "/" + photoFileName));
                    }
                    fupImageCurrent.SaveAs(Server.MapPath(adSpecificFolderPath + "/" + photoFileName));

                    //-- Close the file
                    fupImageCurrent.FileContent.Close();

                    //-- Recreate Parameters, then Update record
                    sqlAdPhotos.UpdateParameters.Clear();
                    sqlAdPhotos.UpdateParameters.Add("prmPhotoId", _photoId.ToString());
                    sqlAdPhotos.UpdateParameters.Add("prmCaption", "");
                    sqlAdPhotos.UpdateParameters.Add("prmPath", Common.pathPhotosAds + "/" + _adsId + "/" + photoFileName);
                    sqlAdPhotos.UpdateParameters.Add("prmOrder", _order.ToString());

                    //-- Save to Audit Log

                    //-- Update Photos Record
                    sqlAdPhotos.Update();
                }

                return(_photoId.ToString());
            }
            catch (Exception ex)
            {
                return("");
            }
        }
        private string SavePhotoPath(string _adsId, int _order)
        {
            //-- SavePhotoPath
            //-- Save Photo at the Server Folder and store filepath into Table
            //-- Parameters:
            //--   _adsId (string)
            //--   _order (int)
            //-- Return Value: bool

            FileUpload fupImageCurrent;

            try
            {
                //-- set current fupImage
                fupImageCurrent = (FileUpload)PostForm.FindControl("fupAdImg" + _order.ToString());

                //-- Validation on Photo Filetype
                if (fupImageCurrent.PostedFile.ContentType != "image/jpeg")
                {
                    throw new Exception("Only JPEG files are accepted!");
                }

                //-- Validation on Photo Filesize
                if (fupImageCurrent.PostedFile.ContentLength >= 2097152)
                {
                    throw new Exception("The file has to be less than 2MB");
                }

                //-- If AdsId folder does not exist in Ads Images folder, create
                string adSpecificFolderPath = "~/" + Common.pathPhotosAds + "/" + _adsId;
                if (!System.IO.Directory.Exists(Server.MapPath(adSpecificFolderPath)))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(adSpecificFolderPath));
                }

                //-- Save File into designated server folder, remove first if existing
                string photoFileName = Path.GetFileName(fupImageCurrent.FileName);
                if (System.IO.File.Exists(Server.MapPath(adSpecificFolderPath + "/" + photoFileName)))
                {
                    System.IO.File.Delete(Server.MapPath(adSpecificFolderPath + "/" + photoFileName));
                }
                fupImageCurrent.SaveAs(Server.MapPath(adSpecificFolderPath + "/" + photoFileName));

                //-- Close the file
                fupImageCurrent.FileContent.Close();

                //-- Get Last Photo Id
                lastAdPhotoId = int.Parse(Common.GetMaxAdsPhotoId());

                //-- Recreate Parameters, then Insert New Record using SqlDataSource object
                sqlAdPhotos.InsertParameters.Clear();

                sqlAdPhotos.InsertParameters.Add("prmPhotoId", (lastAdPhotoId + 1).ToString());
                sqlAdPhotos.InsertParameters.Add("prmCaption", "");
                sqlAdPhotos.InsertParameters.Add("prmPath", Common.pathPhotosAds + "/" + _adsId + "/" + photoFileName);
                sqlAdPhotos.InsertParameters.Add("prmOrder", _order.ToString());

                //-- Save to Audit Log

                //-- Insert Ad Mapping Photos Record
                sqlAdPhotos.Insert();

                return((lastAdPhotoId + 1).ToString());
            }
            catch (Exception ex)
            {
                return("");
            }
        }
Exemple #3
0
        private bool PostSubmit()
        {
            //-- PostSubmit
            //-- Submit Ad Changes and Save into Table
            //-- Return Value: bool

            try
            {
                //-- Recreate Parameters, then Update Record using SqlDataSource object
                sqlAdsMain.UpdateParameters.Clear();

                sqlAdsMain.UpdateParameters.Add("prmAdTypeId", ddlAdTypes.SelectedValue);
                sqlAdsMain.UpdateParameters.Add("prmSubCategoryId", ddlSubCategories.SelectedValue);
                sqlAdsMain.UpdateParameters.Add("prmConditionId", ddlConditions.SelectedValue);
                sqlAdsMain.UpdateParameters.Add("prmPrice", txtPrice.Text);
                sqlAdsMain.UpdateParameters.Add("prmTitle", txtTitle.Text);
                sqlAdsMain.UpdateParameters.Add("prmDescription", txtDescription.Text);
                if (chkNegotiable.Checked)
                {
                    sqlAdsMain.UpdateParameters.Add("prmNegotiable", "1");
                }
                else
                {
                    sqlAdsMain.UpdateParameters.Add("prmNegotiable", "0");
                }
                sqlAdsMain.UpdateParameters.Add("prmAdsId", adsId);
                //-- TEMP Only - Automatically set to Published if not Reserved or Sold
                if ((ddlStatus.SelectedValue != "4") && (ddlStatus.SelectedValue != "5"))
                {
                    sqlAdsMain.UpdateParameters.Add("prmStatus", "2");
                }
                else
                {
                    sqlAdsMain.UpdateParameters.Add("prmStatus", ddlStatus.SelectedValue);
                }

                //-- Save to Audit Log


                //-- Save Ads Photos (currently maxed at 3)
                for (int i = 1; i <= Common.maxPhotos; i++)
                {
                    //-- if a new Photo is uploaded, run SubmitPhoto function
                    FileUpload fupImageCurrent = (FileUpload)PostForm.FindControl("fupAdImg" + i.ToString());

                    if (fupImageCurrent.HasFile)
                    {
                        PostSubmitPhotos(adsId, i);
                    }
                    //else
                    //    DeleteOldPhoto(adsId, i);
                }


                //-- Save Ads Details
                PostSubmitDetails(adsId);

                //-- Update main Ads Record
                sqlAdsMain.Update();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }