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.
YOUserbase/GroupOverviewPage.xaml.cs

60 lines
1.7 KiB

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace YOUserbase;
public partial class GroupOverviewPage : ContentPage {
public int _index = 0;
private string details;
private string name;
public string Details { get => details; set => SetProperty (ref details, value); }
public string Name { get => name; set => SetProperty (ref name, value); }
public GroupOverviewPage ()
{
InitializeComponent ();
groups.ItemsSource = Data.Groups;
}
private async void OnAdd (object sender, EventArgs e)
{
await Navigation.PushAsync (new CreateGroupPage ());
}
private async void OnDeleteItem (object sender, EventArgs e)
{
Button btn = (Button)sender;
var id = Int32.Parse (btn.ClassId);
var group = Data.Groups.FirstOrDefault (usr => usr.Id == id);
var action = await DisplayAlert ("Irreversible action", "Do you really want to delete this group?\nThis will also delete every User that that belongs to this group", "Yes", "No");
if (action) {
while (Data.Users.FirstOrDefault (usr => usr.WorkingGroup == group) != null) {
Data.Users.Remove (Data.Users.FirstOrDefault (usr => usr.WorkingGroup == group));
}
Data.Groups.Remove (group);
}
}
private async void OnEditItem (object sender, EventArgs e)
{
Button btn = (Button)sender;
var id = Int32.Parse (btn.ClassId);
var group = Data.Groups.FirstOrDefault (usr => usr.Id == id);
Console.WriteLine("there");
await Navigation.PushAsync(new CreateGroupPage(group));
Console.WriteLine("and there");
}
protected bool SetProperty<T> (ref T field, T newValue, [CallerMemberName] string propertyName = null)
{
if (!Equals (field, newValue)) {
field = newValue;
return true;
}
return false;
}
}