public async Task <IActionResult> Edit(int id, [Bind("ListingId,Name,StartingBidAmount,AuctionStartTime,AuctionEndTime,Description,ListingImage")] AuctionItemModel auctionItemModel) { if (id != auctionItemModel.ListingId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(auctionItemModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuctionItemModelExists(auctionItemModel.ListingId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(auctionItemModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Title,ReleaseDate,Genre,Price,Rating,ID")] Movie movie) { if (id != movie.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("AvatarImage,Name,Email,MobilePhone,Status,ID")] ApplicationUser applicationUser) { if (id != applicationUser.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(applicationUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationUserExists(applicationUser.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(applicationUser)); }
public static void Update() { context.Update <User>(a => a.Id == 1, a => new User() { Name = a.Name, Age = a.Age + 1, Gender = Gender.Man, OpTime = DateTime.Now }); /* * */ //批量更新 //给所有女性年轻 1 岁 context.Update <User>(a => a.Gender == Gender.Woman, a => new User() { Age = a.Age - 1, OpTime = DateTime.Now }); /* * */ User user = new User(); user.Id = 1; user.Name = "lu"; user.Age = 28; user.Gender = Gender.Man; user.OpTime = DateTime.Now; context.Update(user); //会更新所有映射的字段 /* * */ /* * 支持只更新属性值已变的属性 */ context.TrackEntity(user); //在上下文中跟踪实体 user.Name = user.Name + "1"; context.Update(user); //这时只会更新被修改的字段 /* * */ ConsoleHelper.WriteLineAndReadKey(); }