public ActionResult IlacDuzenle(ilaclar m, HttpPostedFileBase file) { try { using (sifaeczadposuEntities context = new sifaeczadposuEntities()) { var _ilacDuzenle = context.ilaclar.Where(x => x.ID == m.ID).FirstOrDefault(); if (file != null && file.ContentLength > 0) { MemoryStream memoryStream = file.InputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); file.InputStream.CopyTo(memoryStream); } _ilacDuzenle.resim = memoryStream.ToArray(); } _ilacDuzenle.ilacadi = m.ilacadi; _ilacDuzenle.aciklama = m.aciklama; _ilacDuzenle.fiyat = m.fiyat; _ilacDuzenle.indirimorani = m.indirimorani; context.SaveChanges(); return(RedirectToAction("Ilaclar", "Admin")); } } catch (Exception ex) { throw new Exception("Güncellerken hata oluştu " + ex.Message); } }
public ActionResult IlacEkle(ilaclar m, HttpPostedFileBase file) { try { using (sifaeczadposuEntities context = new sifaeczadposuEntities()) { ilaclar _ilac = new ilaclar(); if (file != null && file.ContentLength > 0) { MemoryStream memoryStream = file.InputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); file.InputStream.CopyTo(memoryStream); } _ilac.resim = memoryStream.ToArray(); } _ilac.ilacadi = m.ilacadi; _ilac.aciklama = m.aciklama; _ilac.fiyat = m.fiyat; _ilac.indirimorani = m.indirimorani; context.ilaclar.Add(_ilac); context.SaveChanges(); return(RedirectToAction("Ilaclar", "Admin")); } } catch (Exception ex) { throw new Exception("Eklerken hata oluştu"); } }