diff --git a/NetCoreSample.Web.Old/Controllers/CustomerController.cs b/NetCoreSample.Web.Old/Controllers/CustomerController.cs deleted file mode 100644 index 8d5143a..0000000 --- a/NetCoreSample.Web.Old/Controllers/CustomerController.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace NetCoreSample.Web.Controllers -{ - [Produces("application/json")] - [Route("api/Customer")] - public class CustomerController : Controller - { - private readonly NorthwindSlimContext _context; - - public CustomerController(NorthwindSlimContext context) - { - _context = context; - } - - // GET: api/Customer - [HttpGet] - public async Task GetCustomers() - { - var customers = await _context.Customers - .ToListAsync(); - return Ok(customers); - } - - // GET: api/Customer/ALFKI - [HttpGet("{id}")] - public async Task GetCustomer([FromRoute] string id) - { - var customer = await _context.Customers.SingleOrDefaultAsync(m => m.CustomerId == id); - - if (customer == null) - { - return NotFound(); - } - - return Ok(customer); - } - } -} \ No newline at end of file diff --git a/NetCoreSample.Web.Old/Controllers/OrderController.cs b/NetCoreSample.Web.Old/Controllers/OrderController.cs deleted file mode 100644 index 4440ce8..0000000 --- a/NetCoreSample.Web.Old/Controllers/OrderController.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using NetCoreSample.Entities; -using TrackableEntities.Common.Core; -using TrackableEntities.EF.Core; - -namespace NetCoreSample.Web.Controllers -{ - [Produces("application/json")] - [Route("api/Order")] - public class OrderController : Controller - { - private readonly NorthwindSlimContext _context; - - public OrderController(NorthwindSlimContext context) - { - _context = context; - } - - // GET: api/Order - [HttpGet] - public async Task GetOrders() - { - var orders = await _context.Orders - .Include(m => m.Customer) - .Include(m => m.OrderDetails) - .ThenInclude(m => m.Product) - .ToListAsync(); - return Ok(orders); - } - - // GET: api/Order/ALFKI - [HttpGet("{customerId:alpha}")] - public async Task GetOrders([FromRoute] string customerId) - { - var orders = await _context.Orders - .Include(m => m.Customer) - .Include(m => m.OrderDetails) - .ThenInclude(m => m.Product) - .Where(m => m.CustomerId == customerId) - .ToListAsync(); - return Ok(orders); - } - - // GET: api/Order/5 - [HttpGet("{id}")] - public async Task GetOrder([FromRoute] int id) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var order = await _context.Orders - .Include(m => m.Customer) - .Include(m => m.OrderDetails) - .ThenInclude(m => m.Product) - .SingleOrDefaultAsync(m => m.OrderId == id); - - if (order == null) - { - return NotFound(); - } - - return Ok(order); - } - - // PUT: api/Order - [HttpPut] - public async Task PutOrder([FromBody] Order order) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - // Apply changes to context - _context.ApplyChanges(order); - - try - { - // Persist changes - await _context.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!_context.Orders.Any(o => o.OrderId == order.OrderId)) - { - return NotFound(); - } - throw; - } - - // Populate reference properties - await _context.LoadRelatedEntitiesAsync(order); - - // Reset tracking state to unchanged - _context.AcceptChanges(order); - - //return NoContent(); - return Ok(order); - } - - // POST: api/Order - [HttpPost] - public async Task PostOrder([FromBody] Order order) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - // Set state to added - order.TrackingState = TrackingState.Added; - - // Apply changes to context - _context.ApplyChanges(order); - - // Persist changes - await _context.SaveChangesAsync(); - - // Populate reference properties - await _context.LoadRelatedEntitiesAsync(order); - - // Reset tracking state to unchanged - _context.AcceptChanges(order); - - return CreatedAtAction("GetOrder", new { id = order.OrderId }, order); - } - - // DELETE: api/Order/5 - [HttpDelete("{id}")] - public async Task DeleteOrder([FromRoute] int id) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - // Retrieve order with details - var order = await _context.Orders - .Include(m => m.OrderDetails) - .SingleOrDefaultAsync(m => m.OrderId == id); - if (order == null) - { - return NotFound(); - } - - // Set tracking state to deleted - order.TrackingState = TrackingState.Deleted; - - // Detach object graph - _context.DetachEntities(order); - - // Apply changes to context - _context.ApplyChanges(order); - - // Persist changes - await _context.SaveChangesAsync(); - - return Ok(); - } - } -} \ No newline at end of file diff --git a/NetCoreSample.Web.Old/Controllers/ValuesController.cs b/NetCoreSample.Web.Old/Controllers/ValuesController.cs deleted file mode 100644 index 6dac388..0000000 --- a/NetCoreSample.Web.Old/Controllers/ValuesController.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; - -namespace NetCoreSample.Web.Controllers -{ - [Route("api/[controller]")] - public class ValuesController : Controller - { - // GET api/values - [HttpGet] - public IEnumerable Get() - { - return new string[] { "value1", "value2" }; - } - - // GET api/values/5 - [HttpGet("{id}")] - public string Get(int id) - { - return "value"; - } - - // POST api/values - [HttpPost] - public void Post([FromBody]string value) - { - } - - // PUT api/values/5 - [HttpPut("{id}")] - public void Put(int id, [FromBody]string value) - { - } - - // DELETE api/values/5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} diff --git a/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.Designer.cs b/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.Designer.cs deleted file mode 100644 index 4321eb4..0000000 --- a/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.Designer.cs +++ /dev/null @@ -1,190 +0,0 @@ -// -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Storage.Internal; -using NetCoreSample.Web; -using System; - -namespace NetCoreSample.Web.Migrations -{ - [DbContext(typeof(NorthwindSlimContext))] - [Migration("20170925034612_Initial")] - partial class Initial - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("NetCoreSample.Entities.Category", b => - { - b.Property("CategoryId") - .ValueGeneratedOnAdd(); - - b.Property("CategoryName") - .IsRequired() - .HasMaxLength(15); - - b.HasKey("CategoryId"); - - b.ToTable("Category"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Customer", b => - { - b.Property("CustomerId") - .ValueGeneratedOnAdd() - .HasMaxLength(5); - - b.Property("City") - .HasMaxLength(15); - - b.Property("CompanyName") - .IsRequired() - .HasMaxLength(40); - - b.Property("ContactName") - .HasMaxLength(30); - - b.Property("Country") - .HasMaxLength(15); - - b.HasKey("CustomerId"); - - b.ToTable("Customer"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.CustomerSetting", b => - { - b.Property("CustomerId") - .HasMaxLength(5); - - b.Property("Setting") - .IsRequired() - .HasMaxLength(50); - - b.HasKey("CustomerId"); - - b.ToTable("CustomerSetting"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Order", b => - { - b.Property("OrderId") - .ValueGeneratedOnAdd(); - - b.Property("CustomerId") - .HasMaxLength(5); - - b.Property("Freight") - .HasColumnType("money"); - - b.Property("OrderDate"); - - b.Property("ShipVia"); - - b.Property("ShippedDate"); - - b.HasKey("OrderId"); - - b.HasIndex("CustomerId"); - - b.ToTable("Order"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.OrderDetail", b => - { - b.Property("OrderDetailId") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("Quantity"); - - b.Property("UnitPrice") - .HasColumnType("money"); - - b.HasKey("OrderDetailId"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.ToTable("OrderDetail"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Product", b => - { - b.Property("ProductId") - .ValueGeneratedOnAdd(); - - b.Property("CategoryId"); - - b.Property("Discontinued"); - - b.Property("ProductName") - .IsRequired() - .HasMaxLength(40); - - b.Property("RowVersion") - .ValueGeneratedOnAddOrUpdate() - .HasColumnType("timestamp") - .HasMaxLength(8); - - b.Property("UnitPrice") - .HasColumnType("money"); - - b.HasKey("ProductId"); - - b.HasIndex("CategoryId"); - - b.ToTable("Product"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.CustomerSetting", b => - { - b.HasOne("NetCoreSample.Entities.Customer", "Customer") - .WithOne("CustomerSetting") - .HasForeignKey("NetCoreSample.Entities.CustomerSetting", "CustomerId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Order", b => - { - b.HasOne("NetCoreSample.Entities.Customer", "Customer") - .WithMany("Orders") - .HasForeignKey("CustomerId"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.OrderDetail", b => - { - b.HasOne("NetCoreSample.Entities.Order", "Order") - .WithMany("OrderDetails") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("NetCoreSample.Entities.Product", "Product") - .WithMany("OrderDetails") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Product", b => - { - b.HasOne("NetCoreSample.Entities.Category", "Category") - .WithMany("Products") - .HasForeignKey("CategoryId"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.cs b/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.cs deleted file mode 100644 index cc91739..0000000 --- a/NetCoreSample.Web.Old/Migrations/20170925034612_Initial.cs +++ /dev/null @@ -1,175 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using System; -using System.Collections.Generic; - -namespace NetCoreSample.Web.Migrations -{ - public partial class Initial : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Category", - columns: table => new - { - CategoryId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - CategoryName = table.Column(type: "nvarchar(15)", maxLength: 15, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Category", x => x.CategoryId); - }); - - migrationBuilder.CreateTable( - name: "Customer", - columns: table => new - { - CustomerId = table.Column(type: "nvarchar(5)", maxLength: 5, nullable: false), - City = table.Column(type: "nvarchar(15)", maxLength: 15, nullable: true), - CompanyName = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), - ContactName = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: true), - Country = table.Column(type: "nvarchar(15)", maxLength: 15, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Customer", x => x.CustomerId); - }); - - migrationBuilder.CreateTable( - name: "Product", - columns: table => new - { - ProductId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - CategoryId = table.Column(type: "int", nullable: true), - Discontinued = table.Column(type: "bit", nullable: false), - ProductName = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), - RowVersion = table.Column(type: "timestamp", maxLength: 8, nullable: true), - UnitPrice = table.Column(type: "money", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Product", x => x.ProductId); - table.ForeignKey( - name: "FK_Product_Category_CategoryId", - column: x => x.CategoryId, - principalTable: "Category", - principalColumn: "CategoryId", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "CustomerSetting", - columns: table => new - { - CustomerId = table.Column(type: "nvarchar(5)", maxLength: 5, nullable: false), - Setting = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CustomerSetting", x => x.CustomerId); - table.ForeignKey( - name: "FK_CustomerSetting_Customer_CustomerId", - column: x => x.CustomerId, - principalTable: "Customer", - principalColumn: "CustomerId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Order", - columns: table => new - { - OrderId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - CustomerId = table.Column(type: "nvarchar(5)", maxLength: 5, nullable: true), - Freight = table.Column(type: "money", nullable: true), - OrderDate = table.Column(type: "datetime2", nullable: true), - ShipVia = table.Column(type: "int", nullable: true), - ShippedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Order", x => x.OrderId); - table.ForeignKey( - name: "FK_Order_Customer_CustomerId", - column: x => x.CustomerId, - principalTable: "Customer", - principalColumn: "CustomerId", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "OrderDetail", - columns: table => new - { - OrderDetailId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - Discount = table.Column(type: "real", nullable: false), - OrderId = table.Column(type: "int", nullable: false), - ProductId = table.Column(type: "int", nullable: false), - Quantity = table.Column(type: "smallint", nullable: false), - UnitPrice = table.Column(type: "money", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderDetail", x => x.OrderDetailId); - table.ForeignKey( - name: "FK_OrderDetail_Order_OrderId", - column: x => x.OrderId, - principalTable: "Order", - principalColumn: "OrderId", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderDetail_Product_ProductId", - column: x => x.ProductId, - principalTable: "Product", - principalColumn: "ProductId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Order_CustomerId", - table: "Order", - column: "CustomerId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderDetail_OrderId", - table: "OrderDetail", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderDetail_ProductId", - table: "OrderDetail", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_Product_CategoryId", - table: "Product", - column: "CategoryId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CustomerSetting"); - - migrationBuilder.DropTable( - name: "OrderDetail"); - - migrationBuilder.DropTable( - name: "Order"); - - migrationBuilder.DropTable( - name: "Product"); - - migrationBuilder.DropTable( - name: "Customer"); - - migrationBuilder.DropTable( - name: "Category"); - } - } -} diff --git a/NetCoreSample.Web.Old/Migrations/NorthwindSlimContextModelSnapshot.cs b/NetCoreSample.Web.Old/Migrations/NorthwindSlimContextModelSnapshot.cs deleted file mode 100644 index 741543c..0000000 --- a/NetCoreSample.Web.Old/Migrations/NorthwindSlimContextModelSnapshot.cs +++ /dev/null @@ -1,189 +0,0 @@ -// -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Storage.Internal; -using NetCoreSample.Web; -using System; - -namespace NetCoreSample.Web.Migrations -{ - [DbContext(typeof(NorthwindSlimContext))] - partial class NorthwindSlimContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("NetCoreSample.Entities.Category", b => - { - b.Property("CategoryId") - .ValueGeneratedOnAdd(); - - b.Property("CategoryName") - .IsRequired() - .HasMaxLength(15); - - b.HasKey("CategoryId"); - - b.ToTable("Category"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Customer", b => - { - b.Property("CustomerId") - .ValueGeneratedOnAdd() - .HasMaxLength(5); - - b.Property("City") - .HasMaxLength(15); - - b.Property("CompanyName") - .IsRequired() - .HasMaxLength(40); - - b.Property("ContactName") - .HasMaxLength(30); - - b.Property("Country") - .HasMaxLength(15); - - b.HasKey("CustomerId"); - - b.ToTable("Customer"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.CustomerSetting", b => - { - b.Property("CustomerId") - .HasMaxLength(5); - - b.Property("Setting") - .IsRequired() - .HasMaxLength(50); - - b.HasKey("CustomerId"); - - b.ToTable("CustomerSetting"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Order", b => - { - b.Property("OrderId") - .ValueGeneratedOnAdd(); - - b.Property("CustomerId") - .HasMaxLength(5); - - b.Property("Freight") - .HasColumnType("money"); - - b.Property("OrderDate"); - - b.Property("ShipVia"); - - b.Property("ShippedDate"); - - b.HasKey("OrderId"); - - b.HasIndex("CustomerId"); - - b.ToTable("Order"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.OrderDetail", b => - { - b.Property("OrderDetailId") - .ValueGeneratedOnAdd(); - - b.Property("Discount"); - - b.Property("OrderId"); - - b.Property("ProductId"); - - b.Property("Quantity"); - - b.Property("UnitPrice") - .HasColumnType("money"); - - b.HasKey("OrderDetailId"); - - b.HasIndex("OrderId"); - - b.HasIndex("ProductId"); - - b.ToTable("OrderDetail"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Product", b => - { - b.Property("ProductId") - .ValueGeneratedOnAdd(); - - b.Property("CategoryId"); - - b.Property("Discontinued"); - - b.Property("ProductName") - .IsRequired() - .HasMaxLength(40); - - b.Property("RowVersion") - .ValueGeneratedOnAddOrUpdate() - .HasColumnType("timestamp") - .HasMaxLength(8); - - b.Property("UnitPrice") - .HasColumnType("money"); - - b.HasKey("ProductId"); - - b.HasIndex("CategoryId"); - - b.ToTable("Product"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.CustomerSetting", b => - { - b.HasOne("NetCoreSample.Entities.Customer", "Customer") - .WithOne("CustomerSetting") - .HasForeignKey("NetCoreSample.Entities.CustomerSetting", "CustomerId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Order", b => - { - b.HasOne("NetCoreSample.Entities.Customer", "Customer") - .WithMany("Orders") - .HasForeignKey("CustomerId"); - }); - - modelBuilder.Entity("NetCoreSample.Entities.OrderDetail", b => - { - b.HasOne("NetCoreSample.Entities.Order", "Order") - .WithMany("OrderDetails") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("NetCoreSample.Entities.Product", "Product") - .WithMany("OrderDetails") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("NetCoreSample.Entities.Product", b => - { - b.HasOne("NetCoreSample.Entities.Category", "Category") - .WithMany("Products") - .HasForeignKey("CategoryId"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/NetCoreSample.Web.Old/NetCoreSample.Web.Old.csproj b/NetCoreSample.Web.Old/NetCoreSample.Web.Old.csproj deleted file mode 100644 index 08b7cf9..0000000 --- a/NetCoreSample.Web.Old/NetCoreSample.Web.Old.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - netcoreapp2.2 - - - - - - - - - - - - - - - - - - diff --git a/NetCoreSample.Web.Old/NorthwindSlimContext.cs b/NetCoreSample.Web.Old/NorthwindSlimContext.cs deleted file mode 100644 index 558fafc..0000000 --- a/NetCoreSample.Web.Old/NorthwindSlimContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using NetCoreSample.Entities; - -namespace NetCoreSample.Web -{ - public class NorthwindSlimContext : DbContext - { - public NorthwindSlimContext(DbContextOptions options) : base(options) { } - - public DbSet Categories { get; set; } - public DbSet Customers { get; set; } - public DbSet Orders { get; set; } - public DbSet OrderDetails { get; set; } - public DbSet Products { get; set; } - } -} \ No newline at end of file diff --git a/NetCoreSample.Web.Old/NorthwindSlimContextExtensions.cs b/NetCoreSample.Web.Old/NorthwindSlimContextExtensions.cs deleted file mode 100644 index 9417247..0000000 --- a/NetCoreSample.Web.Old/NorthwindSlimContextExtensions.cs +++ /dev/null @@ -1,235 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Transactions; -using Microsoft.EntityFrameworkCore; -using NetCoreSample.Entities; - -namespace NetCoreSample.Web -{ - public static class NorthwindSlimContextExtensions - { - public static void EnsureSeedData(this NorthwindSlimContext context) - { - context.Database.OpenConnection(); - try - { - if (!context.Categories.Any()) - { - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Category] ON"); - AddCategories(context); - context.SaveChanges(); - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Category] OFF"); - } - - if (!context.Products.Any()) - { - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Product] ON"); - AddProducts(context); - context.SaveChanges(); - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Product] OFF"); - } - - if (!context.Customers.Any()) - { - AddCustomers(context); - context.SaveChanges(); - } - - if (!context.Orders.Any()) - { - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Order] ON"); - AddOrders(context); - context.SaveChanges(); - context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.[Order] OFF"); - } - } - finally - { - context.Database.CloseConnection(); - } - } - - private static void AddOrders(NorthwindSlimContext context) - { - context.Orders.Add(new Order - { - CustomerId = "ALFKI", - OrderId = 1, - OrderDate = DateTime.Today, - ShippedDate = DateTime.Today, - Freight = 41.34M, - OrderDetails = new List - { - new OrderDetail - { - ProductId = 1, - Quantity = 1, - UnitPrice = 10M - }, - new OrderDetail - { - ProductId = 2, - Quantity = 2, - UnitPrice = 20M - }, - } - }); - context.Orders.Add(new Order - { - CustomerId = "ALFKI", - OrderId = 2, - OrderDate = DateTime.Today, - ShippedDate = DateTime.Today, - Freight = 41.34M, - OrderDetails = new List - { - new OrderDetail - { - ProductId = 3, - Quantity = 3, - UnitPrice = 30M - }, - } - }); - context.Orders.Add(new Order - { - CustomerId = "ANATR", - OrderId = 3, - OrderDate = DateTime.Today, - ShippedDate = DateTime.Today, - Freight = 41.34M, - OrderDetails = new List - { - new OrderDetail - { - ProductId = 2, - Quantity = 4, - UnitPrice = 20M - }, - } - }); - context.Orders.Add(new Order - { - CustomerId = "ANTON", - OrderId = 4, - OrderDate = DateTime.Today, - ShippedDate = DateTime.Today, - Freight = 41.34M, - OrderDetails = new List - { - new OrderDetail - { - ProductId = 3, - Quantity = 5, - UnitPrice = 30M - }, - } - }); - } - - private static void AddCustomers(NorthwindSlimContext context) - { - context.Customers.Add(new Customer - { - CustomerId = "ALFKI", - CompanyName = "Alfreds Futterkiste", - ContactName = "Maria Anders", - City = "Berlin", - Country = "Germany" - }); - context.Customers.Add(new Customer - { - CustomerId = "ANATR", - CompanyName = "Ana Trujillo Emparedados y helados", - ContactName = "Ana Trujillo", - City = "México D.F.", - Country = "Mexico" - }); - context.Customers.Add(new Customer - { - CustomerId = "ANTON", - CompanyName = "Antonio Moreno Taquería", - ContactName = "Antonio Moreno", - City = "México D.F.", - Country = "Mexico" - }); - } - - private static void AddProducts(NorthwindSlimContext context) - { - context.Products.Add(new Product - { - ProductId = 1, - CategoryId = 1, - ProductName = "Chai", - UnitPrice = 23M - }); - context.Products.Add(new Product - { - ProductId = 2, - CategoryId = 1, - ProductName = "Chang", - UnitPrice = 23M - }); - context.Products.Add(new Product - { - ProductId = 3, - CategoryId = 2, - ProductName = "Aniseed Syrup", - UnitPrice = 23M - }); - context.Products.Add(new Product - { - ProductId = 4, - CategoryId = 2, - ProductName = "Chef Anton's Cajun Seasoning", - UnitPrice = 23M - }); - } - - private static void AddCategories(NorthwindSlimContext context) - { - context.Categories.Add(new Category - { - CategoryId = 1, - CategoryName = "Beverages" - }); - context.Categories.Add(new Category - { - CategoryId = 2, - CategoryName = "Condiments" - }); - context.Categories.Add(new Category - { - CategoryId = 3, - CategoryName = "Confections" - }); - context.Categories.Add(new Category - { - CategoryId = 4, - CategoryName = "Dairy Products" - }); - context.Categories.Add(new Category - { - CategoryId = 5, - CategoryName = "Grains/Cereals" - }); - context.Categories.Add(new Category - { - CategoryId = 6, - CategoryName = "Meat/Poultry" - }); - context.Categories.Add(new Category - { - CategoryId = 7, - CategoryName = "Produce" - }); - context.Categories.Add(new Category - { - CategoryId = 8, - CategoryName = "Seafood" - }); - } - } -} \ No newline at end of file diff --git a/NetCoreSample.Web.Old/NorthwindSlimContextFactory.cs b/NetCoreSample.Web.Old/NorthwindSlimContextFactory.cs deleted file mode 100644 index 45ce18b..0000000 --- a/NetCoreSample.Web.Old/NorthwindSlimContextFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; - -namespace NetCoreSample.Web -{ - public class NorthwindSlimContextFactory : IDesignTimeDbContextFactory - { - public NorthwindSlimContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseSqlServer( - "Data Source=(localdb)\\MSSQLLocalDB;initial catalog=NetCoreSample;Integrated Security=True; MultipleActiveResultSets=True"); - return new NorthwindSlimContext(optionsBuilder.Options); - } - } -} \ No newline at end of file diff --git a/NetCoreSample.Web.Old/Program.cs b/NetCoreSample.Web.Old/Program.cs deleted file mode 100644 index 8b56e08..0000000 --- a/NetCoreSample.Web.Old/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; - -namespace NetCoreSample.Web -{ - public class Program - { - public static void Main(string[] args) - { - BuildWebHost(args).Run(); - } - - public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .Build(); - } -} diff --git a/NetCoreSample.Web.Old/Properties/launchSettings.json b/NetCoreSample.Web.Old/Properties/launchSettings.json deleted file mode 100644 index b660b61..0000000 --- a/NetCoreSample.Web.Old/Properties/launchSettings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:64139/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "api/values", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "NetCoreSample.Web": { - "commandName": "Project", - "launchBrowser": true, - "launchUrl": "api/values", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "http://localhost:64140/" - } - } -} diff --git a/NetCoreSample.Web.Old/Startup.cs b/NetCoreSample.Web.Old/Startup.cs deleted file mode 100644 index 12e02a7..0000000 --- a/NetCoreSample.Web.Old/Startup.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; - -namespace NetCoreSample.Web -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc() - .AddJsonOptions(options => - options.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.All); - var connectionString = Configuration.GetConnectionString("NetCoreSample"); - services.AddDbContext(options => options.UseSqlServer(connectionString)); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, NorthwindSlimContext context) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - context.EnsureSeedData(); - } - - app.UseMvc(); - } - } -} diff --git a/NetCoreSample.Web.Old/appsettings.Development.json b/NetCoreSample.Web.Old/appsettings.Development.json deleted file mode 100644 index fa8ce71..0000000 --- a/NetCoreSample.Web.Old/appsettings.Development.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - } -} diff --git a/NetCoreSample.Web.Old/appsettings.json b/NetCoreSample.Web.Old/appsettings.json deleted file mode 100644 index e46138b..0000000 --- a/NetCoreSample.Web.Old/appsettings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "Debug": { - "LogLevel": { - "Default": "Warning" - } - }, - "Console": { - "LogLevel": { - "Default": "Warning" - } - } - }, - "ConnectionStrings": { - "NetCoreSample": "Data Source=(localdb)\\MSSQLLocalDB;initial catalog=NetCoreSample;Integrated Security=True; MultipleActiveResultSets=True" - } -}