public ActionResult SetGallery(int id) { var galleries = db.Galleries.ToList(); var product = db.Products.FirstOrDefault(d => d.Id == id); var model = new SetGalleryToProductViewModel() { Galleries = galleries, Product = product }; return(View(model)); }
public ActionResult SetGallery(SetGalleryToProductViewModel model, string ChosenGallery) { var product = db.Products.FirstOrDefault(d => d.Id == model.Product.Id); if (!String.IsNullOrWhiteSpace(ChosenGallery)) { product.GalleryId = Int32.Parse(ChosenGallery); db.SaveChanges(); } else { product.GalleryId = null; db.SaveChanges(); } return(RedirectToAction("Details", new { id = model.Product.Id })); }