public async Task <IActionResult> PutAdult(int id, Adult adult) { if (id != adult.Id) { return(BadRequest()); } _context.Entry(adult).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdultExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task addNewAdultAsync(Adult adult) { EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(adult); await ctx.SaveChangesAsync(); //return newlyAdded.Entity; }
public async Task <Adult> AddAdult(Adult todo) { EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(todo); await ctx.SaveChangesAsync(); return(newlyAdded.Entity); }
public async Task <User> AddUserAsync(User user) { EntityEntry <User> newUser = await ctx.users.AddAsync(user); await ctx.SaveChangesAsync(); return(newUser.Entity); }
public async Task <Adult> AddAdultAsync(Adult adult) { EntityEntry <Adult> newAdult = await cxt.Adults.AddAsync(adult); await cxt.SaveChangesAsync(); return(newAdult.Entity); }
public async Task <Adult> AddAdultsAsync(Adult person) { int max = adults.Max(person => person.Id); person.Id = (++max); adults.Add(person); await ctx.Adult.AddAsync(person); await ctx.SaveChangesAsync(); return(person); }
public async Task UpdateAdultsAsync(Adult person) { AdultContext dbContext = new AdultContext(); dbContext.Update(person); await dbContext.SaveChangesAsync(); }
public async Task <IActionResult> PostAdult(int id, Adult adult) { Adult adultToModify = await _context.Adults.FindAsync(id); if (adultToModify == null) { return(NotFound()); } else { adultToModify.Update(adult); } await _context.SaveChangesAsync(); //return CreatedAtAction("GetAdult", new { id = adult.Id }, adult); return(CreatedAtAction(nameof(GetAdult), new { id = adult.Id }, adult)); }
private static void AddUsers(IList <User> users) { foreach (User user in users) { using (AdultContext fctxt = new AdultContext()) { Console.WriteLine(user.ToString()); fctxt.Users.AddAsync(user); fctxt.Entry(user).State = EntityState.Added; //fctxt.Entry(user).State = EntityState.Detached; fctxt.SaveChangesAsync(); } } }
private static void AddAdults(IList <Adult> adults) { foreach (Adult adult in adults) { using (AdultContext fctxt = new AdultContext()) { Console.WriteLine(adult.ToString()); fctxt.Adults.AddAsync(adult); fctxt.Entry(adult).State = EntityState.Added; //fctxt.Entry(adult).State = EntityState.Detached; fctxt.SaveChangesAsync(); } } }