Skip to content

Commit ed874bc

Browse files
committed
chore(examples): migrate grid examples vol2 part1
1 parent 7acac9e commit ed874bc

File tree

101 files changed

+9467
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+9467
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Kendo.Mvc.Extensions;
2+
using Kendo.Mvc.UI;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Web;
7+
using System.Web.Mvc;
8+
using Telerik.Examples.Mvc.Areas.GridBindingDynamicCollection.Models;
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridBindingDynamicCollection.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
public ActionResult Index()
15+
{
16+
ViewBag.Message = "Home page.";
17+
18+
return View();
19+
}
20+
21+
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
22+
{
23+
return GetView(request);
24+
}
25+
26+
[HttpPost]
27+
public ActionResult Create([DataSourceRequest] DataSourceRequest request)
28+
{
29+
using (var db = new GridBindingDynamicCollectionEntities())
30+
{
31+
var product = new GridBindingDynamicCollectionProduct();
32+
if (TryUpdateModel(product, includeProperties: new string[] { "ProductName", "UnitPrice", "QuantityPerUnit" }))
33+
{
34+
db.Products.Add(product);
35+
db.SaveChanges();
36+
}
37+
return Json(new[] { product }.ToDataSourceResult(request));
38+
}
39+
40+
}
41+
42+
[HttpPost]
43+
public ActionResult Update([DataSourceRequest] DataSourceRequest request, int productId)
44+
{
45+
using (var db = new GridBindingDynamicCollectionEntities())
46+
{
47+
var productToUpdate = db.Products.First(p => p.ProductID == productId);
48+
49+
if (TryUpdateModel(productToUpdate, includeProperties: new string[] { "ProductName", "UnitPrice", "QuantityPerUnit" }))
50+
{
51+
db.SaveChanges();
52+
}
53+
}
54+
return Json(ModelState.ToDataSourceResult());
55+
}
56+
57+
[HttpPost]
58+
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, int productId)
59+
{
60+
using (var db = new GridBindingDynamicCollectionEntities())
61+
{
62+
db.Products.Remove(db.Products.First(p => p.ProductID == productId));
63+
db.SaveChanges();
64+
}
65+
return Json(ModelState.ToDataSourceResult());
66+
}
67+
68+
private IEnumerable<dynamic> GetData()
69+
{
70+
var db = new GridBindingDynamicCollectionEntities();
71+
return db.Products;
72+
}
73+
74+
private JsonResult GetView(DataSourceRequest request)
75+
{
76+
return Json(GetData().ToDataSourceResult(request));
77+
}
78+
79+
80+
public ActionResult About()
81+
{
82+
ViewBag.Message = "Your app description page.";
83+
84+
return View();
85+
}
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Web.Mvc;
2+
3+
namespace Telerik.Examples.Mvc.Areas.GridBindingDynamicCollection
4+
{
5+
public class GridBindingDynamicCollectionAreaRegistration : AreaRegistration
6+
{
7+
public override string AreaName
8+
{
9+
get
10+
{
11+
return "GridBindingDynamicCollection";
12+
}
13+
}
14+
15+
public override void RegisterArea(AreaRegistrationContext context)
16+
{
17+
context.MapRoute(
18+
"GridBindingDynamicCollection_default",
19+
"GridBindingDynamicCollection/{controller}/{action}/{id}",
20+
new { action = "Index", id = UrlParameter.Optional }
21+
);
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated from a template.
4+
//
5+
// Manual changes to this file may cause unexpected behavior in your application.
6+
// Manual changes to this file will be overwritten if the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridBindingDynamicCollection.Models
11+
{
12+
using System;
13+
using System.Collections.Generic;
14+
15+
public partial class GridBindingDynamicCollectionProduct
16+
{
17+
public int ProductID { get; set; }
18+
public string ProductName { get; set; }
19+
public Nullable<int> SupplierID { get; set; }
20+
public Nullable<int> CategoryID { get; set; }
21+
public string QuantityPerUnit { get; set; }
22+
public Nullable<decimal> UnitPrice { get; set; }
23+
public Nullable<short> UnitsInStock { get; set; }
24+
public Nullable<short> UnitsOnOrder { get; set; }
25+
public Nullable<short> ReorderLevel { get; set; }
26+
public bool Discontinued { get; set; }
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated from a template.
4+
//
5+
// Manual changes to this file may cause unexpected behavior in your application.
6+
// Manual changes to this file will be overwritten if the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridBindingDynamicCollection.Models
11+
{
12+
using System;
13+
using System.Data.Entity;
14+
using System.Data.Entity.Infrastructure;
15+
16+
public partial class GridBindingDynamicCollectionEntities : DbContext
17+
{
18+
public GridBindingDynamicCollectionEntities()
19+
: base("name=GridBindingDynamicCollectionEntities")
20+
{
21+
}
22+
23+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
24+
{
25+
throw new UnintentionalCodeFirstException();
26+
}
27+
28+
public virtual DbSet<GridBindingDynamicCollectionProduct> Products { get; set; }
29+
}
30+
}

0 commit comments

Comments
 (0)