-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeController.cs
90 lines (89 loc) · 3.14 KB
/
HomeController.cs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Web.Mvc;
using E4425.Models;
using DevExpress.Web.Mvc;
using System.Linq;
namespace E4425.Controllers
{
public class HomeController : Controller
{
WorldCitiesEntities entity = new WorldCitiesEntities();
public ActionResult Index()
{
return View(entity.Customers.ToList());
}
public ActionResult GridViewPartial()
{
return PartialView(entity.Customers.ToList());
}
public ActionResult GridViewEditPartial(Customer customerInfo)
{
if (ModelState.IsValid)
{
try
{
entity.Customers.Attach(customerInfo);
var entry = entity.Entry(customerInfo);
entry.Property(e => e.CityId).IsModified = true;
entry.Property(e => e.CountryId).IsModified = true;
entry.Property(e => e.CustomerName).IsModified = true;
// uncomment the next line to enable database updates
// entity.SaveChanges();
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("GridViewPartial", entity.Customers.ToList());
}
public ActionResult GridViewInsertPartial(Customer customerInfo)
{
if (ModelState.IsValid)
{
try
{
entity.Customers.Add(customerInfo);
// uncomment the next line to enable database updates
// entity.SaveChanges();
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("GridViewPartial", entity.Customers.ToList());
}
public ActionResult GridViewDeletePartial(int CustomerId)
{
if (ModelState.IsValid)
{
try
{
entity.Customers.Remove(entity.Customers.Find(CustomerId));
// uncomment the next line to enable database updates
//entity.SaveChanges();
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("GridViewPartial", entity.Customers.ToList());
}
public ActionResult ComboBoxCountryPartial()
{
return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CountryComboBoxProperties);
}
public ActionResult ComboBoxCityPartial()
{
return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CityComboBoxProperties);
}
}
}