예제 #1
0
        public (bool, int) Ekle(UrunEkleDuzenleVM model, List <string> resimler)
        {
            List <Resim> eklenecekResimler = new List <Resim>();

            foreach (var resim in resimler)
            {
                eklenecekResimler.Add(new Resim
                {
                    ResimAdi = resim,
                });
            }
            _urunRepository.Add(new Urun
            {
                UrunAdi      = model.Adi,
                Fiyat        = model.Fiyat.HasValue ? model.Fiyat.Value : 0,
                KategoriId   = model.KategoriId,
                MarkaId      = model.MarkaId,
                StokAdet     = model.StokAdet.HasValue ? model.StokAdet.Value : 0,
                UretimTarihi = model.UretimTarihi.HasValue ? model.UretimTarihi.Value : DateTime.Now,
                Resimler     = eklenecekResimler
            });
            var  sonEklenenUrun = _urunRepository.GetLast <int>(u => u.Id);
            Urun resimliUrun    = _urunRepository.GetTable().Include(u => u.Resimler).FirstOrDefault(u => u.Id == sonEklenenUrun.Id);

            resimliUrun.VitrinResmiId = resimliUrun.Resimler.ToList()[0].Id;
            _urunRepository.Update(resimliUrun);

            return(true, sonEklenenUrun.Id);
        }
예제 #2
0
        public async Task <UrunResponse> UpdateAsync(Urun urun, int id)
        {
            try
            {
                var urunguncel = await urunRepository.GetByIdUrun(id);

                if (urunguncel == null)
                {
                    return(new UrunResponse("Urun bulunamadı."));
                }
                else
                {
                    urunguncel.UrunAd     = urun.UrunAd;
                    urunguncel.UrunFiyat  = urun.UrunFiyat;
                    urunguncel.KategoriId = urun.KategoriId;


                    urunRepository.Update(urunguncel);
                    unitOfWork.CompleteAsync();

                    return(new UrunResponse(urunguncel));
                }
            }
            catch (Exception ex)
            {
                return(new UrunResponse($"Urun güncellenirken bir arıca oluştu.{ex.Message}"));
            }
        }
예제 #3
0
 public int UrunGuncelle(Urun urun)
 {
     try
     {
         _repo.Update(urun);
         _unit.Save();
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
 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));
 }