-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeController.cs
54 lines (53 loc) · 2.03 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
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(MVCxGridViewBatchUpdateValues<Customer, int> modifiedValues)
{
foreach (var customerInfo in modifiedValues.Insert)
{
if (modifiedValues.IsValid(customerInfo))
entity.Customers.Add(customerInfo);
}
foreach (var customerInfo in modifiedValues.Update)
{
if (modifiedValues.IsValid(customerInfo))
{
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;
}
}
foreach (var customerID in modifiedValues.DeleteKeys)
{
entity.Customers.Remove(entity.Customers.Find(customerID));
}
// uncomment the next line to enable database updates
// entity.SaveChanges();
return PartialView("GridViewPartial", entity.Customers.ToList());
}
public ActionResult ComboBoxCountryPartial()
{
return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CountryComboBoxProperties);
}
public ActionResult ComboBoxCityPartial()
{
return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CityComboBoxProperties);
}
}
}