Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ICommand LoginCommand
- {
- get
- {
- return new Command(async () =>
- {
- Message = await _apiServices.LoginAsync(Username, Password);
- if (_apiServices.LastResponse.IsSuccessStatusCode) //login successful?
- {
- // Check if the user details are complete and if not throw up the Edit page.
- if (Settings.DetailsComplete)
- {
- Application.Current.MainPage = new NavigationPage(new HomePage());
- }
- else
- {
- await _apiServices.GetUserDetails(); //Check the details from the server
- Application.Current.MainPage = new NavigationPage(new UserDetails());
- }
- }
- });
- }
- }
- public async Task<bool> GetUserDetails()
- {
- var client = new HttpClient();
- client.DefaultRequestHeaders.Authorization
- = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
- var model = new RGUserDTOModel();
- //Send and respond
- var json = await client.GetStringAsync(ServerURL + UserDetailsEndPoint);
- var userdetails = JsonConvert.DeserializeObject<RGUserDTOModel>(json);
- UpdateUserSettings(userdetails);
- return true; // allows for error handling
- }
- public partial class UserDetails : ContentPage
- {
- public UserDetails()
- {
- InitializeComponent();
- BindingContext = new RGUserViewModel();
- Title = "Update your details";
- }
- }
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- x:Class="xxxxxxGameApp.Views.UserDetails">
- <ContentPage.Content>
- <StackLayout>
- <Label Text="Edit your account details:" />
- <Entry Text="{Binding Email}"
- Placeholder="email"
- FontSize="Large"/>
- <Entry Text="{Binding Id}"
- Placeholder="Id"
- FontSize="Large"/>
- <Entry Text="{Binding Title}"
- Placeholder="Title"
- FontSize="Large"/>
- <Entry Text="{Binding FirstName}"
- Placeholder="FirstName"
- FontSize="Large"/>
- <Entry Text="{Binding MiddleName}"
- Placeholder="MiddleName"
- FontSize="Large"/>
- <Entry Text="{Binding LastName}"
- Placeholder="LastName"
- FontSize="Large"/>
- <Entry Text="{Binding DisplayName}"
- Placeholder="DisplayName"
- FontSize="Large"/>
- <Entry Text="{Binding Password}"
- Placeholder="password"
- IsPassword="False"
- FontSize="Large"/>
- <Button Command="{Binding UpdateCommand}"
- Text="Update Details"
- FontSize="Large"/>
- </StackLayout>
- </ContentPage.Content>
- </ContentPage>
- class RGUserViewModel : INotifyPropertyChanged
- {
- ApiServices _apiServices = new ApiServices();
- RGUserDTOModel DTOmodel = new RGUserDTOModel();
- public event PropertyChangedEventHandler PropertyChanged;
- public void OnPropertyChanged([CallerMemberName] string name = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
- }
- private string Id { get; set; } = Settings.Id;
- public string Email { get; set; } = "5678"; //Settings.Email;
- public string UserName { get; set; } = "1234"; //= Settings.Username;
- public DateTime? DateOfBirth { get; set; } = Settings.DateOfBirth;
- public string Title { get; set; } = Settings.Title;
- public string FirstName { get; set; } = Settings.FirstName;
- public string MiddleName { get; set; } = Settings.MiddleName;
- public string LastName { get; set; } = Settings.LastName;
- public string DisplayName { get; set; } = Settings.DisplayName;
- public string FullName
- {
- get
- {
- return FirstName + (MiddleName != null ? " " + MiddleName : "") + (LastName != null ? " " + LastName : "");
- }
- }
- public bool DetailsComplete { get; set; } = Settings.DetailsComplete;
- private string _message { get; set; } = "No Message";
- public string Message
- {
- get { return _message; }
- set
- {
- if (_message != value)
- {
- _message = value;
- OnPropertyChanged();
- }
- }
- }
- public ICommand UpdateCommand
- {
- get
- {
- return new Command(async () =>
- {
- UpdateDTOmodel(); //Move input to the DTOmodel
- var isSuccess = await _apiServices.UpdateUserDetailAsync(DTOmodel);
- if (isSuccess)
- {
- Message = " Registered Successfully";
- }
- else
- {
- Message = "Update Error : " + Environment.NewLine + _apiServices.ErrorListasString;
- }
- });
- }
- }
- private void UpdateDTOmodel()
- {
- DTOmodel.Id = Id;
- DTOmodel.Title = Title;
- DTOmodel.FirstName = FirstName;
- DTOmodel.MiddleName = MiddleName;
- DTOmodel.LastName = LastName;
- DTOmodel.DisplayName = DisplayName;
- DTOmodel.DateOfBirth = DateOfBirth;
- DTOmodel.UserName = UserName;
- DTOmodel.Email = Email;
- DTOmodel.DetailsComplete = DetailsComplete;
- }
- }
Add Comment
Please, Sign In to add comment