Advertisement
ayurchyk1998

Untitled

May 5th, 2021
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. public async void ButtonAdd (string name, string price, string order)
  2. {
  3.     await using var dbContext = new BurgerContext();
  4.                 await dbContext.Database.EnsureCreatedAsync();
  5.                 Order newOrder = new();
  6.    
  7.                 if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(price)
  8.                     && !string.IsNullOrEmpty(order))
  9.                 {
  10.                     await dbContext.Orders.AddAsync(
  11.                      order =  new Order() { Description = order });
  12.                     await dbContext.Burgers.AddAsync(
  13.                         new Burger() {Name = name, Price = Convert.ToDouble(price), Order = newOrder});
  14.                    
  15.                     await dbContext.SaveChangesAsync();
  16.  
  17.                     MessageBox.Show("Data is saved", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  18.                 }        
  19.                 else
  20.                 {
  21.                     MessageBox.Show("Something went wrong", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information);
  22.                 }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement