public async Task <IActionResult> PutEmployee(int id, Employee employee) { if (id != employee.EmployeeId) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
static async void AddIceCream() { using (var db = new DALContext()) { IceCream a = new IceCream { Name = "IKEA" }; Rating rating = new Rating { Author = "Gab", Description = "Super glace", Rate = 4 }; Rating rating2 = new Rating { Author = "Jo", Description = "Mouais", Rate = 5 }; a.Ratings.Add(rating); a.Ratings.Add(rating2); Shop shop = new Shop { Address = "Rue des Ardennes", Name = "IceCream Shop" }; shop.Supply.Add(a); db.IceCreams.Add(a); db.Shops.Add(shop); await db.SaveChangesAsync(); Console.WriteLine("Fin"); Retrieve(); Console.Read(); } }
static async void TestUpdate() { using (var db = new DALContext()) { var oldI = await db.IceCreams.FindAsync(4); var newI = oldI; newI.Name = "IKEA 222"; db.Entry(oldI).CurrentValues.SetValues(newI); await db.SaveChangesAsync(); } }
static async void Update() { using (var db = new DALContext()) { var ice = db.IceCreams.First(); Console.WriteLine("Avant "); Console.WriteLine($"{ice.Name} {ice.Description}"); var newIce = ice; newIce.Description = "Une nouvelle description"; newIce.AverageRate = 4; db.Entry(ice).CurrentValues.SetValues(newIce); await db.SaveChangesAsync(); var icen = db.IceCreams.First(); Console.WriteLine($"{icen.Name} {icen.Description}"); } }