public async Task <IActionResult> Create([Bind("ShopId,DepartmentId,ShopName,Description,ImageUrl,Location")] GiftShop giftShop) { if (ModelState.IsValid) { _context.Add(giftShop); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Department, "DepartmentId", "DepartmentName", giftShop.DepartmentId); return(View(giftShop)); }
public async Task <IActionResult> Edit(int id, [Bind("ShopId,DepartmentId,ShopName,Description,ImageUrl,Location")] GiftShop giftShop) { if (id != giftShop.ShopId) { return(NotFound()); } if (ModelState.IsValid) { try { GiftShop _giftShop = _context.GiftShop.Where(s => s.ShopId == giftShop.ShopId).First(); _giftShop.DepartmentId = giftShop.DepartmentId; _giftShop.ShopName = giftShop.ShopName; _giftShop.Description = giftShop.Description; _giftShop.ImageUrl = giftShop.ImageUrl; _giftShop.Location = giftShop.Location; _context.Update(_giftShop); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GiftShopExists(giftShop.ShopId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Department, "DepartmentId", "DepartmentName", giftShop.DepartmentId); return(View(giftShop)); }