using JiangSu.cs;
|
using JiangSu.Models;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Web.Http;
|
|
namespace JiangSu.Controllers
|
{
|
public class GridController : ApiController
|
{
|
[HttpGet]
|
public object SelectAll()
|
{
|
try
|
{
|
List<Grid> grids = GridDAL.SelectAll();
|
List<JObject> list = GetJObjects(grids);
|
|
Dictionary<string, object> dict = GetDict();
|
dict.Add("features", list);
|
|
return dict;
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return null;
|
}
|
}
|
|
private Dictionary<string, object> GetDict()
|
{
|
string crs = "{ \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" } }";
|
JObject crsJObj = JsonConvert.DeserializeObject<JObject>(crs);
|
|
Dictionary<string, object> dict = new Dictionary<string, object>();
|
dict.Add("type", "FeatureCollection");
|
dict.Add("name", "网格4549");
|
dict.Add("crs", crsJObj);
|
|
return dict;
|
}
|
|
private List<JObject> GetJObjects(List<Grid> grids)
|
{
|
List<JObject> list = new List<JObject>();
|
if (null != grids && grids.Count > 0)
|
{
|
foreach (Grid g in grids)
|
{
|
JObject obj = JsonConvert.DeserializeObject<JObject>(g.json);
|
list.Add(obj);
|
}
|
}
|
|
return list;
|
}
|
|
[HttpGet]
|
public object SelectById(long id)
|
{
|
try
|
{
|
Grid grid = GridDAL.SelectById(id);
|
List<JObject> list = GetJObjects(null == grid ? null : new List<Grid> { grid });
|
|
Dictionary<string, object> dict = GetDict();
|
dict.Add("features", list);
|
|
return dict;
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return null;
|
}
|
}
|
|
[HttpGet]
|
public int DeleteByIds([FromUri] List<int> ids)
|
{
|
try
|
{
|
if (null == ids || ids.Count == 0) return 0;
|
|
return GridDAL.DeleteByIds(ids);
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return 0;
|
}
|
}
|
|
[HttpGet]
|
public int DelAll()
|
{
|
try
|
{
|
return GridDAL.DelAll();
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return 0;
|
}
|
}
|
|
[HttpPost]
|
public int Insert([FromBody] Grid grid)
|
{
|
try
|
{
|
if (null == grid) return 0;
|
|
return GridDAL.Insert(grid);
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return 0;
|
}
|
}
|
|
[HttpPost]
|
public int UpdateById([FromBody] Grid grid)
|
{
|
try
|
{
|
if (null == grid) return 0;
|
|
return GridDAL.UpdateById(grid);
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
return 0;
|
}
|
}
|
}
|
}
|