public void AddCustomer(Customer customerToAdd) { if (customerToAdd == null) { throw new ArgumentNullException(nameof(customerToAdd)); } _context.Add(customerToAdd); }
public async Task <IActionResult> Create([Bind("Id,Name,Phone,LastPurchase")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task ResetData() { var notes = await _dbContext.Notes.ToListAsync(); _dbContext.RemoveRange(notes); var customers = await _dbContext.Customers.ToListAsync(); _dbContext.RemoveRange(customers); await _dbContext.SaveChangesAsync(); for (int i = 1; i <= 10; i++) { var newCustomer = new Customer { FirstName = $"First Name {i}", LastName = $"Last Name {i}", City = $"City {i}", Country = $"Country {i}", Street = $"Street {i}", Status = CustomerStatus.Current }; for (int j = 1; j <= 3; j++) { var newNote = new Note { Content = $"Content {j}" }; newCustomer.Notes.Add(newNote); } _dbContext.Add(newCustomer); } await _dbContext.SaveChangesAsync(); }
public static void Interceptors_get_the_source_of_the_command() { Console.WriteLine($">>>> Sample: {nameof(Interceptors_get_the_source_of_the_command)}"); Console.WriteLine(); using var context = new CustomersContext(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add( new Customer { Name = "Sam Vimes" }); context.SaveChanges(); context.ChangeTracker.Clear(); var customers = context.Customers.ToList(); Console.WriteLine(); }