//[Ignore("Initial integration test. Run once.")] public void SaveChanges() { using (var db = new DomainDbContext()) { var products = db.Products.ToList(); var customer = db.Customers.FirstOrDefault(); if (customer == null) { customer = new Customer { FirstName = "Elton", LastName = "Stoneman" }; } var order = new Order { Reference = Guid.NewGuid().ToString(), Customer = customer }; foreach (var product in products) { order.OrderProducts.Add(new OrderProduct() { Product = product }); } db.Orders.Add(order); db.Save(); } }
private static void CreateDatabase() { System.IO.File.Delete("TestDatabase.db"); using (var domainDbContext = new DomainDbContext()) { domainDbContext.Database.EnsureCreated(); } }
public static void Init() { //Create the Entity Frameworkd DBContext _domainDbContext = new DomainDbContext(); //Create the database _domainDbContext.Database.EnsureCreated(); //Create repositories. _deliveryRepository = new DeliveryRepository(_domainDbContext); _plannedDeliveryRepository = new PlannedDeliveryRepository(_domainDbContext); }
public void UpdateOrder() { using (var db = new DomainDbContext()) { var order = db.Orders.FirstOrDefault(); if (order != null) { order.Reference += ".1"; db.Save(); } } }
public void UpdateProduct() { using (var db = new DomainDbContext()) { var product = db.Products.FirstOrDefault(); if (product != null) { product.Name += " new"; db.Save(); } } }
static void Main(string[] args) { System.IO.File.Delete("TestDatabase.db"); var newCustomerId = Guid.NewGuid().ToString(); using (var domainDbContext = new DomainDbContext()) { domainDbContext.Database.EnsureCreated(); } using (var domainDbContext = new DomainDbContext()) { var repository = new CustomerRepository(domainDbContext); var customer = new Customer { Id = newCustomerId, City = "Maldegem" }; customer.AddDeliveryAddress(new DeliveryAddress { Id = Guid.NewGuid().ToString(), Address = new AddressStruct { AddressLine1 = "Kleitkalseide" } }); repository.Add(customer); } using (var domainDbContext = new DomainDbContext()) { var repository = new CustomerRepository(domainDbContext); var customer = repository.GetById(newCustomerId); Console.WriteLine(customer.City); foreach (var deliveryAddress in customer.DeliveryAddresses) { Console.WriteLine(deliveryAddress.Address.AddressLine1); } //var deliveryRepository = new DeliveryRepository(domainDbContext); //var specification = new DeliveryIsPlannedSpecification(); //var list = deliveryRepository.List(specification); } Console.WriteLine("Done"); Console.ReadKey(); }
// POST api/customers public HttpResponseMessage Post([FromBody] Customer customer) { using (var db = new DomainDbContext()) { db.Customers.Add(customer); db.Save(); } var response = new HttpResponseMessage(HttpStatusCode.Created); // Using the extension method to set Location header response.AddLocationHeader(Request, customer.Id); return(response); }
private static void Test_DeleteCustomer() { using (var domainDbContext = new DomainDbContext()) { var query = from c in domainDbContext.Customers select c; var customerForid = query.FirstOrDefault(); var repository = new CustomerRepository(domainDbContext); var customer = repository.GetById(customerForid.Id); repository.Delete(customer); } }
// GET api/customers public Customer Get(int id) { Customer customer = null; using (var db = new DomainDbContext()) { db.Configuration.LazyLoadingEnabled = false; customer = db.Customers.Find(id); } if (customer == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(customer); }
protected virtual DomainDbContext BootstrapContext(bool deleteData = false, bool initialize = false) { var dbContext = new DomainDbContext(); if (deleteData) { TeardownData(dbContext); dbContext.SaveChanges(); } if (initialize) { dbContext.Database.Initialize(true); } return(dbContext); }
public DomainDbContext BuildDataContext(bool withData = true) { var builder = new DbContextOptionsBuilder <DomainDbContext>(); builder = builder.UseInMemoryDatabase("TestDb"); var db = new DomainDbContext(builder.Options); db.Database.EnsureCreated(); if (withData) { DataSeed seed = new DataSeed(db); seed.Seed(); } return(db); }
private static void Test_UpdateCustomer_UpdateOneAddress_DeleteTheOther() { using (var domainDbContext = new DomainDbContext()) { var query = from c in domainDbContext.Customers select c; var customerForid = query.FirstOrDefault(); var repository = new CustomerRepository(domainDbContext); var customer = repository.GetById(customerForid.Id); customer.DeliveryAddresses[0].Address.AddressLine1 = "Changed !!"; customer.DeliveryAddresses.RemoveAt(1); repository.Update(customer); } }
public static async Task DispatchDomainEventsAsync(this IMediator mediator, DomainDbContext ctx) { var domainEntities = ctx.ChangeTracker .Entries <Entity>() .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any()); var domainEvents = domainEntities .SelectMany(x => x.Entity.DomainEvents) .ToList(); domainEntities.ToList() .ForEach(entity => entity.Entity.ClearDomainEvents()); var tasks = domainEvents .Select(async(domainEvent) => { await mediator.Publish(domainEvent); }); await Task.WhenAll(tasks); }
private static void Test_InsertCustomer() { using (var domainDbContext = new DomainDbContext()) { var customerId = Guid.NewGuid().ToString(); var customer = new Customer(); customer.Id = customerId; customer.Name = "Test"; customer.Info = "Test"; customer.AddDeliveryAddress(new DeliveryAddress { CustomerId = customerId, Id = Guid.NewGuid().ToString(), Info = "Test 1", Address = new DomainModel.ValueObjects.AddressStruct { AddressLine1 = "a", AddressLine2 = "b", AddressLine3 = "c", City = "X" } }); customer.AddDeliveryAddress(new DeliveryAddress { CustomerId = customerId, Id = Guid.NewGuid().ToString(), Info = "Test 2", Address = new DomainModel.ValueObjects.AddressStruct { AddressLine1 = "d", AddressLine2 = "e", AddressLine3 = "f", City = "X" } }); var repository = new CustomerRepository(domainDbContext); repository.Add(customer); } }
public Repository(DomainDbContext context) => _domainDbContext = context ?? throw new ArgumentException(nameof(context));
public PostsController(DomainDbContext context) { _context = context; }
public CommentsController(DomainDbContext context) { _context = context; }
public DisciplinesController(DomainDbContext context) { _context = context; }
public Store(DomainDbContext dbContext) { DbContext = dbContext; }
public DomainDbContextTransactionBehavior(DomainDbContext dbContext, ILogger <DomainDbContextTransactionBehavior <TRequest, TResponse> > logger) : base(dbContext, logger) { }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IDispatcher dispatcher, DomainDbContext domainDbContext) { // Ensure WeapsyCqrs database is installed. domainDbContext.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async context => { // Create a sample product loading data from domain events. var product = await GettingStarted.CreateProduct(dispatcher); // Display product title. await context.Response.WriteAsync($"Product title: {product.Title}"); }); }
public PerfilServices(DomainDbContext domainDb) { _domainDb = domainDb; }
public ProjectController() { _context = new DomainDbContext(); }
public CategoriesController(DomainDbContext context) { _context = context; }
public DomainManager(DomainDbContext context) { _context = context; }
public PostServices(DomainDbContext context) { Context = context; }
public DeliveryRepository(DomainDbContext domainDbContext) : base(domainDbContext) { }
public void Init() { _db = BuildDataContext(); _store = new ProductStore(_db); }
public BaseRepository(DomainDbContext domainDbContext) { _domainDbContext = domainDbContext; }
public CreateCustomerController(DomainDbContext db) { _db = db; }