예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Adi,Aciklama")] Kategori kategori)
        {
            if (id != kategori.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(kategori);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KategoriExists(kategori.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(kategori));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Ad,Aciklama,Fiyat")] Urun urun)
        {
            if (id != urun.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(urun);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UrunExists(urun.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(urun));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Ad,Aciklama,Fiyat,Dosya")] Urun urun)
        {
            if (id != urun.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var dosyaYolu = Path.Combine(_hostEnvironment.WebRootPath, "resimler");
                if (!Directory.Exists(dosyaYolu))
                {
                    Directory.CreateDirectory(dosyaYolu);
                }

                try
                {
                    foreach (var item in urun.Dosya)
                    {
                        string guid     = Guid.NewGuid().ToString();
                        var    split    = item.FileName.Split(".");
                        var    fileName = split[0] + guid + "." + split[1];

                        var tamDosyaAdi = Path.Combine(dosyaYolu, fileName);

                        await using (var dosyaAkisi = new FileStream(tamDosyaAdi, FileMode.Create))
                        {
                            await item.CopyToAsync(dosyaAkisi);
                        }

                        urun.Resimler.Add(new Resim {
                            DosyaAdi = fileName
                        });
                    }
                }
                catch (NullReferenceException)
                {
                }

                try
                {
                    _context.Update(urun);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UrunExists(urun.Id))
                    {
                        return(NotFound());
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }


            return(View(urun));
        }
예제 #4
0
 public void Update(T entity)
 {
     Context.Update(entity);
 }