// Generate dummy data for Customer Unit Tests if needed private void GenerateDummyCustomers(CustomerContext context) { context.Add(new Customer { Id = 1, FirstName = "Kurt", LastName = "Cobain", DateOfBirth = DateTime.Today }); context.Add(new Customer { Id = 2, FirstName = "Dave", LastName = "Grohl", DateOfBirth = DateTime.Today.AddDays(1) }); context.Add(new Customer { Id = 3, FirstName = "Jim", LastName = "Morrison", DateOfBirth = DateTime.Today.AddDays(2) }); context.SaveChanges(); }
public async Task Should_throw_if_specified_connection_mode_is_wrong() { var exception = await Assert.ThrowsAsync <ArgumentOutOfRangeException>( async() => { await using (var testDatabase = CosmosTestStore.CreateInitialized( DatabaseName, o => o.ConnectionMode((ConnectionMode)123456))) { var options = CreateOptions(testDatabase); var customer = new Customer { Id = 42, Name = "Theon" }; using (var context = new CustomerContext(options)) { context.Database.EnsureCreated(); context.Add(customer); context.SaveChanges(); } } }); }
public async Task <Customer> AddNewCustomer(Customer c) { _customerContext.Add(c); await _customerContext.SaveChangesAsync(); return(c); }
public void Should_throw_if_specified_region_is_wrong() { var regionName = "FakeRegion"; Action a = () => { using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region(regionName))) { var options = Fixture.CreateOptions(testDatabase); var customer = new Customer { Id = 42, Name = "Theon" }; using (var context = new CustomerContext(options)) { context.Database.EnsureCreated(); context.Add(customer); context.SaveChanges(); } } }; var ex = Assert.Throws <ArgumentException>(a); Assert.Equal("Current location is not a valid Azure region.", ex.Message); }
public IEnumerable <MrzInfo> InsertMrzInfo(MrzInfo mrzInfo) { mrzInfo.CreatedDate = DateTime.Now; _dbContext.Add(mrzInfo); Save(); return(_dbContext.MrzInfos.ToList()); }
public async Task Should_throw_if_specified_region_is_wrong() { var exception = await Assert.ThrowsAsync <ArgumentException>(async() => { await using (var testDatabase = CosmosTestStore.CreateInitialized(DatabaseName, o => o.Region("FakeRegion"))) { var options = CreateOptions(testDatabase); var customer = new Customer { Id = 42, Name = "Theon" }; using (var context = new CustomerContext(options)) { context.Database.EnsureCreated(); context.Add(customer); context.SaveChanges(); } } }); Assert.Equal("Current location is not a valid Azure region.", exception.Message); }
public async Task Can_add_update_delete_end_to_end() { using (var testDatabase = CosmosSqlTestStore.CreateInitialized(DatabaseName)) { var options = Fixture.CreateOptions(testDatabase); var customer = new Customer { Id = 42, Name = "Theon" }; using (var context = new CustomerContext(options)) { await context.Database.EnsureCreatedAsync(); context.Add(customer); await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon", customerFromStore.Name); } using (var context = new CustomerContext(options)) { customer.Name = "Theon Greyjoy"; context.Update(customer); await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); } using (var context = new CustomerContext(options)) { context.Remove(customer); await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { Assert.Equal(0, context.Set <Customer>().Count()); } } }
public async Task AddCustomerAsync(CustomerModel customer) { _customerContext.Add(new CustomerEntity { FirstName = customer.FirstName, LastName = customer.LastName, DateOfBirth = customer.DateOfBirth }); await _customerContext.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Amount")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("id,firstName,surname,emailAddress,password")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CustomerID,CustomerName,TFN,Address,City,State,PostCode,Phone")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CustomerID,Name,address,Code,Checked,JoinedDate")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Addrses1,City,Province,Country,Postal,Phone,Email")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ID,ISBN,Title,List_Price,ReleaseDate")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("customerId,name,dateOfPurchase,product,quantity,price")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CallerId,Login,Name,LastName")] Caller caller) { if (ModelState.IsValid && _context.Callers.All(c => c.Login != caller.Login)) { _context.Add(caller); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(caller)); }
public async Task <IActionResult> Create([Bind("CustomerId,Name,Email,Gender,DateRegistered,EventDays,AdditionalReq")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Address,Zipcode,City")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("id,FirstName,SecondName,ThirdName,Addres,PhoneNumber,EGN,NameOfBook,DateOfRecord,DateOfDeregistration")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CustomerID,CustomerName,CustomerSurName,Email")] Customer customer) { if (ModelState.IsValid) { customer.CustomerID = Guid.NewGuid(); _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("orderID,dateOrderPlaced,dateOrderPaid,paymentMethod,CustomerFK")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerFK"] = new SelectList(_context.Customers, "customerId", "customerId", order.CustomerFK); return(View(order)); }
public async Task <IActionResult> Create([Bind("Id,Email,Password,Salt,CreatedAt,UpdatedAt,Status")] Customer customer) { if (ModelState.IsValid) { customer.GenerateSalt(); customer.EncryptPassword(); _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ProductID,CustomerID")] Favorite favorite) { if (ModelState.IsValid) { _context.Add(favorite); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = favorite.CustomerID })); } ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "CustomerID", favorite.CustomerID); ViewData["ProductID"] = new SelectList(_context.Products, "ID", "Title", favorite.ProductID); return(View(favorite)); }
public void Test_GetCustomerOrderHistory() { var options = new DbContextOptionsBuilder <OrderContext>() .UseInMemoryDatabase(databaseName: "TestDb15") .Options; var options1 = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb15") .Options; var options2 = new DbContextOptionsBuilder <CustomerContext>() .UseInMemoryDatabase(databaseName: "TestDb15") .Options; using (var context = new OrderContext(options)) { using (var context1 = new StoreContext(options1)) { using (var context2 = new CustomerContext(options2)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context1.Database.EnsureDeleted(); context1.Database.EnsureCreated(); context2.Database.EnsureDeleted(); context2.Database.EnsureCreated(); OrderRepository orderRepo = new OrderRepository(context); StoreRepository storeRepo = new StoreRepository(context1); CustomerRepository custRepo = new CustomerRepository(context2); OrderLogic ol = new OrderLogic(orderRepo, storeRepo, custRepo); AStore store = new AStore(); Customer newCust = new Customer(); Order testOrder = new Order(); testOrder.Store = store.StoreID; testOrder.Cust = newCust.CustomerID; testOrder.JSONPizzaOrder = "this is a test order for customers"; context.Add <Order>(testOrder); context1.Add <AStore>(store); context2.Add <Customer>(newCust); context.SaveChanges(); context1.SaveChanges(); context2.SaveChanges(); RawOrderHistory createOrder = ol.GetCustomerOrderHistory(newCust.CustomerID); Assert.Equal(testOrder.JSONPizzaOrder, createOrder.jsonPizzaOrders[0]); } } } }
public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,PhoneNumber,Email")] Customer customer) { if (ModelState.IsValid) { if (_context.Customers.All(c => c.Email != customer.Email) && _context.Customers.All(c => c.PhoneNumber != customer.PhoneNumber)) { _context.Add(customer); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CustomerId,CallerId")] Call call) { call.Time = new CallTime(DateTime.Now, _callStrategy.Call()); if (ModelState.IsValid) { _context.Add(call); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "Email", call.CustomerId); ViewData["CallerId"] = new SelectList(_context.Callers, "CallerId", "Login", call.CallerId); return(View(call)); }
public Note Add(Note note) { // TODO: Validate FK var noteData = new Note { Id = Guid.NewGuid(), CustomerId = note.CustomerId, Value = note.Value }; customerContext.Add(noteData); customerContext.SaveChanges(); return(noteData); }
public async Task Can_add_update_delete_end_to_end_async() { var options = Fixture.CreateOptions(); var customer = new Customer { Id = 42, Name = "Theon" }; using (var context = new CustomerContext(options)) { await context.Database.EnsureCreatedAsync(); context.Add(customer); await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { var customerFromStore = await context.Set <Customer>().SingleAsync(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon", customerFromStore.Name); customerFromStore.Name = "Theon Greyjoy"; await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { var customerFromStore = await context.Set <Customer>().SingleAsync(); Assert.Equal(42, customerFromStore.Id); Assert.Equal("Theon Greyjoy", customerFromStore.Name); context.Remove(customerFromStore); await context.SaveChangesAsync(); } using (var context = new CustomerContext(options)) { Assert.Empty(await context.Set <Customer>().ToListAsync()); } }
public async Task CreateRequestForCommandAsync <T>(Guid id) { var exists = await ExistAsync(id); var request = exists ? throw new InvalidOperationException($"Request with {id} already exists") : new ClientRequest() { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add(request); await _context.SaveChangesAsync(); }
public static void DoDB() { ImageStreamer(); var dbConnection = Configuration.GetConnectionString("DBConn"); DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder(); if (!optionsBuilder.IsConfigured) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var connectionString = configuration.GetConnectionString("DBConn"); optionsBuilder.UseSqlite(connectionString); } using (var db = new CustomerContext()) { var customer = new Customer { LName = "Cox", FName = "Johann", DOB = new DateTime(2001, 01, 30).ToString(), Address = "200 Heywood Ave", City = "Spartanburg", State = "SC", ZipCode = "29304", Interests = "Hiking, Biking, Cloud Watching", Image = imageBytes }; if (db.Customers.Count() >= 1) { // string tablename = "Customers"; FormattableString sql = $"delete from Customers;"; db.Database.ExecuteSqlCommand(sql); //db.Customers.RemoveRange(db.Customers); db.SaveChanges(); } db.Add(customer); db.SaveChangesAsync(); } }