(MVC) MVC (2018)

<<назад StudentsController1.vb (Contoso University).

   1:  Imports System
   2:  Imports System.Collections.Generic
   3:  Imports System.Data
   4:  Imports System.Data.Entity
   5:  Imports System.Linq
   6:  Imports System.Threading.Tasks
   7:  Imports System.Net
   8:  Imports System.Web
   9:  Imports System.Web.Mvc
  10:  Imports CU_VB_3
  11:  Imports CU_VB_3.Models
  12:   
  13:  Namespace Controllers
  14:      Public Class StudentsController
  15:          Inherits System.Web.Mvc.Controller
  16:   
  17:          Private db As New SchoolContext
  18:   
  19:          ' GET: Students
  20:          Async Function Index() As Task(Of ActionResult)
  21:              Return View(Await Task.FromResult(db.Students.ToList()))
  22:          End Function
  23:   
  24:          ' GET: Students/Details/5
  25:          Async Function Details(ByVal id As Integer?) As Task(Of ActionResult)
  26:              If IsNothing(id) Then
  27:                  Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
  28:              End If
  29:              Dim student As Student = Await db.People.FindAsync(id)
  30:              If IsNothing(student) Then
  31:                  Return HttpNotFound()
  32:              End If
  33:              Return View(student)
  34:          End Function
  35:   
  36:          ' GET: Students/Create
  37:          Function Create() As ActionResult
  38:              Return View()
  39:          End Function
  40:   
  41:          ' POST: Students/Create
  42:          'To protect from overposting attacks, please enable the specific properties you want to bind to, for 
  43:          'more details see https://go.microsoft.com/fwlink/?LinkId=317598.
  44:          <HttpPost()>
  45:          <ValidateAntiForgeryToken()>
  46:          Async Function Create(<Bind(Include:="ID,LastName,FirstMidName,EnrollmentDate")> ByVal student As Student) As Task(Of ActionResult)
  47:              If ModelState.IsValid Then
  48:                  db.People.Add(student)
  49:                  Await db.SaveChangesAsync()
  50:                  Return RedirectToAction("Index")
  51:              End If
  52:              Return View(student)
  53:          End Function
  54:   
  55:          ' GET: Students/Edit/5
  56:          Async Function Edit(ByVal id As Integer?) As Task(Of ActionResult)
  57:              If IsNothing(id) Then
  58:                  Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
  59:              End If
  60:              Dim student As Student = Await db.People.FindAsync(id)
  61:              If IsNothing(student) Then
  62:                  Return HttpNotFound()
  63:              End If
  64:              Return View(student)
  65:          End Function
  66:   
  67:          ' POST: Students/Edit/5
  68:          'To protect from overposting attacks, please enable the specific properties you want to bind to, for 
  69:          'more details see https://go.microsoft.com/fwlink/?LinkId=317598.
  70:          <HttpPost()>
  71:          <ValidateAntiForgeryToken()>
  72:          Async Function Edit(<Bind(Include:="ID,LastName,FirstMidName,EnrollmentDate")> ByVal student As Student) As Task(Of ActionResult)
  73:              If ModelState.IsValid Then
  74:                  db.Entry(student).State = EntityState.Modified
  75:                  Await db.SaveChangesAsync()
  76:                  Return RedirectToAction("Index")
  77:              End If
  78:              Return View(student)
  79:          End Function
  80:   
  81:          ' GET: Students/Delete/5
  82:          Async Function Delete(ByVal id As Integer?) As Task(Of ActionResult)
  83:              If IsNothing(id) Then
  84:                  Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
  85:              End If
  86:              Dim student As Student = Await db.People.FindAsync(id)
  87:              If IsNothing(student) Then
  88:                  Return HttpNotFound()
  89:              End If
  90:              Return View(student)
  91:          End Function
  92:   
  93:          ' POST: Students/Delete/5
  94:          <HttpPost()>
  95:          <ActionName("Delete")>
  96:          <ValidateAntiForgeryToken()>
  97:          Async Function DeleteConfirmed(ByVal id As Integer) As Task(Of ActionResult)
  98:              Dim student As Student = Await db.People.FindAsync(id)
  99:              db.People.Remove(student)
 100:              Await db.SaveChangesAsync()
 101:              Return RedirectToAction("Index")
 102:          End Function
 103:   
 104:          Protected Overrides Sub Dispose(ByVal disposing As Boolean)
 105:              If (disposing) Then
 106:                  db.Dispose()
 107:              End If
 108:              MyBase.Dispose(disposing)
 109:          End Sub
 110:      End Class
 111:  End Namespace


Comments ( )
Link to this page: //www.vb-net.com/EF-missing-FAQ/Code/StudentsController1.vb.htm
< THANKS ME>