// GET: api/Commandes/5 public IEnumerable<MyOrder> Get(int id, string nom, string prenom ) { using (AWContext db = new AWContext()) { return db.GetOrders(id); } }
public void CreateDatabase_ModelConfigurationsAreApplied( Mock <IMediator> mockMediator ) { //Arrange var contextOptions = new DbContextOptionsBuilder <AWContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new AWContext( contextOptions, mockMediator.Object, typeof(AddressTypeConfiguration).Assembly ); //Act context.Database.EnsureCreated(); //Assert var entityTypes = context.Model.GetEntityTypes().ToList(); entityTypes[0].Name.Should().Be(typeof(AddressType).FullName); entityTypes[1].Name.Should().Be(typeof(ContactType).FullName); entityTypes[2].Name.Should().Be(typeof(CountryRegion).FullName); entityTypes[3].Name.Should().Be(typeof(ShipMethod).FullName); entityTypes[4].Name.Should().Be(typeof(StateProvince).FullName); entityTypes[5].Name.Should().Be(typeof(Territory).FullName); }
/// <summary> /// Initialize the application database. /// </summary> public static void InitializeDatabase() { using (var databaseUpdateLock = new ApplicationLock(LOCK_NAME, ApplicationSettings.ApplicationConnectionString)) { Stopwatch stopwatch = Stopwatch.StartNew(); // Try to obtain the lock on the database. If not obtained during the specified interval, retry. while (!databaseUpdateLock.TryGetLock(ApplicationSettings.DatabaseInitializationRetryInterval)) { // After the specified timeout, if the lock is still not obtained, throw an exception to stop the application starting if (stopwatch.Elapsed.TotalMilliseconds >= ApplicationSettings.DatabaseInitializationTimeout) { throw new DatabaseUpdateException("Timeout trying to get the lock on the application database."); } } stopwatch.Stop(); // If the the lock is obtained, initialize the database try { Database.SetInitializer(new MigrateDatabaseToLatestVersion <AWContext, Configuration>()); using (var context = new AWContext()) { context.Database.Initialize(force: true); } } finally { databaseUpdateLock.ReleaseLock(); } } }
private void InitialLoadApplication() { var context = new AWContext(); ICustomerRepository customerRepository = new CustomerRepository(context); _customerService = new CustomerService(customerRepository); }
public ShoppingDetails Get(int businessEntityID) { ShoppingDetails details = new ShoppingDetails(); using (var context = new AWContext()) { var result = (from a in context.Address join b in context.BusinessEntityAddress on a.AddressID equals b.AddressID join sp in context.StateProvince on a.StateProvinceID equals sp.StateProvinceID where b.BusinessEntityID == businessEntityID orderby a.AddressID descending select new { AddressLine1 = a.AddressLine1, City = a.City, PostalCode = a.PostalCode, CountryRegionCode = sp.CountryRegionCode } ).FirstOrDefault(); if (result != null) { details = new ShoppingDetails { Address = result.AddressLine1, City = result.City, PostalCode = result.PostalCode, Country = result.CountryRegionCode } } ; } return(details); }
public int Create(Person person) { using (var context = new AWContext()) { BusinessEntity bs = new BusinessEntity { rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now }; context.BusinessEntity.Add(bs); context.SaveChanges(); bs.Person = new Person { BusinessEntityID = bs.BusinessEntityID, PersonType = person.PersonType, FirstName = person.FirstName, LastName = person.LastName, ModifiedDate = DateTime.Now, rowguid = Guid.NewGuid() }; int id = bs.BusinessEntityID; context.SaveChanges(); return(id); } }
public List <ShopCartLine> GetPurchaseOrderDetails(int purchaseID) { var result = new List <ShopCartLine>(); using (AWContext context = new AWContext()) { var items = ( from pod in context.PurchaseOrderDetail join p in context.Product on pod.ProductID equals p.ProductID where pod.PurchaseOrderID == purchaseID select new { Product = pod.Product, Quantity = pod.OrderQty } ); foreach (var item in items) { result.Add(new ShopCartLine { Product = item.Product, Quantity = item.Quantity }); } return(result); } }
// GET: api/Commandes public IEnumerable<MyOrder> Get() { using (AWContext db = new AWContext()) { return db.GetOrders(30072); } }
public void CreateDatabase_ModelConfigurationsAreApplied( Mock <IMediator> mockMediator ) { //Arrange var contextOptions = new DbContextOptionsBuilder <AWContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new AWContext( contextOptions, mockMediator.Object, typeof(CustomerConfiguration).Assembly ); //Act context.Database.EnsureCreated(); //Assert var entityTypes = context.Model.GetEntityTypes().ToList(); entityTypes[0].Name.Should().Be(typeof(Entities.Address).FullName); entityTypes[1].Name.Should().Be(typeof(Entities.Customer).FullName); entityTypes[2].Name.Should().Be(typeof(Entities.CustomerAddress).FullName); entityTypes[3].Name.Should().Be(typeof(Entities.IndividualCustomer).FullName); entityTypes[4].Name.Should().Be(typeof(Entities.Person).FullName); entityTypes[5].Name.Should().Be(typeof(Entities.PersonEmailAddress).FullName); entityTypes[6].Name.Should().Be(typeof(Entities.PersonPhone).FullName); entityTypes[7].Name.Should().Be(typeof(Entities.SalesOrder).FullName); entityTypes[8].Name.Should().Be(typeof(Entities.StoreCustomer).FullName); entityTypes[9].Name.Should().Be(typeof(Entities.StoreCustomerContact).FullName); }
private void UpdateSalesData(decimal saleSum, int purchaseID) { using (var context = new AWContext()) { var employeeID = context.PurchaseOrderHeader.Where(x => x.PurchaseOrderID == purchaseID).Select(x => x.EmployeeID).FirstOrDefault(); var result = context.SalesPerson.Where(x => x.BusinessEntityID == employeeID).FirstOrDefault(); result.SalesYTD += saleSum; context.SaveChanges(); } }
private void InitializeObjects() { _context = new AWContext(); _context1 = new AWContext(); _programa = new DataRepository <IAWContext, Programa>(_context); _proyecto = new DataRepository <IAWContext, Proyecto>(_context); _comunidad = new DataRepository <IAWContext, Comunidad>(_context); _actividad = new DataRepository <IAWContext, Actividad>(_context); _beneficiario = new DataRepository <IAWContext, Beneficiario>(_context); }
private decimal GetTaxRate(string country) { using (AWContext context = new AWContext()) { var result = (from t in context.SalesTaxRate join s in context.StateProvince on t.StateProvinceID equals s.StateProvinceID where s.CountryRegionCode == country select t.TaxRate ).FirstOrDefault(); return(result); } }
public List <PurchaseOrderHeader> GetPurchaseOrders(int customerID) { using (AWContext context = new AWContext()) { var result = ( from h in context.PurchaseOrderHeader where (h.Status == 2 || h.Status == 3) && h.BusinessEntityID == customerID select h ); return(result.ToList()); } }
public int GetStateProvince(string city, string countryCode) { using (var context = new AWContext()) { int result = ( from s in context.StateProvince where s.Name == city && s.CountryRegionCode == countryCode select s.StateProvinceID ).FirstOrDefault(); return(result); } }
private int MinSalesWorker(string city) { using (var context = new AWContext()) { var workerID = (from s in context.SalesPerson join t in context.SalesTerritory on s.TerritoryID equals t.TerritoryID join p in context.StateProvince on t.TerritoryID equals p.TerritoryID where p.Name == city orderby s.SalesLastYear + s.SalesYTD select s.BusinessEntityID ).FirstOrDefault(); return(workerID); } }
public void UpdateStatus(int orderID, int workerID, byte status = 2) { using (AWContext context = new AWContext()) { var result = context.PurchaseOrderHeader.SingleOrDefault(o => o.PurchaseOrderID == orderID); if (workerID != 0) { result.EmployeeID = workerID; } result.Status = status; result.ModifiedDate = DateTime.Now; context.SaveChanges(); } }
private void UpdateOrder(List <PurchaseOrderDetailXML> details, int purchaseID) { using (var context = new AWContext()) { foreach (var detail in details) { var result = context.ProductInventory.Where(x => x.ProductID == detail.ProductID).OrderByDescending(x => x.Quantity).FirstOrDefault(); result.Quantity -= detail.Quantity; } OrderProcessor order = new OrderProcessor(); order.UpdateStatus(purchaseID, workerID: 0, status: 3); context.SaveChanges(); } }
private void InsertAddress(ShoppingDetails shoppingDetails, int businessEntityID) { ShoppingAddress shoppingAddress = new ShoppingAddress(); ShoppingDetails details = shoppingAddress.Get(businessEntityID); if (!details.Equals(shoppingDetails)) { using (var context = new AWContext()) { var customerAddress = new Address() { AddressLine1 = shoppingDetails.Address, City = shoppingDetails.City, StateProvinceID = shoppingAddress.GetStateProvince(shoppingDetails.City, shoppingDetails.Country), PostalCode = shoppingDetails.PostalCode, ModifiedDate = DateTime.Now, rowguid = Guid.NewGuid() }; if (details.Address != null) //update { var addressID = context.BusinessEntityAddress.SingleOrDefault(x => x.BusinessEntityID == businessEntityID).AddressID; var result = context.Address.SingleOrDefault(x => x.AddressID == addressID); result.AddressLine1 = customerAddress.AddressLine1; result.City = customerAddress.City; result.StateProvinceID = customerAddress.StateProvinceID; result.PostalCode = customerAddress.PostalCode; result.ModifiedDate = customerAddress.ModifiedDate; result.rowguid = customerAddress.rowguid; context.SaveChanges(); } else // insert { var businessEntity = new BusinessEntityAddress() { BusinessEntityID = businessEntityID, AddressTypeID = 1, ModifiedDate = DateTime.Now, rowguid = Guid.NewGuid() }; context.Address.Add(customerAddress); context.SaveChanges(); businessEntity.AddressID = customerAddress.AddressID; context.BusinessEntityAddress.Add(businessEntity); context.SaveChanges(); } } } }
private OrderXMLDetail GetData(int purchaseID) { using (AWContext context = new AWContext()) { var result = ( from po in context.PurchaseOrderHeader join be in context.BusinessEntity on po.BusinessEntityID equals be.BusinessEntityID join per in context.Person on be.BusinessEntityID equals per.BusinessEntityID join bea in context.BusinessEntityAddress on be.BusinessEntityID equals bea.BusinessEntityID join ads in context.Address on bea.AddressID equals ads.AddressID where po.PurchaseOrderID == purchaseID select new OrderXMLDetail { OrderDetail = new OrderDetail { AddressLine = ads.AddressLine1, City = ads.City, PurchaseID = po.PurchaseOrderID, TotalDue = po.TotalDue, SubTotal = po.SubTotal }, EmployeeID = po.EmployeeID, FirstName = per.FirstName, LastName = per.LastName } ).FirstOrDefault(); var subOrder = ( from pod in context.PurchaseOrderDetail join p in context.Product on pod.ProductID equals p.ProductID where pod.PurchaseOrderID == purchaseID select new PurchaseOrderDetailXML { PurchaseOrderDetailID = pod.PurchaseOrderDetailID, ProductName = p.Name, Quantity = pod.OrderQty, UnitPrice = pod.UnitPrice, LineTotal = pod.LineTotal, ProductID = pod.ProductID } ); result.OrderLine = subOrder.ToList(); UpdateSalesData(result.OrderDetail.SubTotal, purchaseID); UpdateOrder(result.OrderLine, purchaseID); return(result); } }
public List <VendorProductsInfo> ListVendorProducts() { using (var context = new AWContext()) { var result = from data in context.ProductVendors select new VendorProductsInfo { ProductName = data.Product.Name, Number = data.Product.ProductNumber, SellingPrice = data.Product.ListPrice, StandardPurchasePrice = data.StandardPrice, MinOrder = data.MinOrderQty, MaxOrder = data.MaxOrderQty, Unit = data.UnitMeasure.Name, LeadTime = data.AverageLeadTime, Vendor = data.Vendor.Name }; return(result.ToList()); } }
public List <GeneratedDTO> Generate() { using (var context = new AWContext()) { var logins = ( from e in context.Employee join s in context.SalesPerson on e.BusinessEntityID equals s.BusinessEntityID join p in context.Person on e.BusinessEntityID equals p.BusinessEntityID join pp in context.Password on p.BusinessEntityID equals pp.BusinessEntityID select new GeneratedDTO { LoginID = e.LoginID + "@gmail.com", Password = pp.PasswordSalt, BusinessEntityID = e.BusinessEntityID } ); return(logins.ToList()); } }
public void CreateDatabase_ModelConfigurationsAreApplied( Mock <IMediator> mockMediator ) { //Arrange var contextOptions = new DbContextOptionsBuilder <AWContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new AWContext( contextOptions, mockMediator.Object, typeof(ProductConfiguration).Assembly ); //Act context.Database.EnsureCreated(); //Assert var entityTypes = context.Model.GetEntityTypes().ToList(); entityTypes[0].Name.Should().Be(typeof(BillOfMaterials).FullName); entityTypes[1].Name.Should().Be(typeof(Culture).FullName); entityTypes[2].Name.Should().Be(typeof(Document).FullName); entityTypes[3].Name.Should().Be(typeof(Illustration).FullName); entityTypes[4].Name.Should().Be(typeof(Location).FullName); entityTypes[5].Name.Should().Be(typeof(Core.Entities.Product).FullName); entityTypes[6].Name.Should().Be(typeof(ProductCategory).FullName); entityTypes[7].Name.Should().Be(typeof(ProductCostHistory).FullName); entityTypes[8].Name.Should().Be(typeof(ProductDescription).FullName); entityTypes[9].Name.Should().Be(typeof(ProductDocument).FullName); entityTypes[10].Name.Should().Be(typeof(ProductInventory).FullName); entityTypes[11].Name.Should().Be(typeof(ProductListPriceHistory).FullName); entityTypes[12].Name.Should().Be(typeof(ProductModel).FullName); entityTypes[13].Name.Should().Be(typeof(ProductModelIllustration).FullName); entityTypes[14].Name.Should().Be(typeof(ProductModelProductDescriptionCulture).FullName); entityTypes[15].Name.Should().Be(typeof(ProductPhoto).FullName); entityTypes[16].Name.Should().Be(typeof(ProductProductPhoto).FullName); entityTypes[17].Name.Should().Be(typeof(ProductSubcategory).FullName); entityTypes[18].Name.Should().Be(typeof(UnitMeasure).FullName); }
public void CreateDatabase_ModelConfigurationsAreApplied( Mock <IMediator> mockMediator ) { //Arrange var contextOptions = new DbContextOptionsBuilder <AWContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new AWContext( contextOptions, mockMediator.Object, typeof(SalesOrderConfiguration).Assembly ); //Act context.Database.EnsureCreated(); //Assert var entityTypes = context.Model.GetEntityTypes().ToList(); entityTypes[0].Name.Should().Be(typeof(IntegrationEventLogEntry).FullName); entityTypes[1].Name.Should().Be(typeof(CreditCard).FullName); entityTypes[2].Name.Should().Be(typeof(Customer).FullName); entityTypes[3].Name.Should().Be(typeof(IndividualCustomer).FullName); entityTypes[4].Name.Should().Be(typeof(Person).FullName); entityTypes[5].Name.Should().Be(typeof(SalesOrder).FullName); entityTypes[6].Name.Should().Be($"{typeof(SalesOrder).FullName}.BillToAddress#Address"); entityTypes[7].Name.Should().Be($"{typeof(SalesOrder).FullName}.ShipToAddress#Address"); entityTypes[8].Name.Should().Be(typeof(SalesOrderLine).FullName); entityTypes[9].Name.Should().Be(typeof(SalesOrderSalesReason).FullName); entityTypes[10].Name.Should().Be(typeof(SalesPerson).FullName); entityTypes[11].Name.Should().Be(typeof(SalesPersonEmailAddress).FullName); entityTypes[12].Name.Should().Be(typeof(SalesPersonPhone).FullName); entityTypes[13].Name.Should().Be(typeof(SalesReason).FullName); entityTypes[14].Name.Should().Be(typeof(SpecialOffer).FullName); entityTypes[15].Name.Should().Be(typeof(SpecialOfferProduct).FullName); entityTypes[16].Name.Should().Be(typeof(StoreCustomer).FullName); }
public List <OrderDetail> GetCustomerOrder(int employeeID) { using (AWContext context = new AWContext()) { var result = ( from p in context.PurchaseOrderHeader join be in context.BusinessEntity on p.BusinessEntityID equals be.BusinessEntityID join bea in context.BusinessEntityAddress on be.BusinessEntityID equals bea.BusinessEntityID join a in context.Address on bea.AddressID equals a.AddressID where p.EmployeeID == employeeID && p.Status == 2 select new OrderDetail { PurchaseID = p.PurchaseOrderID, City = a.City, AddressLine = a.AddressLine1, SubTotal = p.SubTotal, TotalDue = p.TotalDue, CustomerID = p.BusinessEntityID } ); return(result.ToList()); } }
public IEnumerable <ProductCatalog> GetList() { using (var context = new AWContext()) { var productCatalog = context.Database.SqlQuery <ProductCatalog>( @"select pr.ProductID as ID, pr.Name, pr.Color, prd.Description, temp.Quantity, prsc.Name as SubCategory, prph.ProductPhotoID as PhotoID, pr.ListPrice as Price from Production.Product as pr inner join Production.ProductModel as prm on prm.ProductModelID = pr.ProductModelID inner join Production.ProductModelProductDescriptionCulture as prmprd on prmprd.ProductModelID = prm.ProductModelID inner join Production.ProductDescription as prd on prd.ProductDescriptionID = prmprd.ProductDescriptionID inner join Production.ProductSubcategory as prsc on pr.ProductSubcategoryID = prsc.ProductSubcategoryID inner join Production.ProductCategory as prc on prsc.ProductCategoryID = prc.ProductCategoryID inner join Production.ProductProductPhoto as prph on pr.ProductID = prph.ProductID inner join ( SELECT ProductID, quantity, roworder from ( select ProductID, quantity, row_number() over(partition by ProductID order by quantity desc) as roworder from [AdventureWorks2019].[Production].[ProductInventory] ) innerTemp ) temp on temp.ProductID = pr.ProductID where prmprd.CultureID like ('%en%') and temp.Quantity > 0 and roworder = 1;").ToList(); return(productCatalog); } }
public AWUnitOfWork(AWContext context) { _context = context; Address = new AddressRepository(context); BusinessEntity = new BusinessEntityRepository(context); BusinessEntityAddress = new BusinessEntityAddressRepository(context); PersonPhone = new PersonPhoneRepository(context); StateProvince = new StateProvinceRepository(context); Customer = new CustomerRepository(context); SalesPerson = new SalesPersonRepository(context); SalesOrderHeader = new SalesOrderHeaderRepository(context); SalesOrderDetail = new SalesOrderDetailRepository(context); ShoppingCartItem = new ShoppingCartItemRepository(context); SalesTerritory = new SalesTerritoryRepository(context); Product = new ProductRepository(context); ProductCategory = new ProductCategoryRepository(context); ProductDescription = new ProductDescriptionRepository(context); ProductInventory = new ProductInventoryRepository(context); ProductListPriceHistory = new ProductListPriceHistoryRepository(context); ProductPhoto = new ProductPhotoRepository(context); ProductProductPhoto = new ProductProductPhotoRepository(context); Person = new PersonRepository(context); }
private int InsertPurchaseOrderHeader(ShopCartItem cart, int businessEntityID, string country) { decimal totalPrice = 0; PurchaseOrderDetail orderDetails = new PurchaseOrderDetail(); var orderHeader = new PurchaseOrderHeader() { RevisionNumber = 1, Status = 1, ShipMethodID = 1, OrderDate = DateTime.Now, ModifiedDate = DateTime.Now, BusinessEntityID = businessEntityID }; foreach (var items in cart.Lines) { decimal subtotal = items.Product.ListPrice * items.Quantity; totalPrice += subtotal; orderDetails = new PurchaseOrderDetail { DueDate = DateTime.Now.AddDays(3), OrderQty = (short)items.Quantity, ProductID = items.Product.ProductID, UnitPrice = items.Product.ListPrice, LineTotal = subtotal, ReceivedQty = items.Quantity, RejectedQty = 0, StockedQty = items.Quantity, ModifiedDate = DateTime.Now }; orderHeader.PurchaseOrderDetails.Add(orderDetails); } orderHeader.SubTotal = totalPrice; orderHeader.TaxAmt = GetTaxRate(country) / 100 * totalPrice; orderHeader.Freight = ShipBaseRate() / 100 * totalPrice; orderHeader.TotalDue = totalPrice + orderHeader.Freight + orderHeader.TaxAmt; using (var context = new AWContext()) { context.PurchaseOrderHeader.Add(orderHeader); context.SaveChanges(); } return(orderHeader.PurchaseOrderID); }
public ProductCategoryRepository(AWContext context) : base(context) { }
public ProductDescriptionRepository(AWContext context) : base(context) { }
public AppUserStore(AWContext context) : base(context) { }
private void InitializeObjects() { _context = new AWContext(connection); _usuario = new DataRepository <IAWContext, Usuario>(_context); }
private void InitializeObjects() { _context = new AWContext(connection); }