public MainPage()
        {
            if (App.Current.Properties.ContainsKey("Token"))
            {
                viewModel = new ChatViewModel(null);
            }
            InitializeComponent();
            var MyEntry = new Entry {
                Text = "I am an Entry"
            };

            if (App.Current.Properties.ContainsKey("Token"))
            {
                this.BindingContext = this;
                Dictionary <string, string> tokenJson = JsonConvert.DeserializeObject <Dictionary <string, string> >((string)App.Current.Properties["Token"]);
                string             token   = tokenJson["access_token"];
                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage();
                request.RequestUri = new Uri("http://192.168.100.2:3000/Mobile/GetListOfUsers?jwt=" + token);
                request.Method     = HttpMethod.Post;
                request.Headers.Add("Accept", "application/json");
                HttpResponseMessage response = client.SendAsync(request).Result;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    HttpContent      json = response.Content;
                    List <IndexUser> list = JsonConvert.DeserializeObject <List <IndexUser> >(json.ReadAsStringAsync().Result);
                    listView.ItemsSource    = list.Select(x => x.IdentityUser.UserName).ToList();
                    usernameEntry.IsVisible = false;
                    passwordEntry.IsVisible = false;
                    UsernameLabel.Text      = tokenJson["username"];
                    UsernameLabel.FontSize  = 30;
                    UsernameLabel.TextColor = Color.Black;
                    PasswordLabel.IsVisible = false;
                    buttonLogin.IsVisible   = false;
                    buttonLogout.IsVisible  = true;
                }
            }
            else
            {
                buttonLogout.IsVisible = false;
                ListLabel.Text         = "";
            };
        }
Beispiel #2
0
        public Chat()
        {
            Title = "Я - " + (string)App.Current.Properties["Username"] + " для " + (string)App.Current.Properties["toUser"];
            InitializeComponent();
            viewModel           = new ChatViewModel(this);
            this.BindingContext = viewModel;

            Dictionary <string, string> responseJson = JsonConvert.DeserializeObject <Dictionary <string, string> >((string)App.Current.Properties["Token"]);
            HttpClient         client  = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://192.168.100.2:3000/Mobile/GetListOfMessagges?jwt=" + responseJson["access_token"] + "&toUser="******"toUser"]);
            request.Method     = HttpMethod.Post;
            request.Headers.Add("Accept", "application/json");
            HttpResponseMessage response = client.SendAsync(request).Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                HttpContent jsonRespone          = response.Content;
                Dictionary <string, object> json = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonRespone.ReadAsStringAsync().Result);
                JArray a = (JArray)json["messages"];
                foreach (JObject b in a)
                {
                    var         z       = b.ToObject <Dictionary <string, string> >();
                    MessageData message = new MessageData
                    {
                        Message = z["contect"],
                        User    = z["user1Id"]
                    };
                    viewModel.Messages.Add(message);
                }
                ;
                var v = MessagesList.ItemsSource.Cast <object>().LastOrDefault();
                MessagesList.ScrollTo(v, ScrollToPosition.End, true);
            }
            ;
        }