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 grids = GridDAL.SelectAll(); List list = GetJObjects(grids); Dictionary dict = GetDict(); dict.Add("features", list); return dict; } catch (Exception ex) { LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); return null; } } private Dictionary GetDict() { string crs = "{ \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" } }"; JObject crsJObj = JsonConvert.DeserializeObject(crs); Dictionary dict = new Dictionary(); dict.Add("type", "FeatureCollection"); dict.Add("name", "网格4549"); dict.Add("crs", crsJObj); return dict; } private List GetJObjects(List grids) { List list = new List(); if (null != grids && grids.Count > 0) { foreach (Grid g in grids) { JObject obj = JsonConvert.DeserializeObject(g.json); list.Add(obj); } } return list; } [HttpGet] public object SelectById(long id) { try { Grid grid = GridDAL.SelectById(id); List list = GetJObjects(null == grid ? null : new List { grid }); Dictionary 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 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; } } } }