private async void LoadUsersInformation() { var user = new AuthenticationModel(); var applicationState = new ClockResponseModel(); string jsonProfilePictureUrl = null; var model = new LoginModel { Email = await Constants.GetEmail(), Password = await Constants.GetPassword() }; try { user = await _userService.LoginAsync(model); jsonProfilePictureUrl = await _userService.GetProfilePictureUrl(model.Email); applicationState = await _userService.GetApplicationState(model.Email); } catch (Exception ex) { await DisplayAlert("Error", ex.Message, "OK"); } if (user != null && user.IsAuthenticated) { Constants.RemoveAll(); Constants.SaveUsersDetails(model); labelName.Text = user.Name; labelEmail.Text = user.Email; if (jsonProfilePictureUrl != null) { Dictionary <string, string> objectProfile = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonProfilePictureUrl); Uri uri = new Uri(String.Format(Constants.EcsApiUrl + "images/" + objectProfile["pic"], string.Empty)); entryProfilePic.Source = ImageSource.FromUri(uri); } else { entryProfilePic.BackgroundColor = Color.AliceBlue; } if (applicationState != null && applicationState.Succeeded) { if (applicationState.IsClockActive) { buttonClock.Text = "Clock Out"; buttonClock.BackgroundColor = Color.Red; } else { buttonClock.Text = "Clock In"; buttonClock.BackgroundColor = Color.FromHex("#77D065"); } } } else { Navigation.InsertPageBefore(new LoginPage(), this); await Navigation.PopAsync(); } }
public async Task <ClockResponseModel> GetApplicationState(string email) { Uri uri = new Uri(String.Format(Constants.EcsApiUrl + "api/user/application-state", string.Empty)); string json = JsonConvert.SerializeObject(email); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { string responseContent = await response.Content.ReadAsStringAsync(); ClockResponseModel responseModel = JsonConvert.DeserializeObject <ClockResponseModel>(responseContent); return(responseModel); } return(null); }
private async void ClockUser() { var clockModel = new ClockModel(); var result = new ClockResponseModel(); var usersLocation = await GetUsersLocationAsync(); if (usersLocation != null) { clockModel.Email = await Constants.GetEmail(); clockModel.ClockLocation = usersLocation; clockModel.ClockTime = DateTime.UtcNow.AddHours(3); if (buttonClock.Text == "Clock In") { result = await _userService.ClockInAsync(clockModel); if (result != null && result.Succeeded) { buttonClock.Text = "Clock Out"; buttonClock.BackgroundColor = Color.Red; await DisplayAlert("Success", "Clocked In Successfully", "OK"); } } else { result = await _userService.ClockOutAsync(clockModel); if (result != null && result.Succeeded) { buttonClock.Text = "Clock In"; buttonClock.BackgroundColor = Color.FromHex("#77D065"); await DisplayAlert("Success", "Clocked Out Successfully", "OK"); } } } }