Esempio n. 1
0
        public List<JSVirodata> ConvertToTableToList(DataTable table)
        {
            var list = new List<JSVirodata>();
            try
            {
                foreach (DataRow i in table.Rows)
                {

                    //CultureInfo ci = new CultureInfo("en-GB");
                    //var start = DateTime.Parse(i["FLU_SDate"].ToString());
                    //var forcedParse = new DateTime(start.Year,start.Month,start.Day);
                    //var sdate = forcedParse.ToString("dd MMM yyyy", ci);
                    //start = DateTime.Parse(i["FLU_EDate"].ToString());
                    //forcedParse = new DateTime(start.Year, start.Month, start.Day);
                    //var edate = forcedParse.ToString("dd MMM yyyy", ci);

                    var sdate = string.Empty;
                    var edate = string.Empty;
                    var forcedParse = new DateTime();
                    CultureInfo ci = new CultureInfo("en-GB");
                    if (i["FLU_SDate"].ToString() != string.Empty)
                    {
                        var start = DateTime.Parse(i["FLU_SDate"].ToString());
                        forcedParse = new DateTime(start.Year, start.Month, start.Day);
                        sdate = forcedParse.ToString("dd MMM yyyy", ci);

                    }

                    if (i["FLU_EDate"].ToString() != string.Empty)
                    {
                        var end = DateTime.Parse(i["FLU_EDate"].ToString());
                        forcedParse = new DateTime(end.Year, end.Month, end.Day);
                        edate = forcedParse.ToString("dd MMM yyyy", ci);
                    }
                    var item = new JSVirodata
                    {
                        COUNTRY_TITLE = i["COUNTRY_TITLE"].ToString(),
                        REPORTSITE_CODE = i["REPORTSITE_CODE"].ToString(),
                        LAB_NAME = i["LAB_NAME"].ToString(),
                        FLUREGION = i["FLUREGION"].ToString(),
                        FLU_SDate = sdate,
                        FLU_EDate = edate,
                        EPI_YEAR = i["EPI_YEAR"].ToString(),
                        EPI_WEEK = i["EPI_WEEK"].ToString(),
                        AH1 = i["AH1"].ToString(),
                        AH3 = i["AH3"].ToString(),
                        AH5 = i["AH5"].ToString(),
                        AH1N12009 = i["AH1N12009"].ToString(),
                        ANOTSUBTYPED = i["ANOTSUBTYPED"].ToString(),
                        AOTHER_SUBTYPE = i["AOTHER_SUBTYPE"].ToString(),
                        BVICTORIA = i["BVICTORIA"].ToString(),
                        BYAMAGATA = i["BYAMAGATA"].ToString(),
                        BNOTDETERMINED = i["BNOTDETERMINED"].ToString(),
                        INF_A = i["INF_A"].ToString(),
                        INF_B = i["INF_B"].ToString(),
                        ALL_INF = i["ALL_INF"].ToString()
                    };

                    list.Add(item);
                }

                return list;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        // GET api/<controller>
        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 == "avian")
                {
                    if(rawValue.ContainsKey("pathogen_ids"))
                    {
                        parameters.Add("@pathogen_ids", rawValue["pathogen_ids"]);
                    }
                    else
                        parameters.Add("@pathogen_ids", string.Empty);


                    if (rawValue.ContainsKey("ctry_code"))
                    {
                        parameters.Add("@ctry_codes", rawValue["ctry_code"]);
                    } 
                    else
                        parameters.Add("@ctry_codes", string.Empty);

                    if(rawValue.ContainsKey("flu_years"))
                    {
                        parameters.Add("@flu_years", rawValue["flu_years"]);
                    }
                    else
                        parameters.Add("@flu_years", string.Empty);
                        
                    var result = dataBL.GetTable(StoredProcedure.TLinelist, parameters);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    var columns = dataBL.GetColumns(StoredProcedure.TLinelist);
                    var data = new Dictionary<string, string>();
                    data.Add("table", table);
                    data.Add("columns", JsonConvert.SerializeObject(columns));
                    return JsonConvert.SerializeObject(data);
                }
                else if (tableSource == "avian2")
                {
                    if (rawValue.ContainsKey("pathogen_ids"))
                    {
                        parameters.Add("@pathogen_ids", rawValue["pathogen_ids"]);
                    }
                    else
                        parameters.Add("@pathogen_ids", string.Empty);


                    if (rawValue.ContainsKey("ctry_code"))
                    {
                        parameters.Add("@ctry_codes", rawValue["ctry_code"]);
                    }
                    else
                        parameters.Add("@ctry_codes", string.Empty);

                    if (rawValue.ContainsKey("flu_years"))
                    {
                        parameters.Add("@flu_years", rawValue["flu_years"]);
                    }
                    else
                        parameters.Add("@flu_years", string.Empty);

                    var result = dataBL.GetTable(StoredProcedure.Linelist, parameters);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    var columns = dataBL.GetColumns(StoredProcedure.Linelist);
                    var data = new Dictionary<string, string>();
                    data.Add("table", table);
                    data.Add("columns", JsonConvert.SerializeObject(columns));
                    return JsonConvert.SerializeObject(data);
                }
                else if (tableSource == "avian_country")
                {
                    var result = dataBL.GetTable(StoredProcedure.Linelist_Ctry_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);
                }
                else if (tableSource == "avian_year")
                {
                    var result = dataBL.GetTable(StoredProcedure.Linelist_Year_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);
                }
                else if (tableSource == "avian_pathogen")
                {
                    var result = dataBL.GetTable(StoredProcedure.Linelist_Pathogen_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);
                }
                else if (tableSource == "Virological")
                {
                    if (rawValue.ContainsKey("ctry_codes"))
                    {
                        parameters.Add("@ctry_codes", rawValue["ctry_codes"]);
                    }
                    else
                        parameters.Add("@ctry_codes", string.Empty);

                    if (rawValue.ContainsKey("flu_years"))
                    {
                        parameters.Add("@flu_years", rawValue["flu_years"]);
                    }
                    else
                        parameters.Add("@flu_years", string.Empty);

                    var tableRaw = new JSVirodata().ConvertToTableToList(dataBL.GetTable(StoredProcedure.ViroList, parameters).Tables[0]).Take(4000);
                    var serializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                    var table = serializer.Serialize(tableRaw);
                    var columns = dataBL.GetColumns(StoredProcedure.ViroList);
                    var data = new Dictionary<string, string>();
                    data.Add("table", table);
                    data.Add("columns", JsonConvert.SerializeObject(columns));
                    return JsonConvert.SerializeObject(data);
                }
                else if (tableSource == "viro_country")
                {
                    var result = dataBL.GetTable(StoredProcedure.Viro_Ctry_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);
                }
                else if (tableSource == "viro_year")
                {
                    var result = dataBL.GetTable(StoredProcedure.Viro_Year_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);

                }
                else if (tableSource == "Epidemiological")
                {
                    if (rawValue.ContainsKey("ctry_codes"))
                    {
                        parameters.Add("@ctry_codes", rawValue["ctry_codes"]);
                    }
                    else
                        parameters.Add("@ctry_codes", string.Empty);

                    if (rawValue.ContainsKey("flu_years"))
                    {
                        parameters.Add("@flu_years", rawValue["flu_years"]);
                    }
                    else
                        parameters.Add("@flu_years", string.Empty);
              

                   var result = dataBL.GetTable(StoredProcedure.EpiData, parameters);


                    //var table = JsonConvert.SerializeObject(result.Tables[0]);
                    var tableRaw = new JSEpidata().ConvertToTableToList(result.Tables[0]).Take(4000);
                    var serializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                    var table = serializer.Serialize(tableRaw);
                    var columns = dataBL.GetColumns(StoredProcedure.EpiData);
                    var data = new Dictionary<string, string>();
                    data.Add("table", table);
                    data.Add("columns", JsonConvert.SerializeObject(columns));
                    
                    return JsonConvert.SerializeObject(data);
                }
                else if (tableSource == "epi_country")
                {
                    var result = dataBL.GetTable(StoredProcedure.EpiData_Ctry_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);
                }
                else if (tableSource == "epi_year")
                {
                    var result = dataBL.GetTable(StoredProcedure.EpiData_Year_Ddl);
                    var table = JsonConvert.SerializeObject(result.Tables[0]);
                    return JsonConvert.SerializeObject(table);

                }
                else if (tableSource == "epi_data")
                {
                    if (rawValue.ContainsKey("ctry_codes"))
                    {
                        parameters.Add("@ctry_codes", rawValue["ctry_codes"]);
                    }
                    else
                        parameters.Add("@ctry_codes", string.Empty);

                    if (rawValue.ContainsKey("flu_years"))
                    {
                        parameters.Add("@flu_years", rawValue["flu_years"]);
                    }
                    else
                        parameters.Add("@flu_years", string.Empty);


                    var id = Convert.ToInt32(rawValue.ContainsKey("id"));

                    var result = dataBL.GetTable(StoredProcedure.EpiData, parameters);
                    var table = new JSEpidata().ConvertToTableToList(result.Tables[0])
                                .Where(e => e.epi_wide_id == id);
                    var response = JsonConvert.SerializeObject(table);

                    return response;
                }
                else if (tableSource == "recent_update")
                {
                    var result = ActionHelper.GetActions(ActionsLog.Publish.ToString(), ActionModule.Linelist.ToString());
                    var response = JsonConvert.SerializeObject(result.Rows[0].Table);

                    return response;

                }
              

                return string.Empty;
        }