add method getAllLanguages

parent 95aa5d01
......@@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="JsonTranslator.cs" />
<Compile Include="Languages.cs" />
<Compile Include="Models\Language.cs" />
<Compile Include="Traductor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
......
using System;
using Api.Business.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
......@@ -7,9 +8,9 @@ namespace Api.Business
{
public static class Languages
{
public static Dictionary<string, string> getAllLanguages()
public static ICollection<Language> getAllLanguages()
{
Dictionary<string, string> response = null;
ICollection<Language> response = null;
string connectionString = "Server = languagesDat.mssql.somee.com; Database = languagesDat; User ID = torgaiv3_SQLLogin_1; Password = nz53hhpc22; Trusted_Connection = False;";
......@@ -22,14 +23,15 @@ namespace Api.Business
if (dr.HasRows)
{
response = new Dictionary<string, string>();
response = new List<Language>();
while (dr.Read())
{
response.Add(
Convert.ToString(dr["id"]),
Convert.ToString(dr["value"])
);
response.Add(new Language()
{
LanguageCode = Convert.ToString(dr["id"]),
LanguageDescription = Convert.ToString(dr["value"])
});
}
}
}
......
using System;
namespace Api.Business.Models
{
[Serializable]
public class Language
{
public string LanguageCode { get; set; }
public string LanguageDescription { get; set; }
}
}
......@@ -44,6 +44,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
......
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Web.Services;
namespace Api.Traductor
......@@ -9,7 +9,6 @@ namespace Api.Traductor
public class ServicioRest : System.Web.Services.WebService
{
[WebMethod]
public string Translate(string input, string langFrom, string langTo)
{
......@@ -34,7 +33,13 @@ namespace Api.Traductor
throw new System.Exception("El campo lenguaje destino no puede estar vacío");
return Api.Business.JsonTranslator.TranslateJson(input, langFrom, langTo);
}
[WebMethod]
public string getAllLanguages()
{
var jsonSerialiser = new JavaScriptSerializer();
return jsonSerialiser.Serialize(Api.Business.Languages.getAllLanguages());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment