You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.8 KiB
53 lines
1.8 KiB
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace YOUserbase;
|
|
|
|
public partial class UserOverviewPage : ContentPage {
|
|
public int _index = 0;
|
|
|
|
private string details;
|
|
private string firstname;
|
|
private string lastname;
|
|
private string birthDate;
|
|
public string Details { get => details; set => SetProperty(ref details, value); }
|
|
public string Firstname { get => firstname; set => SetProperty(ref firstname, value); }
|
|
public string Lastname { get => lastname; set => SetProperty(ref lastname, value); }
|
|
public string BirthDate { get => birthDate; set => SetProperty(ref birthDate, value); }
|
|
|
|
public UserOverviewPage() {
|
|
InitializeComponent();
|
|
users.ItemsSource = Data.Users;
|
|
}
|
|
|
|
private async void OnAdd(object sender, EventArgs e) {
|
|
await Navigation.PushAsync(new CreateUserPage());
|
|
Console.WriteLine(Data.Users);
|
|
}
|
|
|
|
private async void OnDeleteItem(object sender, EventArgs e) {
|
|
Button btn = (Button) sender;
|
|
var id = Int32.Parse(btn.ClassId);
|
|
var user = Data.Users.FirstOrDefault(usr => usr.Id == id);
|
|
var action = await DisplayAlert("Irreversible action", "Do you really want to delete this user?", "Yes", "No");
|
|
if(action) {
|
|
Data.Users.Remove(user);
|
|
}
|
|
}
|
|
|
|
private async void OnEditItem(object sender, EventArgs e) {
|
|
Button btn = (Button) sender;
|
|
var id = Int32.Parse(btn.ClassId);
|
|
var user = Data.Users.FirstOrDefault(usr => usr.Id == id);
|
|
await Navigation.PushAsync(new CreateUserPage(user));
|
|
}
|
|
|
|
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string propertyName = null) {
|
|
if(!Equals(field, newValue)) {
|
|
field = newValue;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} |