You are on page 1of 12

Imports System.Collections.

Generic
Imports System.ComponentModel.DataAnnotations.Schema
Imports MvcCRUDEntity.Models.Course
Namespace Models
Public Class Course
<DatabaseGenerated(DatabaseGeneratedOption.None)> _
Public Property CourseID() As Integer
Get
Return m_CourseID
End Get
Set(value As Integer)
m_CourseID = value
End Set
End Property
Private m_CourseID As Integer
Public Property Title() As String
Get
Return m_Title
End Get
Set(value As String)
m_Title = value
End Set
End Property
Private m_Title As String
Public Property Credits() As Integer
Get
Return m_Credits
End Get
Set(value As Integer)
m_Credits = value
End Set
End Property
Private m_Credits As Integer
Public Overridable Property Enrollments() As ICollection(Of Enrollment)
Get
Return m_Enrollments
End Get
Set(value As ICollection(Of Enrollment))
m_Enrollments = value
End Set
End Property
Private m_Enrollments As ICollection(Of Enrollment)
Shared Sub ForEach(p1 As Object)
Throw New NotImplementedException
End Sub
End Class
End Namespace
Imports System.ComponentModel.DataAnnotations.Schema
Imports System.Collections.Generic
Imports MvcCRUDEntity.Models.Student
Namespace Models
Public Class Student
Public Property StudentID() As Integer
Get
Return m_StudentID
End Get
Set(value As Integer)
m_StudentID = value
End Set
End Property
Private m_StudentID As Integer
Public Property LastName() As String
Get
Return m_LastName
End Get
Set(value As String)
m_LastName = value
End Set
End Property
Private m_LastName As String
Public Property FirstMidName() As String
Get
Return m_FirstMidName
End Get
Set(value As String)
m_FirstMidName = value
End Set
End Property
Private m_FirstMidName As String
Public Property EnrollmentDate() As DateTime
Get
Return m_EnrollmentDate
End Get
Set(value As DateTime)
m_EnrollmentDate = value
End Set
End Property
Private m_EnrollmentDate As DateTime
Public Overridable Property Enrollments() As ICollection(Of Enrollment)
Get
Return m_Enrollments
End Get
Set(value As ICollection(Of Enrollment))
m_Enrollments = value
End Set
End Property
Private m_Enrollments As ICollection(Of Enrollment)
Shared Sub ForEach(p1 As Object)
Throw New NotImplementedException
End Sub
Function Add(s As Object) As Object
Throw New NotImplementedException
End Function
End Class
End Namespace
Imports System.Collections.Generic
Imports System.ComponentModel.DataAnnotations.Schema
Imports MvcCRUDEntity.Models.Enrollment
Namespace Models
Public Enum Grade
A
B
C
D
F
End Enum
Public Class Enrollment
Public Property EnrollmentID() As Integer
Get
Return m_EnrollmentID
End Get
Set(value As Integer)
m_EnrollmentID = value
End Set
End Property
Private m_EnrollmentID As Integer
Public Property CourseID() As Integer
Get
Return m_CourseID
End Get
Set(value As Integer)
m_CourseID = value
End Set
End Property
Private m_CourseID As Integer
Public Property StudentID() As Integer
Get
Return m_StudentID
End Get
Set(value As Integer)
m_StudentID = value
End Set
End Property
Private m_StudentID As Integer
Public Property Grade() As System.Nullable(Of Grade)
Get
Return m_Grade
End Get
Set(value As System.Nullable(Of Grade))
m_Grade = value
End Set
End Property
Private m_Grade As System.Nullable(Of Grade)
Public Overridable Property Course() As Course
Get
Return m_Course
End Get
Set(value As Course)
m_Course = value
End Set
End Property
Private m_Course As Course
Public Overridable Property Student() As Student
Get
Return m_Student
End Get
Set(value As Student)
m_Student = value
End Set
End Property
Private m_Student As Student
Shared Sub ForEach(p1 As Object)
Throw New NotImplementedException
End Sub
End Class
End Namespace
Imports System.ComponentModel.DataAnnotations.Schema
Imports System.Collections.Generic
Imports MvcCRUDEntity.Models.SchoolContext
Imports System.Data.Entity
Imports System.Data.Entity.ModelConfiguration.Conventions
Namespace Models
Public Class SchoolContext
Inherits DbContext
Public Sub New()
MyBase.New("SchoolContext")
End Sub
Public Property studant() As DbSet(Of Student)
Get
Return m_student
End Get
Set(value As DbSet(Of Student))
m_student = value
End Set
End Property
Private m_student As DbSet(Of Student)
Public Property Enrollments() As DbSet(Of Enrollment)
Get
Return m_Enrollments
End Get
Set(value As DbSet(Of Enrollment))
m_Enrollments = value
End Set
End Property
Private m_Enrollments As DbSet(Of Enrollment)
Public Property Courses() As DbSet(Of Course)
Get
Return m_Courses
End Get
Set(value As DbSet(Of Course))
m_Courses = value
End Set
End Property
Private m_Courses As DbSet(Of Course)
'Private Property m_studantes As Estudante
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
modelBuilder.Conventions.Remove(Of PluralizingTableNameConvention)()
End Sub
'Private Function m_Estudante() As Models.Estudante
'Throw New NotImplementedException
'End Function
'Private Function m_studantes() As Estudante
' New NotImplementedException
'End Function
'Private Function m_studantes() As Estudante
'Throw New NotImplementedException
'End Function
Function Estudente() As Object
Throw New NotImplementedException
End Function
'Private Function m_studantes() As Estudante
'Throw New NotImplementedException
'End Function
'Private Function m_student() As DbSet(Of Student)
'Throw New NotImplementedException
'End Function
Function student() As Object
Throw New NotImplementedException
End Function
End Class
End Namespace
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Data.Entity
Imports MvcCRUDEntity.Models.SchoolInitializer
Namespace Models
Public Class SchoolInitializer
Inherits System.Data.Entity.DropCreateDatabaseIfModelChanges(Of SchoolCo
ntext)
Protected Overrides Sub Seed(context As SchoolContext)
Dim students = New List(Of Student)() From { _
New Student() With { _
.FirstMidName = "Carson", _
.LastName = "Alexander", _
.EnrollmentDate = DateTime.Parse("2005-09-01") _
}, _
New Student() With { _
.FirstMidName = "Meredith", _
.LastName = "Alonso", _
.EnrollmentDate = DateTime.Parse("2002-09-01") _
}, _
New Student() With { _
.FirstMidName = "Arturo", _
.LastName = "Anand", _
.EnrollmentDate = DateTime.Parse("2003-09-01") _
}, _
New Student() With { _
.FirstMidName = "Gytis", _
.LastName = "Barzdukas", _
.EnrollmentDate = DateTime.Parse("2002-09-01") _
}, _
New Student() With { _
.FirstMidName = "Yan", _
.LastName = "Li", _
.EnrollmentDate = DateTime.Parse("2002-09-01") _
}, _
New Student() With { _
.FirstMidName = "Peggy", _
.LastName = "Justice", _
.EnrollmentDate = DateTime.Parse("2001-09-01") _
}, _
New Student() With { _
.FirstMidName = "Laura", _
.LastName = "Norman", _
.EnrollmentDate = DateTime.Parse("2003-09-01") _
}, _
New Student() With { _
.FirstMidName = "Nino", _
.LastName = "Olivetto", _
.EnrollmentDate = DateTime.Parse("2005-09-01") _
} _
}
Student.ForEach(Function(s) context.student.Add(s))
context.SaveChanges()
Dim courses = New List(Of Course)() From { _
New Course() With { _
.CourseID = 1050, _
.Title = "Chemistry", _
.Credits = 3 _
}, _
New Course() With { _
.CourseID = 4022, _
.Title = "Microeconomics", _
.Credits = 3 _
}, _
New Course() With { _
.CourseID = 4041, _
.Title = "Macroeconomics", _
.Credits = 3 _
}, _
New Course() With { _
.CourseID = 1045, _
.Title = "Calculus", _
.Credits = 4 _
}, _
New Course() With { _
.CourseID = 3141, _
.Title = "Trigonometry", _
.Credits = 4 _
}, _
New Course() With { _
.CourseID = 2021, _
.Title = "Composition", _
.Credits = 3 _
}, _
New Course() With { _
.CourseID = 2042, _
.Title = "Literature", _
.Credits = 4 _
} _
}
Course.ForEach(Function(s) context.Courses.Add(s))
context.SaveChanges()
Dim enrollments = New List(Of Enrollment)() From { _
New Enrollment() With { _
.StudentID = 1, _
.CourseID = 1050, _
.Grade = Grade.A _
}, _
New Enrollment() With { _
.StudentID = 1, _
.CourseID = 4022, _
.Grade = Grade.C _
}, _
New Enrollment() With { _
.StudentID = 1, _
.CourseID = 4041, _
.Grade = Grade.B _
}, _
New Enrollment() With { _
.StudentID = 2, _
.CourseID = 1045, _
.Grade = Grade.B _
}, _
New Enrollment() With { _
.StudentID = 2, _
.CourseID = 3141, _
.Grade = Grade.F _
}, _
New Enrollment() With { _
.StudentID = 2, _
.CourseID = 2021, _
.Grade = Grade.F _
}, _
New Enrollment() With { _
.StudentID = 3, _
.CourseID = 1050 _
}, _
New Enrollment() With { _
.StudentID = 4, _
.CourseID = 1050 _
}, _
New Enrollment() With { _
.StudentID = 4, _
.CourseID = 4022, _
.Grade = Grade.F _
}, _
New Enrollment() With { _
.StudentID = 5, _
.CourseID = 4041, _
.Grade = Grade.C _
}, _
New Enrollment() With { _
.StudentID = 6, _
.CourseID = 1045 _
}, _
New Enrollment() With { _
.StudentID = 7, _
.CourseID = 3141, _
.Grade = Grade.A _
} _
}
Enrollment.ForEach(Function(s) context.Enrollments.Add(s))
context.SaveChanges()
End Sub
End Class
End Namespace
<!DOCTYPE html>
<html lang="pt">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8" />
<title>@ViewData("Title") - Universidade ASP.NET MVC</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("Universidade Asp.NET
MVC", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
@Html.Partial("_LoginPartial")
</section>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Pgina Inicial", "Index", "Home"
)</li>
<li>@Html.ActionLink("Sobre", "About", "Home")</li>
<li>@Html.ActionLink("Contato", "Contact", "Home")</
li>
<li>@Html.ActionLink("Estudantes", "Estudante", "Hom
e")</li>
<li>@Html.ActionLink("Cursos", "Curso", "Home")</li>
<li>@Html.ActionLink("Professores", "Professor", "Ho
me")</li>
<li>@Html.ActionLink("Funcionrios", "Funcionario", "H
ome")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
@RenderSection("featured", required:=false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>&copy; @DateTime.Now.Year - Universidade Asp.NET MVC</p>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required:=False)
</body>
</html>
@Code
ViewData("Title") = "Home Page"
End Code
@section featured
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewData("Title").</h1>
<h2>@ViewData("Message")</h2>
</hgroup>
<p>
To learn more about ASP.NET MVC visit
<a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://
asp.net/mvc</a>.
The page features <mark>videos, tutorials, and samples</mark> to
help you get the most from ASP.NET MVC.
If you have any questions about ASP.NET MVC visit
<a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET M
VC Forum">our forums</a>.
</p>
</div>
</section>
End Section
<h3>We suggest the following:</h3>
<ol class="round">
<div class="row">
<div class="col-md-4">
<h2>Welcome to Contoso University</h2>
<p>
Contoso University is a sample application that
demonstrates how to use Entity Framework 6 in an
ASP.NET MVC 5 web application.
</p>
</div>
<div class="col-md-4">
<h2>Build it from scratch</h2>
<p>You can build the application by following the steps in the tutor
ial series on the ASP.NET site.</p>
<p><a class="btn btn-default" href="http://www.asp.net/mvc/tutorials
/getting-started-with-ef-using-mvc/">See the tutorial &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Download it</h2>
<p>You can download the completed project from the Microsoft Code Ga
llery.</p>
<p><a class="btn btn-default" href="http://code.msdn.microsoft.com/A
SPNET-MVC-Application-b01a9fe8">Download &raquo;</a></p>
</div>
</div>
</ol>
?xml version="1.0" encoding="utf-8"?>
<!--
Para obter mais informaes sobre como configurar o aplicativo ASP.NET, acesse
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go
.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile
.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, Publ
icKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-MvcCRUDEntity-20140522165206;Integrated Security=SSPI;Att
achDBFilename=|DataDirectory|\aspnet-MvcCRUDEntity-20140522165206.mdf" providerN
ame="System.Data.SqlClient" />
<add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Init
ial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.D
ata.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HE
AD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%
windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="class
icMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HE
AD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%
windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="cla
ssicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEA
D,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequest
Handler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers></system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d5
7b246" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10
d57b246" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad36
4e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35
" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad3
64e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<contexts>
<context type="MvcCRUDEntity.DAL.SchoolContext, MvcCRUDEntity">
<databaseInitializer type="MvcCRUDEntity.DAL.SchoolInitializer, MvcCRUDE
ntity" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnect
ionFactory, EntityFramework" />
</entityFramework>
</configuration>

You might also like