|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.Linq; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.AspNetCore.Mvc; |
| 7 | +using filter_core.Models; |
| 8 | +using Syncfusion.EJ2.Base; |
| 9 | + |
| 10 | +namespace TestSample.Controllers |
| 11 | +{ |
| 12 | + |
| 13 | + public class HomeController : Controller |
| 14 | + { |
| 15 | + |
| 16 | + public static List<States> state = new List<States>(); |
| 17 | + public static List<Country> country= new List<Country>(); |
| 18 | + public IActionResult Index() |
| 19 | + { |
| 20 | + var Order = OrdersDetails.GetAllRecords(); |
| 21 | + ViewBag.DataSource = Order; |
| 22 | + |
| 23 | + return View(); |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | + public IActionResult StateDataSource([FromBody]ExtendedDataManager dm) |
| 28 | + { |
| 29 | + |
| 30 | + var state = States.getStates(); |
| 31 | + |
| 32 | + var Data = state.ToList(); |
| 33 | + int count = state.Count(); |
| 34 | + |
| 35 | + |
| 36 | + List<States> iterateState= new List<States>(); |
| 37 | + foreach (States st in state) { |
| 38 | + if (st.countryId == (Int64)dm.Where[0].value) { |
| 39 | + iterateState.Add(st); |
| 40 | + } |
| 41 | + } |
| 42 | + return dm.RequiresCounts ? Json(new { result = Data.Skip(dm.Skip).Take(dm.Take), count = count }) : Json(iterateState.ToList()); |
| 43 | + } |
| 44 | + |
| 45 | + public IActionResult CountryDataSource([FromBody]ExtendedDataManager dm) |
| 46 | + { |
| 47 | + |
| 48 | + var country = Country.getCountries(); |
| 49 | + var Data = country.ToList(); |
| 50 | + int count = country.Count(); |
| 51 | + |
| 52 | + return dm.RequiresCounts ? Json(new { result = Data.Skip(dm.Skip).Take(dm.Take), count = count }) : Json(Data); |
| 53 | + } |
| 54 | + |
| 55 | + public class ExtendedDataManager : DataManagerRequest |
| 56 | + { |
| 57 | + public IDictionary<string, string> @params; |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + public IActionResult UrlDatasource([FromBody]Data dm) |
| 63 | + { |
| 64 | + var order = OrdersDetails.GetAllRecords(); |
| 65 | + var Data = order.ToList(); |
| 66 | + int count = order.Count(); |
| 67 | + return dm.requiresCounts ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }) : Json(Data); |
| 68 | + } |
| 69 | + |
| 70 | + public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value) |
| 71 | + { |
| 72 | + var ord = value.value; |
| 73 | + OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); |
| 74 | + val.OrderID = ord.OrderID; |
| 75 | + val.EmployeeID = ord.EmployeeID; |
| 76 | + val.CustomerID = ord.CustomerID; |
| 77 | + val.Freight = ord.Freight; |
| 78 | + val.OrderDate = ord.OrderDate; |
| 79 | + val.ShipCity = ord.ShipCity; |
| 80 | + |
| 81 | + return Json(value.value); |
| 82 | + } |
| 83 | + //insert the record |
| 84 | + public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value) |
| 85 | + { |
| 86 | + |
| 87 | + OrdersDetails.GetAllRecords().Insert(0, value.value); |
| 88 | + return Json(value.value); |
| 89 | + } |
| 90 | + //Delete the record |
| 91 | + public ActionResult CellEditDelete([FromBody]CRUDModel<OrdersDetails> value) |
| 92 | + { |
| 93 | + OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.key.ToString())).FirstOrDefault()); |
| 94 | + return Json(value); |
| 95 | + } |
| 96 | + |
| 97 | + public class Country |
| 98 | + { |
| 99 | + public Country() |
| 100 | + { |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + public Country(int cid, string cname) |
| 105 | + { |
| 106 | + this.countryId = cid; |
| 107 | + this.countryName = cname; |
| 108 | + } |
| 109 | + public int countryId { get; set; } |
| 110 | + public string countryName { get; set; } |
| 111 | + public static List<Country> getCountries() |
| 112 | + { |
| 113 | + if (country.Count == 0) |
| 114 | + { |
| 115 | + |
| 116 | + country.Add(new Country(1, "United States")); |
| 117 | + country.Add(new Country(2, "Australia")); |
| 118 | + } |
| 119 | + return country; |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + public class States |
| 125 | + { |
| 126 | + |
| 127 | + public States() { |
| 128 | + |
| 129 | + } |
| 130 | + |
| 131 | + public States(int cid,int sid, string sname) { |
| 132 | + this.stateId= sid; |
| 133 | + this.countryId = cid; |
| 134 | + this.stateName = sname; |
| 135 | + } |
| 136 | + public int countryId { get; set; } |
| 137 | + public int stateId { get; set; } |
| 138 | + public string stateName { get; set; } |
| 139 | + public static List<States> getStates() |
| 140 | + { |
| 141 | + if (state.Count == 0) |
| 142 | + { |
| 143 | + state.Add(new States(1, 101, "New York")); |
| 144 | + state.Add(new States(1, 102, "Virginia")); |
| 145 | + state.Add(new States(1, 103, "Washington")); |
| 146 | + state.Add(new States(2, 104, "Queensland")); |
| 147 | + state.Add(new States(2, 105, "Tasmania")); |
| 148 | + state.Add(new States(2, 106, "Victoria")); |
| 149 | + } |
| 150 | + return state; |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + |
| 155 | + public class Data |
| 156 | + { |
| 157 | + |
| 158 | + public bool requiresCounts { get; set; } |
| 159 | + public int skip { get; set; } |
| 160 | + public int take { get; set; } |
| 161 | + public Dictionary<string, object> @params { get; set; } |
| 162 | + } |
| 163 | + public class CRUDModel<T> where T : class |
| 164 | + { |
| 165 | + public string action { get; set; } |
| 166 | + |
| 167 | + public string table { get; set; } |
| 168 | + |
| 169 | + public string keyColumn { get; set; } |
| 170 | + |
| 171 | + public object key { get; set; } |
| 172 | + |
| 173 | + public T value { get; set; } |
| 174 | + |
| 175 | + public List<T> added { get; set; } |
| 176 | + |
| 177 | + public List<T> changed { get; set; } |
| 178 | + |
| 179 | + public List<T> deleted { get; set; } |
| 180 | + |
| 181 | + public IDictionary<string, object> @params { get; set; } |
| 182 | + } |
| 183 | + } |
| 184 | + public class OrdersDetails |
| 185 | + { |
| 186 | + public static List<OrdersDetails> order = new List<OrdersDetails>(); |
| 187 | + public OrdersDetails() |
| 188 | + { |
| 189 | + |
| 190 | + } |
| 191 | + public OrdersDetails(int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress) |
| 192 | + { |
| 193 | + this.OrderID = OrderID; |
| 194 | + this.CustomerID = CustomerId; |
| 195 | + this.EmployeeID = EmployeeId; |
| 196 | + this.Freight = Freight; |
| 197 | + this.ShipCity = ShipCity; |
| 198 | + this.Verified = Verified; |
| 199 | + this.OrderDate = OrderDate; |
| 200 | + this.ShipName = ShipName; |
| 201 | + this.ShipCountry = ShipCountry; |
| 202 | + this.ShippedDate = ShippedDate; |
| 203 | + this.ShipAddress = ShipAddress; |
| 204 | + } |
| 205 | + public static List<OrdersDetails> GetAllRecords() |
| 206 | + { |
| 207 | + if (order.Count() == 0) |
| 208 | + { |
| 209 | + int code = 10000; |
| 210 | + for (int i = 1; i < 10; i++) |
| 211 | + { |
| 212 | + order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6")); |
| 213 | + order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123")); |
| 214 | + order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo")); |
| 215 | + order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7")); |
| 216 | + order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S.")); |
| 217 | + code += 5; |
| 218 | + } |
| 219 | + } |
| 220 | + return order; |
| 221 | + } |
| 222 | + |
| 223 | + public int? OrderID { get; set; } |
| 224 | + public string CustomerID { get; set; } |
| 225 | + public int? EmployeeID { get; set; } |
| 226 | + public double? Freight { get; set; } |
| 227 | + public string ShipCity { get; set; } |
| 228 | + public bool Verified { get; set; } |
| 229 | + public DateTime OrderDate { get; set; } |
| 230 | + |
| 231 | + public string ShipName { get; set; } |
| 232 | + |
| 233 | + public string ShipCountry { get; set; } |
| 234 | + |
| 235 | + public DateTime ShippedDate { get; set; } |
| 236 | + public string ShipAddress { get; set; } |
| 237 | + } |
| 238 | +} |
0 commit comments