-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHomeController.cs
43 lines (40 loc) · 1.53 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.Mvc;
using Models;
namespace GridViewBatchEdit.Controllers {
public class HomeController : Controller {
public ActionResult Index() {
return View();
}
[ValidateInput(false)]
public ActionResult GridViewPartial() {
return PartialView("_GridViewPartial", BatchEditRepository.GridData);
}
[HttpPost, ValidateInput(false)]
public ActionResult BatchUpdatePartial(MVCxGridViewBatchUpdateValues<GridDataItem, int> batchValues) {
if(ModelState.IsValid) {
try {
foreach(var item in batchValues.Insert) {
if(batchValues.IsValid(item))
BatchEditRepository.InsertNewItem(item);
}
foreach(var item in batchValues.Update) {
if(batchValues.IsValid(item))
BatchEditRepository.UpdateItem(item);
}
foreach(var itemKey in batchValues.DeleteKeys) {
BatchEditRepository.DeleteItem(itemKey);
}
} catch(Exception e) {
ViewData["EditError"] = e.Message;
}
} else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("_GridViewPartial", BatchEditRepository.GridData);
}
}
}