Exemplo n.º 1
0
 public async Task <IActionResult> UrunEkle(UrunAddDTO model)
 {
     if (ModelState.IsValid)
     {
         var urun = mapper.Map <Urun>(model);
         await urunService.Add(urun);
     }
     return(View(model));
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(UrunAddDTO model, IFormFile Resim)
        {
            if (ModelState.IsValid)
            {
                var urun = mapper.Map <Urun>(model);

                if (Resim != null)
                {
                    string uzanti  = Path.GetExtension(Resim.FileName);
                    string resimAd = Guid.NewGuid() + uzanti;

                    string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/" + resimAd);
                    using var stream = new FileStream(path, FileMode.Create);
                    await Resim.CopyToAsync(stream);

                    urun.ResimYolu = resimAd;
                }
                await urunService.Add(urun);

                return(RedirectToAction("Urunler"));
            }
            return(View(model));
        }