Skip to content

Commit 75bce59

Browse files
added sample
1 parent 7dbe4e1 commit 75bce59

33 files changed

+1850
-0
lines changed
1.2 MB
Binary file not shown.

.vs/TestSample/v15/.suo

45.5 KB
Binary file not shown.
3.66 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/config/applicationhost.config

Lines changed: 996 additions & 0 deletions
Large diffs are not rendered by default.

TestSample.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26730.16
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestSample", "TestSample\TestSample.csproj", "{334C8F03-85AB-44BA-9910-A0E8D18157F0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{334C8F03-85AB-44BA-9910-A0E8D18157F0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0ED9D229-2BD1-403B-A1A9-EE104F3DF119}
24+
EndGlobalSection
25+
EndGlobal
9.65 KB
Binary file not shown.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using TestSample.Models;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Syncfusion.XlsIO;
8+
using Syncfusion.EJ2.Base;
9+
using System.Data;
10+
using System.IO;
11+
using Microsoft.AspNetCore.Http;
12+
using Newtonsoft.Json;
13+
14+
namespace TestSample.Controllers
15+
{
16+
17+
public class HomeController : Controller
18+
{
19+
20+
public IActionResult Index()
21+
{
22+
ViewBag.datasource = OrdersDetails.GetAllRecords().ToList();
23+
return View();
24+
}
25+
public async Task<IActionResult> Save()
26+
{
27+
string filePath = "App_Data/TempData/";
28+
string directoryPath = Path.Combine(new FileInfo(filePath).Directory.FullName);
29+
30+
if (!Directory.Exists(directoryPath))
31+
Directory.CreateDirectory(directoryPath);
32+
33+
try
34+
{
35+
if (HttpContext.Request.Form.Files.Count > 0)
36+
{
37+
for (int i = 0; i < HttpContext.Request.Form.Files.Count; ++i)
38+
{
39+
IFormFile httpPostedFile = HttpContext.Request.Form.Files[i];
40+
41+
if (httpPostedFile != null)
42+
{
43+
filePath = Path.Combine(directoryPath, httpPostedFile.FileName);
44+
45+
if (!System.IO.File.Exists(filePath))
46+
{
47+
using (var fileStream = new FileStream(filePath, FileMode.Create))
48+
{
49+
await httpPostedFile.CopyToAsync(fileStream);
50+
ExcelEngine excelEngine = new ExcelEngine();
51+
52+
//Loads or open an existing workbook through Open method of IWorkbooks
53+
fileStream.Position = 0;
54+
IWorkbook workbook = excelEngine.Excel.Workbooks.Open(httpPostedFile.OpenReadStream());
55+
IWorksheet worksheet = workbook.Worksheets[0];
56+
57+
// Read data from the worksheet and Export to the DataTable.
58+
59+
DataTable table = worksheet.ExportDataTable(worksheet.UsedRange.Row, worksheet.UsedRange.Column, worksheet.UsedRange.LastRow, worksheet.UsedRange.LastColumn, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.ComputedFormulaValues);
60+
string JSONString = string.Empty;
61+
JSONString = JsonConvert.SerializeObject(table);
62+
ViewBag.data = JsonConvert.SerializeObject(table, Formatting.Indented, new JsonSerializerSettings { Converters = new[] { new Newtonsoft.Json.Converters.DataTableConverter() } });
63+
64+
//return View();
65+
}
66+
67+
return Ok(ViewBag.data);
68+
}
69+
else
70+
{
71+
return BadRequest("File already exists");
72+
}
73+
}
74+
}
75+
}
76+
77+
return BadRequest("No file in request"); ;
78+
}
79+
catch (Exception e)
80+
{
81+
return BadRequest(e.Message);
82+
}
83+
}
84+
85+
public IActionResult gridState([FromBody]DataManagerRequest dm)
86+
{
87+
var query = dm;
88+
return Json(query);
89+
}
90+
91+
public IActionResult GridDatasource([FromBody]DataManagerRequest dm)
92+
{
93+
var DataSource = OrdersDetails.GetAllRecords().ToList();
94+
95+
DataOperations operation = new DataOperations();
96+
int count = DataSource.Count();
97+
return dm.RequiresCounts ? Json(new { result = DataSource.Skip(dm.Skip).Take(dm.Take), count = count }) : Json(DataSource);
98+
}
99+
public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value)
100+
{
101+
var ord = value.Value;
102+
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
103+
val.OrderID = ord.OrderID;
104+
val.ShipName = ord.ShipName;
105+
val.CustomerID = ord.CustomerID;
106+
val.ShipCountry = ord.ShipCountry;
107+
108+
return Json(value.Value);
109+
}
110+
//insert the record
111+
public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value)
112+
{
113+
114+
OrdersDetails.GetAllRecords().Insert(0, value.Value);
115+
return Json(value.Value);
116+
}
117+
//Delete the record
118+
public ActionResult Delete([FromBody]CRUDModel<OrdersDetails> value)
119+
{
120+
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault());
121+
return Json(value);
122+
}
123+
124+
public class Data
125+
{
126+
127+
public bool requiresCounts { get; set; }
128+
public int skip { get; set; }
129+
public int take { get; set; }
130+
}
131+
public class CRUDModel<T> where T : class
132+
{
133+
public string Action { get; set; }
134+
135+
public string Table { get; set; }
136+
137+
public string KeyColumn { get; set; }
138+
139+
public object Key { get; set; }
140+
141+
public T Value { get; set; }
142+
143+
public List<T> Added { get; set; }
144+
145+
public List<T> Changed { get; set; }
146+
147+
public List<T> Deleted { get; set; }
148+
149+
public IDictionary<string, object> @params { get; set; }
150+
}
151+
}
152+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using TestSample.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.EJ2;
4+
using System;
5+
using System.Linq;
6+
7+
namespace TestSample.Controllers
8+
{
9+
[Produces("application/json")]
10+
[Route("api/Orders")]
11+
public class OrdersController : Controller
12+
{
13+
// GET: api/Orders
14+
[HttpGet("GetTest")]
15+
public object GetTest()
16+
{
17+
18+
var queryString = Request.Query;
19+
int skip = Convert.ToInt32(queryString["$skip"]);
20+
int take = Convert.ToInt32(queryString["$top"]);
21+
var data = OrdersDetails.GetAllRecords().ToList();
22+
return Json(new { Items = data.Skip(skip).Take(take), Count = data.Count() });
23+
24+
}
25+
26+
// GET: api/Orders/5
27+
[HttpGet("{id}", Name = "Get")]
28+
public object Get(string id)
29+
{
30+
var queryString = Request.Query;
31+
var dataa = Convert.ToString(queryString["id"]);
32+
var data = OrdersDetails.GetAllRecords().Where(user => user.CustomerID == dataa).ToList();
33+
return new { Items = data, Count = data.Count() };
34+
}
35+
36+
37+
38+
[HttpPost("GetTest")]
39+
public object PostTest([FromBody]OrdersDetails value)
40+
{
41+
OrdersDetails.GetAllRecords().Add(value);
42+
var Data = OrdersDetails.GetAllRecords().ToList();
43+
int count = Data.Count();
44+
return Json(new { result = Data, count = count });
45+
}
46+
47+
48+
// PUT: api/Orders/5
49+
[HttpPut("GetTest")]
50+
public object Put([FromBody]OrdersDetails value)
51+
{
52+
var ord = value;
53+
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
54+
val.OrderID = ord.OrderID;
55+
val.EmployeeID = ord.EmployeeID;
56+
val.CustomerID = ord.CustomerID;
57+
val.Freight = ord.Freight;
58+
val.OrderDate = ord.OrderDate;
59+
val.ShipCity = ord.ShipCity;
60+
return value;
61+
}
62+
63+
// DELETE: api/ApiWithActions/5
64+
[HttpDelete("{id:int}")]
65+
[Route("Orders/{id:int}")]
66+
public object Delete(int id)
67+
{
68+
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault());
69+
return Json(id);
70+
}
71+
}
72+
public class Data
73+
{
74+
75+
public bool requiresCounts { get; set; }
76+
public int skip { get; set; }
77+
public int take { get; set; }
78+
}
79+
80+
}

0 commit comments

Comments
 (0)