Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 1.72 KB

GET-translation-keyvalue.md

File metadata and controls

65 lines (53 loc) · 1.72 KB

GET - api/translation/keyvalue

Last updated: 04.08.17 by Jonas Solsvik

Request example

HTTP Method

GET

URL

http://localhost:5000/api/translation/keyvalue/? clientKey=Ordbase
                                               & languageKey=
                                               &containerKey=error_messages
                                               & translationKey=

JSON Response

[
    {
        "key": "error_create_client",
        "value": "Failed to create client. Client may already exist"
    },
    {
        "key": "error_create_client",
        "value": "Fikk ikke til å lage ny klient. Klienten finnes kanskje fra før?"
    }
]

Response type

    [] KeyValuePair<string, string>

Implementation draft - asp.net core mvc 1.1.2

TranslationController.cs

[HttpGet("api/translation/keyvalue")]
public IEnumerable<KeyValuePair<string,string>> GetKeyValue([FromQuery] TranslationQuery query)
{
    return _translationRepo.GetKeyValue(query); 
}

TranslationRepository.cs

public IEnumerable<KeyValuePair<string,string>> GetKeyValue (TranslationQuery query) 
{
    return (from t in _context.Translation
            where t.ClientKey    == query.ClientKey      || query.ClientKey      == null 
            where t.LanguageKey  == query.LanguageKey    || query.LanguageKey    == null
            where t.ContainerKey == query.ContainerKey   || query.ContainerKey   == null
            where t.Key          == query.TranslationKey || query.TranslationKey == null
            select new KeyValuePair<string,string>(t.Key, t.Text)).ToArray();            
}