Skip to content

Commit

Permalink
Extend the domain and add photo.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosh-hamedani committed Apr 26, 2017
1 parent 0fb9edc commit a0d7017
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 12 deletions.
13 changes: 13 additions & 0 deletions Core/Models/Photo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;

namespace vega.Core.Models
{
public class Photo
{
public int Id { get; set; }

[Required]
[StringLength(255)]
public string FileName { get; set; }
}
}
2 changes: 2 additions & 0 deletions Core/Models/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class Vehicle
public string ContactPhone { get; set; }
public DateTime LastUpdate { get; set; }
public ICollection<VehicleFeature> Features { get; set; }
public ICollection<Photo> Photos { get; set; }

public Vehicle()
{
Features = new Collection<VehicleFeature>();
Photos = new Collection<Photo>();
}
}
}
163 changes: 163 additions & 0 deletions Migrations/20170412005215_AddPhoto.Designer.cs

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

44 changes: 44 additions & 0 deletions Migrations/20170412005215_AddPhoto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Vega.Migrations
{
public partial class AddPhoto : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Photos",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
FileName = table.Column<string>(maxLength: 255, nullable: false),
VehicleId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_Vehicles_VehicleId",
column: x => x.VehicleId,
principalTable: "Vehicles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateIndex(
name: "IX_Photos_VehicleId",
table: "Photos",
column: "VehicleId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Photos");
}
}
}
49 changes: 37 additions & 12 deletions Migrations/VegaDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("vega.Models.Feature", b =>
modelBuilder.Entity("vega.Core.Models.Feature", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
Expand All @@ -30,7 +30,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Features");
});

modelBuilder.Entity("vega.Models.Make", b =>
modelBuilder.Entity("vega.Core.Models.Make", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
Expand All @@ -44,7 +44,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Makes");
});

modelBuilder.Entity("vega.Models.Model", b =>
modelBuilder.Entity("vega.Core.Models.Model", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
Expand All @@ -62,7 +62,25 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Models");
});

modelBuilder.Entity("vega.Models.Vehicle", b =>
modelBuilder.Entity("vega.Core.Models.Photo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<string>("FileName")
.IsRequired()
.HasMaxLength(255);

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

b.HasKey("Id");

b.HasIndex("VehicleId");

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

modelBuilder.Entity("vega.Core.Models.Vehicle", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
Expand Down Expand Up @@ -91,7 +109,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Vehicles");
});

modelBuilder.Entity("vega.Models.VehicleFeature", b =>
modelBuilder.Entity("vega.Core.Models.VehicleFeature", b =>
{
b.Property<int>("VehicleId");

Expand All @@ -104,30 +122,37 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("VehicleFeatures");
});

modelBuilder.Entity("vega.Models.Model", b =>
modelBuilder.Entity("vega.Core.Models.Model", b =>
{
b.HasOne("vega.Models.Make", "Make")
b.HasOne("vega.Core.Models.Make", "Make")
.WithMany("Models")
.HasForeignKey("MakeId")
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity("vega.Models.Vehicle", b =>
modelBuilder.Entity("vega.Core.Models.Photo", b =>
{
b.HasOne("vega.Core.Models.Vehicle")
.WithMany("Photos")
.HasForeignKey("VehicleId");
});

modelBuilder.Entity("vega.Core.Models.Vehicle", b =>
{
b.HasOne("vega.Models.Model", "Model")
b.HasOne("vega.Core.Models.Model", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity("vega.Models.VehicleFeature", b =>
modelBuilder.Entity("vega.Core.Models.VehicleFeature", b =>
{
b.HasOne("vega.Models.Feature", "Feature")
b.HasOne("vega.Core.Models.Feature", "Feature")
.WithMany()
.HasForeignKey("FeatureId")
.OnDelete(DeleteBehavior.Cascade);

b.HasOne("vega.Models.Vehicle", "Vehicle")
b.HasOne("vega.Core.Models.Vehicle", "Vehicle")
.WithMany("Features")
.HasForeignKey("VehicleId")
.OnDelete(DeleteBehavior.Cascade);
Expand Down
1 change: 1 addition & 0 deletions Persistence/VegaDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class VegaDbContext : DbContext
public DbSet<Make> Makes { get; set; }
public DbSet<Model> Models { get; set; }
public DbSet<Feature> Features { get; set; }
public DbSet<Photo> Photos { get; set; }

public VegaDbContext(DbContextOptions<VegaDbContext> options)
: base(options)
Expand Down

0 comments on commit a0d7017

Please sign in to comment.