-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHomeController.vb
71 lines (70 loc) · 3.15 KB
/
HomeController.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Imports Microsoft.VisualBasic
Imports System.Web.Mvc
Imports E4425.Models
Imports DevExpress.Web.Mvc
Imports System.Linq
Imports System
Namespace E4425.Controllers
Public Class HomeController
Inherits Controller
Private entity As New WorldCitiesEntities()
Public Function Index() As ActionResult
Return View(entity.Customers.ToList())
End Function
Public Function GridViewPartial() As ActionResult
Return PartialView(entity.Customers.ToList())
End Function
Public Function GridViewEditPartial(ByVal customerInfo As Customer) As ActionResult
If ModelState.IsValid Then
Try
entity.Customers.Attach(customerInfo)
Dim entry = entity.Entry(customerInfo)
entry.Property(Function(e) e.CityId).IsModified = True
entry.Property(Function(e) e.CountryId).IsModified = True
entry.Property(Function(e) e.CustomerName).IsModified = True
' uncomment the next line to enable database updates
' entity.SaveChanges();
Catch e As Exception
ViewData("EditError") = e.Message
End Try
Else
ViewData("EditError") = "Please, correct all errors."
End If
Return PartialView("GridViewPartial", entity.Customers.ToList())
End Function
Public Function GridViewInsertPartial(ByVal customerInfo As Customer) As ActionResult
If ModelState.IsValid Then
Try
entity.Customers.Add(customerInfo)
' uncomment the next line to enable database updates
' entity.SaveChanges();
Catch e As Exception
ViewData("EditError") = e.Message
End Try
Else
ViewData("EditError") = "Please, correct all errors."
End If
Return PartialView("GridViewPartial", entity.Customers.ToList())
End Function
Public Function GridViewDeletePartial(ByVal CustomerId As Integer) As ActionResult
If ModelState.IsValid Then
Try
entity.Customers.Remove(entity.Customers.Find(CustomerId))
'uncomment the next line to enable database updates
'entity.SaveChanges();
Catch e As Exception
ViewData("EditError") = e.Message
End Try
Else
ViewData("EditError") = "Please, correct all errors."
End If
Return PartialView("GridViewPartial", entity.Customers.ToList())
End Function
Public Function ComboBoxCountryPartial() As ActionResult
Return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CountryComboBoxProperties)
End Function
Public Function ComboBoxCityPartial() As ActionResult
Return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CityComboBoxProperties)
End Function
End Class
End Namespace