コード例 #1
0
        public IActionResult Update(int countryId, int id, [FromBody] OfficialLanguagesByCountryForUpdateDTO officialLanguages)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var country = CountriesDataStore.Current.Countries.SingleOrDefault(x => x.Id == countryId);

            if (country == null)
            {
                return(NotFound());
            }

            var languaguesStore = country.OfficialLanguages.SingleOrDefault(x => x.Id == id);

            if (languaguesStore == null)
            {
                return(NotFound());
            }

            Languages.UpdateLanguage(languaguesStore, officialLanguages);


            return(NoContent());
        }
コード例 #2
0
        public IActionResult Patch(int countryId, int id, [FromBody] JsonPatchDocument <OfficialLanguagesByCountryForUpdateDTO> patchLanguage)
        {
            if (patchLanguage == null)
            {
                return(BadRequest());
            }

            var country = CountriesDataStore.Current.Countries.SingleOrDefault(x => x.Id == countryId);

            if (country == null)
            {
                return(NotFound());
            }

            var languaguesStore = country.OfficialLanguages.SingleOrDefault(x => x.Id == id);

            if (languaguesStore == null)
            {
                return(NotFound());
            }

            var languaguesToPatch = new OfficialLanguagesByCountryForUpdateDTO()
            {
                LanguageName = languaguesStore.LanguageName
            };

            patchLanguage.ApplyTo(languaguesToPatch, ModelState);

            var isValid = TryValidateModel(languaguesToPatch);

            if (!isValid)
            {
                return(BadRequest(ModelState));
            }

            Languages.UpdateLanguage(languaguesStore, languaguesToPatch);

            return(NoContent());
        }
コード例 #3
0
        public static OfficialLanguagesByCountryDTO UpdateLanguage(OfficialLanguagesByCountryDTO languaguesStore, OfficialLanguagesByCountryForUpdateDTO officialLanguages)
        {
            languaguesStore.LanguageName = officialLanguages.LanguageName;

            return(languaguesStore);
        }