public void ResimEkle(UrunResimleri tabloResim) { int AddResim = repResimler.insert(new UrunResimleri() { PersonelID = tabloResim.PersonelID, UrunID = tabloResim.UrunID, Resim = tabloResim.Resim }); }
public int ResimSil(int ResimlerId) { UrunResimleri sil = repResimler.VeriBul(k => k.UrunResimleriID == ResimlerId); if (sil != null) { if (repResimler.Delete(sil) > 0) { return(1); } } return(0); }
protected void btnResimUpload_Click(object sender, EventArgs e) { string path = Server.MapPath("/UrunResimleri/"); //string dosyaadi = FileUpload1.FileName; string dosyaadi = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; FileUpload1.SaveAs(path + dosyaadi); projeEntities entities = new projeEntities(); ETicaret.UrunResimleri resim = new UrunResimleri() { UrunID = int.Parse(hdnID.Value), Resim = dosyaadi, Vitrin = chkVitrin.Checked }; entities.UrunResimleris.Add(resim); entities.SaveChanges(); }
//bu metot geriye bir json döndürecektir.View tarafında yazılacak json scriptini döndürecek public JsonResult UrunFileUpload(HttpPostedFileBase file, int?id) { //HttpPostedFile resim eklemek için bu yapıya ihtiyacaımız var. Sadece resim dosya da eklemek iin bu türde bir class yapısına ihtiyaç vardır if (file != null && (file.ContentType == "image/jpg" || file.ContentType == "image/jpeg" || file.ContentType == "image/png")) { //her ekelnen resime bir kod ile benzersiz yapmak için aşağıdaki kod yapısını kullanıyoruz string filename = $"Urun_{ Guid.NewGuid()}.{file.ContentType.Split('/')[1] }"; string path = Server.MapPath($"~/EklenenResimler/{filename}"); //file.SaveAs(Server.MapPath($"~/EklenenResimler/{filename}")); file.SaveAs(path); UrunResimleri urunRess = new UrunResimleri(); urunRess.Resim = filename; urunRess.UrunID = id; resimMan.ResimEkle(urunRess); return(Json("csd")); } return(Json("sfsdfs")); }