Beispiel #1
0
        public async Task <CountryDtoResult> Put(CountryUpdateV2Dto dto)
        {
            var model     = _mapper.Map <CountryModel>(dto);
            var entity    = _mapper.Map <CountryEntity>(model);
            var oldRecord = await _repository.SelectAsync(entity.Id);

            entity.Name         = oldRecord.Name;
            entity.SvgFile      = oldRecord.SvgFile;
            entity.ObjectJson   = oldRecord.ObjectJson;
            entity.OriginalInfo = false;
            if (entity.OfficialLanguage == null)
            {
                entity.OfficialLanguage = oldRecord.OfficialLanguage;
            }
            var result = await _repository.UpdateAsync(entity);

            return(_mapper.Map <CountryDtoResult>(result));
        }
Beispiel #2
0
        public async Task E_Possivel_Realizar_Crud_Usuario()
        {
            await AdicionarToken();

            _name = Faker.Name.First();

            //Get All
            response = await client.GetAsync($"{hostApi}v2/Countries");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            var jsonResult = await response.Content.ReadAsStringAsync();

            var listaFromJson = JsonConvert.DeserializeObject <IEnumerable <CountryDtoResult> >(jsonResult);

            Assert.NotNull(listaFromJson);
            Assert.True(listaFromJson.Count() > 0);
            Assert.True(listaFromJson.Where(r => r.Name == "Brazil").Count() == 1);

            var updateCountryDto = new CountryUpdateV2Dto()
            {
                Id                = listaFromJson.Where(r => r.Name == "Brazil").FirstOrDefault().Id,
                Area              = 15,
                Capital           = "São Paulo",
                Population        = 123213213,
                PopulationDensity = 321,
                OfficialLanguage  = "Espanhol"
            };

            //PUT
            var stringContent = new StringContent(JsonConvert.SerializeObject(updateCountryDto),
                                                  Encoding.UTF8, "application/json");

            response = await client.PutAsync($"{hostApi}v2/Countries", stringContent);

            jsonResult = await response.Content.ReadAsStringAsync();

            var registroAtualizado = JsonConvert.DeserializeObject <CountryDtoResult>(jsonResult);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal("Brazil", registroAtualizado.Name);
            Assert.Equal("São Paulo", registroAtualizado.Capital);
            Assert.Equal("Espanhol", registroAtualizado.OfficialLanguage);
        }
Beispiel #3
0
        public async Task <ActionResult> Put([FromBody] CountryUpdateV2Dto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await _service.Put(dto);

                if (result != null)
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }