// GET: api/Publications/5 public string Get(string id) { List <ptPublication> items = ptsHelper.GetAllPublications(); ptPublication item = items.Find(x => x.PublicationId == id); return(JsonConvert.SerializeObject(item)); }
// POST: api/Publications public void Post(HttpRequestMessage request) { string json = File.ReadAllText(path); var items = JsonConvert.DeserializeObject <List <ptPublication> >(json); string body = request.Content.ReadAsStringAsync().Result; ptPublication newPub = JsonConvert.DeserializeObject <ptPublication>(body); items.Add(newPub); File.WriteAllText(path, JsonConvert.SerializeObject(items)); }
// PUT: api/Publications/5 public void Put(string id, HttpRequestMessage request) { string json = File.ReadAllText(path); var items = JsonConvert.DeserializeObject <List <ptPublication> >(json); string body = request.Content.ReadAsStringAsync().Result; ptPublication updatedPub = JsonConvert.DeserializeObject <ptPublication>(body); int index = items.IndexOf(items.Find(x => x.PublicationId == id)); if (index != -1) { items[index] = updatedPub; } File.WriteAllText(path, JsonConvert.SerializeObject(items)); }
// POST: api/Publications public void Post(HttpRequestMessage request) { string body = request.Content.ReadAsStringAsync().Result; ptPublication p = JsonConvert.DeserializeObject <ptPublication>(body); string sql = "INSERT INTO [pubtrack].[Publication]([PublicationId],[SortId],[Title],[Type],[Series],[Division],[Roles],[Statuses],[Remarks]) VALUES('" + p.PublicationId + "'," + Convert.ToInt32(p.SortId) + ",'" + p.Title + "','" + JsonConvert.SerializeObject(p.Type) + "','" + p.Series + "','" + JsonConvert.SerializeObject(p.Division) + "','" + JsonConvert.SerializeObject(p.Roles) + "','" + JsonConvert.SerializeObject(p.Statuses) + "','" + p.Remarks + "');"; ptsHelper.ExcecuteSql(sql); }
// PUT: api/Publications/5 public void Put(string id, HttpRequestMessage request) { string body = request.Content.ReadAsStringAsync().Result; ptPublication p = JsonConvert.DeserializeObject <ptPublication>(body); string sql = "UPDATE [pubtrack].[Publication] SET " + "[SortId] = " + Convert.ToInt32(p.SortId) + ",[Title] = '" + p.Title + "',[Type] = '" + JsonConvert.SerializeObject(p.Type) + "',[Series] = '" + p.Series + "',[Division] = '" + JsonConvert.SerializeObject(p.Division) + "',[Roles] = '" + JsonConvert.SerializeObject(p.Roles) + "',[Statuses] = '" + JsonConvert.SerializeObject(p.Statuses) + "',[Remarks] = '" + p.Remarks + "' WHERE [PublicationId] = '" + p.PublicationId + "';"; ptsHelper.ExcecuteSql(sql); }
}//End GetAll Users public static List<ptPublication> GetAllPublications() { List<SqlParameter> myParameters = new List<SqlParameter>(); List<ptPublication> items = new List<ptPublication>(); string sql = "Select * from pubtrack.Publication;"; DataSet ds = ExecuteSPDataSetText(sql, conn); foreach (DataRow r in ds.Tables[0].Rows) { ptPublication item = new ptPublication(); item.PublicationId = r["PublicationId"].ToString(); item.SortId = Convert.ToInt32(r["SortId"].ToString()); item.Title = r["Title"].ToString(); item.Type = JsonConvert.DeserializeObject<ptType>(r["Type"].ToString()); item.Series = r["Series"].ToString(); item.Division = JsonConvert.DeserializeObject<ptDivision>(r["Division"].ToString()); item.Roles = JsonConvert.DeserializeObject<List<ptRoles>>(r["Roles"].ToString()); item.Statuses = JsonConvert.DeserializeObject<List<ptStatus>>(r["Statuses"].ToString()); item.Remarks = r["Remarks"].ToString(); items.Add(item); } return items; }//End GetAll