Exemplo n.º 1
0
        public IActionResult Detay(int id)
        {
            Urun urun = urunRepo.GetbyId(id);

            if (urun != null)
            {
                UrunImageModel model = new UrunImageModel()
                {
                    Urun   = urun,
                    Images = imageRepo.GetByUrunId(id).ToList()
                };
                return(View(model));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public IActionResult UrunDuzenle(int id)
        {
            ViewBag.Kategoriler = new SelectList(kategoriRepo.GetAll(), "KategoriId", "KategoriAd");
            Urun urun = urunRepo.GetbyId(id);

            if (urun == null)
            {
                return(RedirectToAction("UrunList"));
            }
            UrunImageModel model = new UrunImageModel()
            {
                Urun   = urun,
                Images = imageRepo.GetByUrunId(urun.UrunId).ToList()
            };

            return(View(model));
        }
 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));
 }