Skip to content

Commit

Permalink
moved models to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
alimon808 committed Aug 9, 2017
1 parent 9f5de4f commit 03499d9
Show file tree
Hide file tree
Showing 38 changed files with 86 additions and 81 deletions.
19 changes: 17 additions & 2 deletions ContosoUniversity.Data/ApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace ContosoUniversity.Data
{
Expand All @@ -8,9 +9,23 @@ public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(o
{
}

public DbSet<Course> Courses { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<Instructor> Instructors { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{

modelBuilder.Entity<Course>().ToTable("Course", "Contoso");
modelBuilder.Entity<Enrollment>().ToTable("Enrollment", "Contoso");
modelBuilder.Entity<Student>().ToTable("Student", "Contoso");
modelBuilder.Entity<Department>().ToTable("Department", "Contoso");
modelBuilder.Entity<Instructor>().ToTable("Instructor", "Contoso");
modelBuilder.Entity<OfficeAssignment>().ToTable("OfficeAssignment", "Contoso");
modelBuilder.Entity<CourseAssignment>().ToTable("CourseAssignment", "Contoso");
modelBuilder.Entity<Person>().ToTable("Person", "Contoso");
modelBuilder.Entity<CourseAssignment>().HasKey(c => new { c.CourseID, c.InstructorID });
}
}
}
6 changes: 0 additions & 6 deletions ContosoUniversity.Data/ContosoUniversity.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Entities\**" />
<EmbeddedResource Remove="Entities\**" />
<None Remove="Entities\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class Course
{
Expand All @@ -18,7 +18,7 @@ public class Course

public int DepartmentID { get; set; }

public Department Department { get; set; }
public Department Department { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
public ICollection<CourseAssignment> CourseAssignments { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class CourseAssignment
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class Department
{
Expand All @@ -28,6 +28,5 @@ public class Department

public Instructor Administrator { get; set; }
public ICollection<Course> Courses { get; set; }

}
}
17 changes: 17 additions & 0 deletions ContosoUniversity.Data/Entities/Enrollment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ContosoUniversity.Data.Enums;
using System.ComponentModel.DataAnnotations;

namespace ContosoUniversity.Data.Entities
{
public class Enrollment
{
public long EnrollmentID { get; set; }
public long CourseID { get; set; }
public long StudentID { get; set; }

[DisplayFormat(NullDisplayText = "No Grade")]
public Grade? Grade { get; set; }
public Course Course { get; set; }
public Student Student { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class Instructor : Person
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class OfficeAssignment
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.ComponentModel.DataAnnotations;
using ContosoUniversity.Data;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class Person
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Entities
{
public class Student : Person
{
[Display(Name = "Enrollment Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime EnrollmentDate { get; set; }

public ICollection<Enrollment> Enrollments { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ContosoUniversity.Models
namespace ContosoUniversity.Data.Enums
{
public enum Grade
{
Expand Down
8 changes: 3 additions & 5 deletions ContosoUniversity/Controllers/CoursesController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data;
using ContosoUniversity.Models;
using ContosoUniversity.Data.Entities;

namespace ContosoUniversity.Controllers
{
public class CoursesController : Controller
{
private readonly SchoolContext _context;
private readonly ApplicationContext _context;

public CoursesController(SchoolContext context)
public CoursesController(ApplicationContext context)
{
_context = context;
}
Expand Down
4 changes: 1 addition & 3 deletions ContosoUniversity/Controllers/DepartmentsController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data;
using ContosoUniversity.Models;
using ContosoUniversity.Data.Entities;

namespace ContosoUniversity.Controllers
{
Expand Down
7 changes: 3 additions & 4 deletions ContosoUniversity/Controllers/InstructorsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data;
using ContosoUniversity.Models;
using ContosoUniversity.Models.SchoolViewModels;
using ContosoUniversity.Data.Entities;

namespace ContosoUniversity.Controllers
{
public class InstructorsController : Controller
{
private readonly SchoolContext _context;
private readonly ApplicationContext _context;

public InstructorsController(SchoolContext context)
public InstructorsController(ApplicationContext context)
{
_context = context;
}
Expand Down
1 change: 1 addition & 0 deletions ContosoUniversity/Controllers/StudentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data;
using ContosoUniversity.Models;
using ContosoUniversity.Data.Entities;

namespace ContosoUniversity.Controllers
{
Expand Down
5 changes: 2 additions & 3 deletions ContosoUniversity/Data/DbInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using ContosoUniversity.Models;
using ContosoUniversity.Data.Entities;
using ContosoUniversity.Data.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ContosoUniversity.Data
{
Expand Down
18 changes: 9 additions & 9 deletions ContosoUniversity/Data/SchoolContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ContosoUniversity.Models;
using ContosoUniversity.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace ContosoUniversity.Data
Expand All @@ -20,14 +20,14 @@ public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>().ToTable("Course");
modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
modelBuilder.Entity<Student>().ToTable("Student");
modelBuilder.Entity<Department>().ToTable("Department");
modelBuilder.Entity<Instructor>().ToTable("Instructor");
modelBuilder.Entity<OfficeAssignment>().ToTable("OfficeAssignment");
modelBuilder.Entity<CourseAssignment>().ToTable("CourseAssignment");
modelBuilder.Entity<Person>().ToTable("Person");
modelBuilder.Entity<Course>().ToTable("Course", "Contoso");
modelBuilder.Entity<Enrollment>().ToTable("Enrollment", "Contoso");
modelBuilder.Entity<Student>().ToTable("Student", "Contoso");
modelBuilder.Entity<Department>().ToTable("Department", "Contoso");
modelBuilder.Entity<Instructor>().ToTable("Instructor", "Contoso");
modelBuilder.Entity<OfficeAssignment>().ToTable("OfficeAssignment", "Contoso");
modelBuilder.Entity<CourseAssignment>().ToTable("CourseAssignment", "Contoso");
modelBuilder.Entity<Person>().ToTable("Person", "Contoso");
modelBuilder.Entity<CourseAssignment>().HasKey(c => new { c.CourseID, c.InstructorID });

}
Expand Down
16 changes: 0 additions & 16 deletions ContosoUniversity/Models/Enrollment.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using ContosoUniversity.Data.Entities;
using System.Collections.Generic;

namespace ContosoUniversity.Models.SchoolViewModels
{
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Courses/Create.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Course
@model ContosoUniversity.Data.Entities.Course

@{
ViewData["Title"] = "Create";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Courses/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Course
@model ContosoUniversity.Data.Entities.Course

@{
ViewData["Title"] = "Delete";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Courses/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Course
@model ContosoUniversity.Data.Entities.Course

@{
ViewData["Title"] = "Details";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Courses/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Course
@model ContosoUniversity.Data.Entities.Course

@{
ViewData["Title"] = "Edit";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Courses/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model IEnumerable<ContosoUniversity.Models.Course>
@model IEnumerable<ContosoUniversity.Data.Entities.Course>

@{
ViewData["Title"] = "Courses";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Departments/Create.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Department
@model ContosoUniversity.Data.Entities.Department

@{
ViewData["Title"] = "Create";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Departments/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Department
@model ContosoUniversity.Data.Entities.Department

@{
ViewData["Title"] = "Delete";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Departments/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Department
@model ContosoUniversity.Data.Entities.Department

@{
ViewData["Title"] = "Details";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Departments/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Department
@model ContosoUniversity.Data.Entities.Department

@{
ViewData["Title"] = "Edit";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Departments/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model IEnumerable<ContosoUniversity.Models.Department>
@model IEnumerable<ContosoUniversity.Data.Entities.Department>

@{
ViewData["Title"] = "Departments";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Instructors/Create.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Instructor
@model ContosoUniversity.Data.Entities.Instructor

@{
ViewData["Title"] = "Create";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Instructors/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Instructor
@model ContosoUniversity.Data.Entities.Instructor

@{
ViewData["Title"] = "Delete";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Instructors/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Instructor
@model ContosoUniversity.Data.Entities.Instructor

@{
ViewData["Title"] = "Details";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Instructors/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Instructor
@model ContosoUniversity.Data.Entities.Instructor

@{
ViewData["Title"] = "Edit";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Students/Create.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Student
@model ContosoUniversity.Data.Entities.Student

@{
ViewData["Title"] = "Create";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Students/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Student
@model ContosoUniversity.Data.Entities.Student

@{
ViewData["Title"] = "Delete";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Students/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Student
@model ContosoUniversity.Data.Entities.Student

@{
ViewData["Title"] = "Details";
Expand Down
2 changes: 1 addition & 1 deletion ContosoUniversity/Views/Students/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model ContosoUniversity.Models.Student
@model ContosoUniversity.Data.Entities.Student

@{
ViewData["Title"] = "Edit";
Expand Down
Loading

0 comments on commit 03499d9

Please sign in to comment.