// GET api/<controller>/5 public string Get(string value) { var rawValue = JsonConvert.DeserializeObject<Dictionary<string, object>>(value); var tableSource = rawValue["ListType"].ToString(); var parameters = new Dictionary<string, object>(); if (tableSource == "year") { var result = dataBL.GetTable(StoredProcedure.ArchiveYearDdl); var table = JsonConvert.SerializeObject(result.Tables[0]); return table; } else { parameters.Add("@flu_years", rawValue["flu_years"]); var result = dataBL.GetTable(StoredProcedure.ArchiveList, parameters); var archives = new JSArchive().ConvertTableToList(result.Tables[0]); var table = JsonConvert.SerializeObject(archives); return table; } }
public List<JSArchive> ConvertTableToList(DataTable table) { try { var list = new List<JSArchive>(); foreach (DataRow i in table.Rows) { var item = new JSArchive { archive_id = Convert.ToInt32(i["archive_id"].ToString()), flu_year = Convert.ToInt32(i["flu_year"].ToString()), flu_week = Convert.ToInt32(i["flu_week"].ToString()), archive_link = ConfigurationManager.AppSettings["ArchiveLocation"] + i["flu_year"].ToString() + "-" + i["flu_week"].ToString() + ".pdf" }; list.Add(item); } return list; } catch (Exception ex) { throw ex; } }