private void btnDelete_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageBox.Show("Silmek istediğiniz satırı seçin", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult result = MessageBox.Show("Seçili satırı silmek istediğinize emin misiniz ?", "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { int ilanId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); IlanManager.Delete(ilanId); MessageBox.Show("İşleminiz başarıyla gerçekleşti", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView1.DataSource = IlanManager.GetObjectsWithTable(); dataGridView1.Refresh(); } catch (Exception ex) { MessageBox.Show("İşleminiz gerçekleştirilirken hata oluştu :" + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult Sil(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ilan ilan = _managerIlan.Find(x => x.ID == id.Value); if (ilan == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } foreach (var item in ilan.ilanResimler) { if (System.IO.File.Exists(Server.MapPath("~/img/Ilan/" + item.ResimYol))) { System.IO.File.Delete(Server.MapPath("~/img/Ilan/" + item.ResimYol)); } } _managerIlan.Delete(ilan); return(RedirectToAction("Index")); }