public string SaveSubCategory(SubCategory sub, int categoryId, string image) { string imageType = ImageUpload.GetFileType(image); string FileIconeName = Guid.NewGuid().ToString(); byte[] fileBytes = ImageUpload.Parse(image); string Fullftp = "ftp://demoproje.site/httpdocs/Files/Image/" + FileIconeName + "." + imageType; string httpAdres = "http://demoproje.site/Files/Image/" + FileIconeName + "." + imageType; FtpWebRequest reqFtp = (FtpWebRequest) FtpWebRequest.Create(Fullftp); reqFtp.Credentials = new NetworkCredential("u9172314", "OImu28B6"); reqFtp.KeepAlive = false; reqFtp.Method = WebRequestMethods.Ftp.UploadFile; reqFtp.UseBinary = true; reqFtp.UsePassive = true; try { using (Stream strm = reqFtp.GetRequestStream()) { strm.Write(fileBytes, 0, fileBytes.Length); strm.Close(); } } catch (Exception ex) { } bool result = false; SubCategory subCategory = new SubCategory(); { subCategory.Name = sub.Name; subCategory.IsActive = sub.IsActive; subCategory.CategoryId = categoryId; subCategory.Image = httpAdres; result = subCategory.AddSubCategory(subCategory); } string message = result ? "İşlem Tamamlandı." : "Hata Oluştu."; return(JsonConvert.SerializeObject(message)); }
protected void btnCreateSubCategory_Click(object sender, EventArgs e) { if (ddCategory.SelectedIndex > 0) { if (txtSubCategory.Text.Length > 0) { if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { try { string ImageFile = ""; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 250); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } string categoryid = Convert.ToString(ddCategory.SelectedValue); int success = 0; success = local_subcategory.AddSubCategory(categoryid, txtSubCategory.Text, txtDescription.Text, ImageFile, ImageFile); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Created Successfully"; BindSubCategory(); } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Creation Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } else //Update subcategory { //string ImageFile; //if (UploadImage.HasFile) //{ // string imgPath = "~/Upload/images/"; // string thumbPath = "~/Upload/thumbnails/"; // ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); // ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; // thumbPath = thumbPath + ImageFile; // System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); // System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 250); // objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); // imgPath = imgPath + ImageFile; // UploadImage.SaveAs(MapPath(imgPath)); //} //else //{ // ImageFile = lblImage.Text; //} try { Int32 categoryid = Convert.ToInt32(ddCategory.SelectedValue); Int32 subcategoryid = Convert.ToInt32(ViewState["ID"]); int success = 0; success = local_subcategory.UpdateSubCategory(subcategoryid, txtSubCategory.Text, txtDescription.Text, categoryid); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Updated Successfully"; BindSubCategory(); ViewState["ID"] = null; lblImage.Text = ""; btnCreateSubCategory.Text = "Create Sub Category"; } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Update Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Enter Sub Category Name"; } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Select Category Name"; } }
protected void btnCreateSubCategory_Click(object sender, EventArgs e) { if (ddCategory.SelectedIndex > 0) { if (txtSubCategory.Text.Length > 0) { if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { try { string categoryid = Convert.ToString(ddCategory.SelectedValue); int success = 0; success = local_subcategory.AddSubCategory(categoryid, txtSubCategory.Text); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Created Successfully"; BindSubCategory(); } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Creation Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } else //Update subcategory { try { Int32 categoryid = Convert.ToInt32(ddCategory.SelectedValue); Int32 subcategoryid = Convert.ToInt32(ViewState["ID"]); int success = 0; success = local_subcategory.UpdateSubCategory(subcategoryid, txtSubCategory.Text, categoryid); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Updated Successfully"; BindSubCategory(); ViewState["ID"] = null; btnCreateSubCategory.Text = "Create Sub Category"; } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Update Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Enter Sub Category Name"; } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Select Category Name"; } }