//[ValidateAntiForgeryToken] public ActionResult Save(CustomInstrumentViewModel model) { var userId = User.Identity.GetUserId(); var partsList = new List <CustomInstrumentParts>(); var customInstrument = new CustomInstrument() { ApplicationUserId = userId, InstrumentId = model.Instrument.InstrumentId, PrimaryColor = model.PrimaryColor, SecondaryColor = model.SecondaryColor }; foreach (var type in model.SelectedParts) { partsList.Add(new CustomInstrumentParts() { CustomInstrumentId = customInstrument.CustomInstrumentId, GuitarPartId = type.GuitarPartId }); } _context.CustomInstruments.Add(customInstrument); _context.CustomInstrumentParts.AddRange(partsList); _context.SaveChanges(); _context.ShoppingCarts.Add(new ShoppingCart() { ApplicationUserId = User.Identity.GetUserId(), CustomInstrumentId = customInstrument.CustomInstrumentId }); _context.SaveChanges(); return(RedirectToAction("Index", "ShoppingCart")); }
// GET public ActionResult Index() { var partTypes = _context.PartTypes.ToList(); var partsList = new List <TypeWithItsParts>(); var model = new CustomInstrumentViewModel() { PartTypes = _context.PartTypes.Include(d => d.GuitarParts).ToList(), Instruments = _context.Instruments.ToList() }; return(View(model)); }