Skip to content

Commit

Permalink
add models and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Caitlin Hines and Tammy Dang committed May 3, 2017
1 parent cfeb68c commit 9032243
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/Shoes/Migrations/20170503172321_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions src/Shoes/Migrations/20170503172321_Initial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Shoes.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Inventories",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Revenue = table.Column<int>(nullable: false),
Stock = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Inventories", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Sales",
columns: table => new
{
SaleId = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Comment = table.Column<string>(nullable: true),
Image = table.Column<string>(nullable: true),
InventoryId = table.Column<int>(nullable: true),
Price = table.Column<int>(nullable: false),
ShoeName = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Sales", x => x.SaleId);
table.ForeignKey(
name: "FK_Sales_Inventories_InventoryId",
column: x => x.InventoryId,
principalTable: "Inventories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateIndex(
name: "IX_Sales_InventoryId",
table: "Sales",
column: "InventoryId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Sales");

migrationBuilder.DropTable(
name: "Inventories");
}
}
}
63 changes: 63 additions & 0 deletions src/Shoes/Migrations/ShoesDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Shoes.Models;

namespace Shoes.Migrations
{
[DbContext(typeof(ShoesDbContext))]
partial class ShoesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("Shoes.Models.Inventory", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<int>("Revenue");

b.Property<int>("Stock");

b.HasKey("Id");

b.ToTable("Inventories");
});

modelBuilder.Entity("Shoes.Models.Sale", b =>
{
b.Property<int>("SaleId")
.ValueGeneratedOnAdd();

b.Property<string>("Comment");

b.Property<string>("Image");

b.Property<int?>("InventoryId");

b.Property<int>("Price");

b.Property<string>("ShoeName");

b.HasKey("SaleId");

b.HasIndex("InventoryId");

b.ToTable("Sales");
});

modelBuilder.Entity("Shoes.Models.Sale", b =>
{
b.HasOne("Shoes.Models.Inventory", "Inventory")
.WithMany("Sales")
.HasForeignKey("InventoryId");
});
}
}
}
18 changes: 18 additions & 0 deletions src/Shoes/Models/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Shoes.Models
{
public class Inventory
{
[Key]
public int Id { get; set; }
public int Stock { get; set; }
public int Revenue { get; set; }
public virtual ICollection<Sale> Sales { get; set; }
}
}
19 changes: 19 additions & 0 deletions src/Shoes/Models/Sale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;

namespace Shoes.Models
{
public class Sale
{
[Key]
public int SaleId { get; set; }
public string ShoeName { get; set; }
public int Price { get; set; }
public string Image { get; set; }
public string Comment { get; set; }
public virtual Inventory Inventory { get; set; }
}
}
33 changes: 33 additions & 0 deletions src/Shoes/Models/ShoesDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Shoes.Models
{
public class ShoesDbContext : DbContext
{
public ShoesDbContext()
{

}

public DbSet<Inventory> Inventories { get; set; }
public DbSet<Sale> Sales { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Shoes;integrated security=True");
}

public ShoesDbContext(DbContextOptions<ShoesDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
}
}
13 changes: 13 additions & 0 deletions src/Shoes/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Shoes.Models;

namespace Shoes
{
public class Startup
{
public IConfigurationRoot Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json");
Configuration = builder.Build();

}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFramework()
.AddDbContext<ShoesDbContext>(options =>
options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
}

public void Configure(IApplicationBuilder app)
Expand Down
5 changes: 5 additions & 0 deletions src/Shoes/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=Shoes;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Binary file not shown.
Binary file modified src/Shoes/bin/Debug/netcoreapp1.0/Shoes.dll
Binary file not shown.
Binary file modified src/Shoes/bin/Debug/netcoreapp1.0/Shoes.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Shoes/obj/Debug/netcoreapp1.0/.IncrementalCache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"inputs":["C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\project.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\project.lock.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Program.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Startup.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Controllers\\HomeController.cs"],"outputs":["C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.dll","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.pdb","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.deps.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.runtimeconfig.json"],"buildArguments":{"version-suffix":null}}
{"inputs":["C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\project.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\project.lock.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Program.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Startup.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Controllers\\HomeController.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Migrations\\20170503172321_Initial.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Migrations\\20170503172321_Initial.Designer.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Migrations\\ShoesDbContextModelSnapshot.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Models\\Inventory.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Models\\Sale.cs","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\Models\\ShoesDbContext.cs"],"outputs":["C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.dll","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.pdb","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.deps.json","C:\\Users\\epicodus\\Desktop\\Shoes\\src\\Shoes\\bin\\Debug\\netcoreapp1.0\\Shoes.runtimeconfig.json"],"buildArguments":{"version-suffix":null}}
6 changes: 6 additions & 0 deletions src/Shoes/obj/Debug/netcoreapp1.0/dotnet-compile-csc.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Program.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Startup.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Controllers\HomeController.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\20170503172321_Initial.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\20170503172321_Initial.Designer.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\ShoesDbContextModelSnapshot.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\Inventory.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\Sale.cs"
"C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\ShoesDbContext.cs"
6 changes: 6 additions & 0 deletions src/Shoes/obj/Debug/netcoreapp1.0/dotnet-compile.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,9 @@
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Program.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Startup.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Controllers\HomeController.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\20170503172321_Initial.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\20170503172321_Initial.Designer.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Migrations\ShoesDbContextModelSnapshot.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\Inventory.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\Sale.cs
C:\Users\epicodus\Desktop\Shoes\src\Shoes\Models\ShoesDbContext.cs

0 comments on commit 9032243

Please sign in to comment.