コード例 #1
0
        public List <UfDto> BuscarUfs()
        {
            var resposta = new ConexaoHttpClient().GetResponse("https://servicodados.ibge.gov.br/api/v1/localidades/estados");

            if (resposta.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(null);
            }

            var content = resposta.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <List <UfDto> >(content.Result));
        }
コード例 #2
0
        public List <MunicipioDto> BuscarMunicipiosDaUf(int uf)
        {
            var resposta = new ConexaoHttpClient().GetResponse(string.Format("https://servicodados.ibge.gov.br/api/v1/localidades/estados/{0}/municipios", uf));

            if (resposta.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(null);
            }

            var content = resposta.Content.ReadAsStringAsync();

            File.WriteAllText("c:/temp/teste.txt", content.Result);
            return(JsonConvert.DeserializeObject <List <MunicipioDto> >(content.Result));
        }
コード例 #3
0
        private async Task UpdateAndRefreshViewCommandAsync()
        {
            try
            {
                IsRefreshing = true;

                var user = _sessionService.GetUser();

                var newsUpdated = await ConexaoHttpClient.GetByDateAsync(user.NoticeLastUpdate, _cancellationToken);

                user.SetNoticeUpdated();

                await _userRepository.UpdateAsync(user);

                var idDeletedNews = newsUpdated.Where((n) => n.State.Equals(UserNoticeState.Removed))
                                    .Select((n) => n.Id)
                                    .ToArray();

                await _noticeRepository.RemoveAsync(idDeletedNews)
                .ConfigureAwait(false);

                var idUpdatedNews = newsUpdated.Where((n) => n.State.Equals(UserNoticeState.Modified))
                                    .Select((n) => n.Id)
                                    .ToArray();

                var noticesToUpdated = await _noticeRepository.GetAsync(idUpdatedNews)
                                       .ConfigureAwait(false);

                //TODO: Por enquanto não vou implementar as atualizações de noticias, não vamos ter atualização de feeds.

                var newNotices = newsUpdated
                                 .Where((n) => !noticesToUpdated.Any((notice) => notice.Id == n.Id))
                                 .ToList();

                var noticesToInclude = newNotices.Union(newsUpdated.Where((n) => n.State == UserNoticeState.Included))
                                       .Select((n) => new Notice
                {
                    Id         = n.Id,
                    Posted     = n.Posted,
                    Image      = n.Image,
                    Message    = n.Message,
                    IdPostedBy = n.IdPostedBy,
                    PostedBy   = new Person(n.PostedBy.Id, n.PostedBy.Email, n.PostedBy.ProfileImage, n.PostedBy.Name)
                })
                                       .ToList();

                await _noticeRepository.InsertAsync(noticesToInclude)
                .ConfigureAwait(false);

                News = await _noticeRepository.GetAsync()
                       .ConfigureAwait(false);

                OnPropertyChanged(nameof(this.News));
            }
            catch (UnauthorizedException)
            {
                await _navigation.PushAsync(new AutenticationView());
            }
            catch (Exception ex)
            {
                Log.Warning(nameof(HomeViewModel), ex.Message);

                await _popupService.ShowErrorMessageAsync(ConexaoHttpClient.PrettyMessage);
            }

            IsRefreshing = false;
        }