public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,age,FullAddress,DateOfBirth")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "CustomerID,ContactName,Country,BirthDay")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public Customer AddCustomer(Customer item) { try { context.Customers.Add(item); context.SaveChanges(); return(item); } catch { throw; } }
public IActionResult Post([FromBody] Customer customer) { try { _customersDbContext.Customers.Add(customer); _customersDbContext.SaveChanges(); return(Ok(customer)); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Jessica Smith", Address = "20 Elm St." }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "John Smith", Address = "30 Main St." }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "William Johnson", Address = "100 10th St." }); dbContext.Customers.Add(new Db.Customer() { Id = 4, Name = "sushil", Address = "Loghgoan" }); dbContext.Customers.Add(new Db.Customer() { Id = 5, Name = "ashish", Address = "Hadpsar" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Add(new Db.Customer() { Id = 1, Name = "Bhavin Modi", Address = "Vadodara" }); dbContext.Add(new Db.Customer() { Id = 2, Name = "Naksh Modi", Address = "Mumbai" }); dbContext.Add(new Db.Customer() { Id = 3, Name = "Rajesh Modi", Address = "Pune" }); dbContext.Add(new Db.Customer() { Id = 4, Name = "Akta Modi", Address = "Delhi" }); dbContext.Add(new Db.Customer() { Id = 5, Name = "Purnima Modi", Address = "Udaipur" }); dbContext.SaveChanges(); } }
public CustomersControllerTests() { // Instantiating the DbContext object. // With each test a new instance of the DbContext object is created. var options = new DbContextOptionsBuilder <CustomersDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; _context = new CustomersDbContext(options); _context.Database.EnsureCreated(); // The prepopulated customers of our Data Store. var customers = new[] { new Customer { Id = 1, firstName = "Steve", lastName = "Rogers", dateOfBirth = new DateTime(1910, 1, 1) }, new Customer { Id = 2, firstName = "Tony", lastName = "Stark", dateOfBirth = new DateTime(1970, 2, 2) }, new Customer { Id = 3, firstName = "Bruce", lastName = "Banner", dateOfBirth = new DateTime(1975, 3, 3) }, new Customer { Id = 4, firstName = "Peter", lastName = "Parker", dateOfBirth = new DateTime(2002, 4, 4) } }; _context.Customers.AddRange(customers); _context.SaveChanges(); var controller = new CustomersController(_context); var query = new CustomersController(_context); }
public void SeedData() { if (_dbContext != null && !_dbContext.Customers.Any()) { _dbContext.Customers.Add(new Core.Entities.Customer { Id = 1, Address = "23 Block camp street VI", Name = "Mike Perry" }); _dbContext.Customers.Add(new Core.Entities.Customer { Id = 2, Address = "6 Block vali street VI", Name = "Tony Wask" }); _dbContext.Customers.Add(new Core.Entities.Customer { Id = 3, Address = "12 derry street Font", Name = "John Mecury" }); _dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Suresh", Address = "Hyd" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "Kumar", Address = "VSKP" }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "SDSurya", Address = "Hyd" }); dbContext.Customers.Add(new Db.Customer() { Id = 4, Name = "Dhakshith", Address = "Hyd" }); dbContext.Customers.Add(new Db.Customer() { Id = 5, Name = "Sunkar", Address = "Hyderabad" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!_dbContext.Customers.Any()) { _dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Rafael", Address = "Rua ABC" }); _dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "José", Address = "Rua DEF" }); _dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "Higor", Address = "Rua GHI" }); _dbContext.Customers.Add(new Db.Customer() { Id = 4, Name = "Pedro", Address = "Rua JKL" }); _dbContext.Customers.Add(new Db.Customer() { Id = 5, Name = "Lucas", Address = "Rua MNO" }); _dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Jessica Smith", Address = "20 Elm St." }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "John Smith", Address = "30 Main St." }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "Alam Sleeper", Address = "10 Main 10th St." }); dbContext.Customers.Add(new Db.Customer() { Id = 4, Name = "William Johnson", Address = "100 10th St." }); dbContext.Customers.Add(new Db.Customer() { Id = 5, Name = "William Talbert", Address = "121 9th St." }); dbContext.Customers.Add(new Db.Customer() { Id = 6, Name = "Scott Johnson", Address = "10 5th St." }); dbContext.Customers.Add(new Db.Customer() { Id = 7, Name = "Audery Charity", Address = "30 Elm St." }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { List <Db.Customer> customers = new List <Db.Customer>() { new Db.Customer() { Id = 1, Name = "Jessica Smith", Address = "20 Elm St." }, new Db.Customer() { Id = 2, Name = "John Smith", Address = "30 Main St." }, new Db.Customer() { Id = 3, Name = "William Johnson", Address = "100 10th St." } }; dbContext.Customers.AddRange(customers); dbContext.SaveChanges(); logger?.LogInformation("Customers added to DB"); } }
public static void SeedData() { using (var dbContext = new CustomersDbContext()) { if (!dbContext.Customers.Any() && !dbContext.Payments.Any()) { dbContext.Customers.AddRange(CustomersSeedData.GetSeedData()); dbContext.Payments.AddRange(PaymentsSeedData.GetSeedData()); dbContext.SaveChanges(); } } }
public static void SeedTestData(CustomersDbContext dbContext) { for (int i = 1; i <= 10; i++) { dbContext.Customers.Add(new Core.Entities.Customer { Id = i, Address = $"Address {i}", Name = $"Name {i}" }); } dbContext.SaveChanges(); }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "John Smith", Address = "Street #123 CP 67456 USA" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "Ken Clark", Address = "Street #222 CP 51000 USA" }); dbContext.SaveChanges(); } }
private void CreateCustomers(CustomersDbContext dbContext) { for (int i = 11; i < 20; i++) { dbContext.Customers.Add(new Customer() { Id = i, Address = $"Address of {i} Customer", FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString(), Zipcode = "834002" }); } dbContext.SaveChanges(); }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.AddRange(new[] { new Db.Customer(1, "Adavesh Managaon", "Koramangala"), new Db.Customer(2, "Virat Kohli", "New Delhi"), new Db.Customer(3, "Dean Winchester", "Kansas"), new Db.Customer(4, "Hannah Baker", "New York"), new Db.Customer(5, "Lucifer Morningstar", "Hell"), }); dbContext.SaveChanges(); } }
private void SeedData() { if (!customersDbContext.customers.Any()) { customersDbContext.customers.Add(new Customer { Id = 1, Address = "1234 Main St", Name = "John" }); customersDbContext.customers.Add(new Customer { Id = 2, Address = "1235 Main St", Name = "James" }); customersDbContext.customers.Add(new Customer { Id = 3, Address = "1236 Main St", Name = "Joey" }); customersDbContext.SaveChanges(); } }
private void SeedData() { if (!_dbContext.Customers.Any()) { _dbContext.Customers.Add((new Db.Customer() { Id = 1, FirstName = "Rahul", LastName = "Sahay", Zipcode = "834002", Address = "Bariyatu, Ranchi" })); _dbContext.Customers.Add((new Db.Customer() { Id = 2, FirstName = "Rohit", LastName = "Sahay", Zipcode = "560001", Address = "RajBhavan Bangalore" })); _dbContext.Customers.Add((new Db.Customer() { Id = 3, FirstName = "Mohit", LastName = "Sahay", Zipcode = "560076", Address = "Bannerghatta Road, Bangalore" })); _dbContext.Customers.Add((new Db.Customer() { Id = 4, FirstName = "Anita", LastName = "Kumari", Zipcode = "834003", Address = "Hatia, Ranchi" })); _dbContext.Customers.Add((new Db.Customer() { Id = 5, FirstName = "Shalini", LastName = "Kumari", Zipcode = "834009", Address = "Hehal, Ranchi" })); _dbContext.SaveChanges(); } }
//SEED DATA - If no db then just add data to local memory private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Young Chang", Address = "15 Constya St. Vista, CA 92083", Email = "*****@*****.**" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "*****@*****.**", Address = "4 Ivy Way Dr. Sunnyside, NY 11104", Email = "Constantine Sokol" }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "*****@*****.**", Address = "28 Lafayette Street. Mount Holly, NJ 08060", Email = "Rich Fisher" }); dbContext.Customers.Add(new Db.Customer() { Id = 4, Name = "Cedrik Silvers", Address = "9521 Meadowbrook Street. Spartanburg, SC 29301", Email = "*****@*****.**" }); dbContext.Customers.Add(new Db.Customer() { Id = 5, Name = "Mario Phearsom", Address = "894 Gregory Court. Chesterton, IN 46304", Email = "*****@*****.**" }); dbContext.SaveChanges(); } }
private static void Seed(CustomersDbContext context) { // Seed with fixed data context.Customers.AddRange(Enumerable.Range(1, 5).Select(index => new Customer { CompanyName = SeedData.DummyCompanyNames[index - 1], ContactName = SeedData.DummyContactNames[index - 1], Address = SeedData.DummyAddresses[index - 1], City = SeedData.DummyCities[index - 1], Region = SeedData.DummyRegions[index - 1], PostalCode = SeedData.DummyPostalCodes[index - 1], Country = SeedData.DummyCountries[index - 1], Phone = SeedData.DummyPhones[index - 1], }).ToArray()); context.SaveChanges(); }
private void SeedData() { if (!_context.Customers.Any()) { _context.Customers.Add(new Db.Customer { Id = 1, Name = "Jessica Smith", Address = "20 Elm St." }); _context.Customers.Add(new Db.Customer { Id = 2, Name = "John Smith", Address = "30 Main St." }); _context.Customers.Add(new Db.Customer { Id = 3, Name = "William Johnson", Address = "100 10th St." }); _context.SaveChanges(); } }
private static void SeedContext(CustomersDbContext context, int rowsCount = 15) { var rng = new Random(); context.Customers.AddRange(Enumerable.Range(1, rowsCount).Select(index => new Customer { CompanyName = DummyCompanyNames[rng.Next(DummyCompanyNames.Length)], ContactName = DummyContactNames[rng.Next(DummyContactNames.Length)], Address = DummyAddresses[rng.Next(DummyAddresses.Length)], City = DummyCities[rng.Next(DummyCities.Length)], Region = DummyRegions[rng.Next(DummyRegions.Length)], PostalCode = DummyPostalCodes[rng.Next(DummyPostalCodes.Length)], Country = DummyCountries[rng.Next(DummyCountries.Length)], Phone = DummyPhones[rng.Next(DummyPhones.Length)] }).ToArray()); context.SaveChanges(); }
private void SeedData() { if (!_dbContext.Customers.Any()) { _dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "KeyBoadrd", Address = "St 3 Deshmoret" }); _dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "Mouse", Address = "BalumStrasse" }); _dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "Monitor", Address = "OsterrichStrasse" }); _dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new CustomerEntity() { Id = 1, Name = "Silas Dantas", Address = "Rua Teste 01" }); dbContext.Customers.Add(new CustomerEntity() { Id = 2, Name = "Filipe Dantas", Address = "Rua Teste 02" }); dbContext.Customers.Add(new CustomerEntity() { Id = 3, Name = "Denise Dantas", Address = "Rua Teste 03" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "john doe", Address = "jay street 1" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "ib ibsen", Address = "ib street 2" }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "al bundy", Address = "bundy street 3" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer { Id = 1, Name = "John", Address = "Canada" }); dbContext.Customers.Add(new Db.Customer { Id = 2, Name = "Steve", Address = "Canada" }); dbContext.Customers.Add(new Db.Customer { Id = 3, Name = "Bill", Address = "Canada" }); dbContext.Customers.Add(new Db.Customer { Id = 4, Name = "Sara", Address = "Canada" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Customer() { Id = 1, Name = "Rodrigo", Address = "México" }); dbContext.Customers.Add(new Customer() { Id = 2, Name = "Leonardo", Address = "Argentina" }); dbContext.Customers.Add(new Customer() { Id = 3, Name = "Renata", Address = "España" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Preethi", Address = "GreenLane" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "Vinay", Address = "Grafton" }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "Tanisha", Address = "Onehunga" }); dbContext.SaveChanges(); } }
private void SeedData() { if (!dbContext.Customers.Any()) { dbContext.Customers.Add(new Db.Customer() { Id = 1, Name = "Berkay", Address = "Çeliktepe" }); dbContext.Customers.Add(new Db.Customer() { Id = 2, Name = "Ömer", Address = "Kayışdağı" }); dbContext.Customers.Add(new Db.Customer() { Id = 3, Name = "Fuko", Address = "Emniyet Evleri" }); dbContext.SaveChanges(); } }