public async Task <IActionResult> Ekle(IFormFile photo, ProductModel model)
        {
            List <Gallery> glry = new List <Gallery>();

            _db.Entry(model.Products).State = Microsoft.EntityFrameworkCore.EntityState.Added;
            if (photo == null || photo.Length == 0)
            {
                return(Content("Resim Bulunamadı. Resimsiz Ürün Eklenemez."));
            }
            else
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "C:/Users/iau/Desktop/ProjeFatihBurak2ugrastıgım/ETicaretAngular/src/assets/images/", photo.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await photo.CopyToAsync(stream);
                }
                model.Products.Image = photo.FileName;
                glry.Add(new Gallery
                {
                    ProductId = model.Products.ProductId,
                    Image     = null,
                });
                foreach (var item in glry)
                {
                    _repglr.Add(item);
                }
                await _rep.Save();

                return(RedirectToAction("ProductsListe", "Products"));
            }
        }
        public async Task <IActionResult> EkleCoklu(List <IFormFile> photo, ProductModel pm, int id)
        {
            List <Gallery> glry = new List <Gallery>();

            if (photo == null || photo.Count == 0)
            {
                return(Content("Resim Bulunamadı"));
            }
            else
            {
                foreach (var item in photo)
                {
                    var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/", item.FileName);
                    var stream = new FileStream(path, FileMode.Create);
                    await item.CopyToAsync(stream);

                    glry.Add(new Gallery
                    {
                        ProductId = pm.Products.ProductId,
                        Image     = item.FileName
                    });
                }
                foreach (var item in glry)
                {
                    _db.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Added;
                }
            }
            await _rep.Save();

            return(RedirectToAction("ProductsListe", "Products"));
            //return RedirectToPage("Liste", "Gallery" + id);
        }
Esempio n. 3
0
 public ActionResult Edit(int?id, Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Esempio n. 4
0
 public ActionResult Edit(int?id, Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.Result = "Bilgiler Güncellenmiştir";
     }
     else
     {
         ViewBag.Result = "Hata";
     }
     return(View(contact));
 }
Esempio n. 5
0
 public void Add(T entity)
 {
     _db.Entry(entity).State = EntityState.Added;
 }
Esempio n. 6
0
 public bool Update(T model)
 {
     _context.Entry <T>(model).State = EntityState.Modified;
     return(Save() > 0 ? true : false);
 }