public IActionResult ImageSil(int id) { UrunImage entity = imageRepo.GetbyId(id); if (entity != null) { Account acc = new Account("naimmobilya", "742112311237693", "nqeO8i7tnQpNPnSAQyESOqImU-I"); Cloudinary cloudinary = new Cloudinary(acc); cloudinary.DeleteResources(entity.UrunImageId.ToString()); imageRepo.Delete(entity); TempData["message"] = $"{entity.UrunId} id li image silindi"; } return(RedirectToAction("UrunDuzenle", new { id = entity.UrunId })); }
public async Task <IActionResult> UrunDuzenle(UrunImageModel entity, IEnumerable <IFormFile> file) { ViewBag.Kategoriler = new SelectList(kategoriRepo.GetAll(), "KategoriId", "KategoriAd"); if (ModelState.IsValid) { Account acc = new Account("naimmobilya", "742112311237693", "nqeO8i7tnQpNPnSAQyESOqImU-I"); Cloudinary cloudinary = new Cloudinary(acc); if (file != null) { foreach (var item in file) { string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", item.FileName); using (var stream = new FileStream(filePath, FileMode.Create)) { await item.CopyToAsync(stream); } UrunImage image = new UrunImage() { UrunId = entity.Urun.UrunId }; imageRepo.Add(image); var uploadParams = new ImageUploadParams() { File = new FileDescription(filePath), PublicId = "" + image.UrunImageId }; var uploadResult = cloudinary.Upload(uploadParams); image.ImageUrl = uploadResult.Uri.ToString(); imageRepo.Update(image); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } } urunRepo.Update(entity.Urun); TempData["message"] = $"{entity.Urun.UrunId} id li ürün eklendi"; return(RedirectToAction("UrunList")); } return(View(entity)); }