public void SaveSiteCard(ProductSiteCard entity)
 {
     if (dbContext.ProductSiteCards.AsNoTracking().FirstOrDefault(e => e.ProductId == entity.ProductId) == default)
     {
         dbContext.Entry(entity).State = EntityState.Added;
     }
     else
     {
         dbContext.Entry(entity).State = EntityState.Modified;
     }
     dbContext.SaveChanges();
 }
Пример #2
0
 public IActionResult ProductCardEdit(ProductSiteCard model, IFormFile formImageFile /* Добавить проверку на картинку*/)
 {
     if (ModelState.IsValid)
     {
         if (formImageFile != null)
         {
             model.BackgroundImage = Path.Combine("images/cardBgs/", formImageFile.FileName);
             using var stream      = new FileStream(Path.Combine(webHostEnvironment.WebRootPath, "images/cardBgs/", formImageFile.FileName), FileMode.Create);
             formImageFile.CopyTo(stream);
         }
         dataManager.ProductSiteCardRep.SaveSiteCard(model);
         return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).CutController()));
     }
     return(View(model));
 }