public async Task <IActionResult> PutUserModel([FromRoute] int id, [FromBody] UserModel userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userModel.UserId) { return(BadRequest()); } _context.Entry(userModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMembership([FromRoute] int id, [FromBody] Membership membership) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != membership.MembershipId) { return(BadRequest()); } _context.Entry(membership).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MembershipExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// 添加 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public async Task <int> AddAsync(T model) { _db.Entry(model).State = EntityState.Added; return(await _db.SaveChangesAsync()); }