public ActionResult Edit(ProductDetailModel data, FormCollection dat) { JewelryCategory category = new JewelryCategory(); category.Id = Convert.ToInt32(dat["Category"]); JewelryColor color = new JewelryColor(); color.Id = Convert.ToInt32(dat["color"]); JewelryType type = new JewelryType(); type.Id = Convert.ToInt32(dat["Type"]); JewelryImages images = new JewelryImages(); //images.Id = Convert.ToInt32(data.ImageUrl); Jewelry jewelry = new Jewelry { Id = data.Id, Name = data.Name, Description = data.Description, Price = data.Price, Category = new JewelryCategory { Id = category.Id }, Color = new JewelryColor { Id = color.Id }, Type = new JewelryType { Id = type.Id }, }; new JewelryHandler().update(jewelry); return(RedirectToAction("home", "admin")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string[] selectedCategories) { var newJewelry = new Jewelry(); if (selectedCategories != null) { newJewelry.JewelryCategories = new List <JewelryCategory>(); foreach (var cat in selectedCategories) { var catToAdd = new JewelryCategory { CategoryID = int.Parse(cat) }; newJewelry.JewelryCategories.Add(catToAdd); } } if (await TryUpdateModelAsync <Jewelry>( newJewelry, "Jewelry", i => i.Product, i => i.Brand, i => i.Price, i => i.ReleaseDate, i => i.MaterialID)) { _context.Jewelry.Add(newJewelry); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedCategoryData(_context, newJewelry); return(Page()); }