protected void btnUpdateAd_ServerClick(object sender, EventArgs e) { Boolean postad = true; if (txtGameTile.Value.Equals("") || txtGamePrice.Value == null || drpGamePlatform.Items[drpGamePlatform.SelectedIndex].Text.Equals("Platform") || txtGameDescription.Value.Equals("")) { InvlaidPostAd.InnerHtml = "<p>Please fill in all the fields</p>"; postad = false; } else { try { int temp = Int32.Parse(txtGamePrice.Value); } catch (FormatException ex) { txtGamePrice.Value = ""; InvlaidPostAd.InnerHtml = "<p>Please fill in a price</p>"; postad = false; } } if (postad) { int negChecked = 0; int ShowPhoneChecked = 0; if (NegotiableCheck.Checked) { negChecked = 1; } if (ShowPhone.Checked) { ShowPhoneChecked = 1; } //**************Check files exist******************** //string base64String1 = ""; //string base64String2 = ""; //string base64String3 = ""; //Check if there is a file 1 if (pic1files.PostedFile.ContentLength != 0) { string base64String1 = ImageFunctions.validateImage(new BinaryReader(pic1files.PostedFile.InputStream).ReadBytes(pic1files.PostedFile.ContentLength)); if (base64String1.Equals("NOPIC")) { InvlaidPostAd.InnerHtml = "<p>Picture 1 is an invalid image. Please attach only the pictures you took of your game.</p>"; return; } Session["pic1"] = base64String1; /* * //convert pic 1 to byte[] * byte[] pic1Data = null; * using (var binaryReader = new BinaryReader(pic1files.PostedFile.InputStream)) * { * pic1Data = CompressImage(binaryReader.ReadBytes(pic1files.PostedFile.ContentLength)); * } * * /*base64String1 this.pic1server Session["pic1"] = Convert.ToBase64String(pic1Data);*/ } /*else * base64String1 = "NOPIC";*/ //Check if there is a file 2 if (pic2files.PostedFile.ContentLength != 0) { string base64String2 = ImageFunctions.validateImage(new BinaryReader(pic2files.PostedFile.InputStream).ReadBytes(pic2files.PostedFile.ContentLength)); if (base64String2.Equals("NOPIC")) { InvlaidPostAd.InnerHtml = "<p>Picture 2 is an invalid image. Please attach only the pictures you took of your game.</p>"; return; } Session["pic2"] = base64String2; /* * //convert pic 2 to byte[] * byte[] pic2Data = null; * using (var binaryReader = new BinaryReader(pic2files.PostedFile.InputStream)) * { * pic2Data = CompressImage(binaryReader.ReadBytes(pic2files.PostedFile.ContentLength)); * } * base64String2 this.pic2server Session["pic2"] = Convert.ToBase64String(pic2Data);*/ } /*else * base64String2 = "NOPIC";*/ //Check if there is a file 3 if (pic3files.PostedFile.ContentLength != 0) { string base64String3 = ImageFunctions.validateImage(new BinaryReader(pic3files.PostedFile.InputStream).ReadBytes(pic3files.PostedFile.ContentLength)); if (base64String3.Equals("NOPIC")) { InvlaidPostAd.InnerHtml = "<p>Picture 3 is an invalid image. Please attach only the pictures you took of your game.</p>"; return; } Session["pic3"] = base64String3; /* * //convert pic 3 to byte[] * byte[] pic3Data = null; * using (var binaryReader = new BinaryReader(pic3files.PostedFile.InputStream)) * { * pic3Data = CompressImage(binaryReader.ReadBytes(pic3files.PostedFile.ContentLength)); * } * base64String3 this.pic3server * Session["pic3"] = Convert.ToBase64String(pic3Data);*/ } /*else * base64String3 = "NOPIC";*/ /*if (base64String1.Equals("NOPIC")) * { * if (!pic1server.Equals("NOPIC")) * base64String1 = pic1server; * } * if (base64String2.Equals("NOPIC")) * { * if (!pic2server.Equals("NOPIC")) * base64String2 = pic2server; * } * if (base64String3.Equals("NOPIC")) * { * if (!pic3server.Equals("NOPIC")) * base64String3 = pic3server; * }*/ //byte[][] sendPics = new byte[3][]; // sendPics[0] = pic1Data; // sendPics[1] = pic2Data; //sendPics[2] = pic3Data; //-------------------------------------------------------------------------- UserData user = (UserData)Session["User"]; AdService.AdCRUDClient service = new AdService.AdCRUDClient(); service.Open(); string adID = Request.QueryString.Get("ad"); int success = service.updateAd(Convert.ToInt32(adID), txtGameTile.Value, drpGamePlatform.Items[drpGamePlatform.SelectedIndex].Text, txtGameDescription.Value, txtGameLocation.Value, Convert.ToDouble(txtGamePrice.Value), negChecked, ShowPhoneChecked, /*base64String1 this.pic1server*/ (string)Session["pic1"], /*base64String2 this.pic2server*/ (string)Session["pic2"], /*base64String3 this.pic3server*/ (string)Session["pic3"], user.isPrem()); if (success == 1) { editAdDiv.InnerHtml = "<div class='col s12 m6 push-m3'>"; editAdDiv.InnerHtml += "<div class='card white'>"; editAdDiv.InnerHtml += "<div class='card-content Black-text'>"; editAdDiv.InnerHtml += "<span class='card-title bold'>Ad Updated Successfully</span>"; editAdDiv.InnerHtml += "<p>You have successfully Updated your ad. To view your ad, proceeed to the My Ads page.</p>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "<div class='card-action'>"; editAdDiv.InnerHtml += "<a href='MyAds.aspx' runat='server' class='btn waves-effect waves-light'>My Ads</a>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "</div>"; } else { editAdDiv.InnerHtml = "<div class='col s12 m6 push-m3'>"; editAdDiv.InnerHtml += "<div class='card white'>"; editAdDiv.InnerHtml += "<div class='card-content Black-text'>"; editAdDiv.InnerHtml += "<span class='card-title bold'>Ad Update Unsuccessfully</span>"; editAdDiv.InnerHtml += "<p>We where unable to update your add. Please try again and if the problem persists pleas contact us <a href='ContactUs.aspx'>here</a>.</p>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "<div class='card-action'>"; editAdDiv.InnerHtml += "<a href='MyAds.aspx' runat='server' class='btn waves-effect waves-light'>Continue</a>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "</div>"; editAdDiv.InnerHtml += "</div>"; } service.Close(); Session["pic1"] = null; Session["pic2"] = null; Session["pic3"] = null; } }