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.
59 lines
1.9 KiB
59 lines
1.9 KiB
namespace YOUserbase;
|
|
|
|
public partial class CreateGroupPage : ContentPage {
|
|
|
|
private Group group;
|
|
|
|
public CreateGroupPage() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
public CreateGroupPage(Group group) {
|
|
InitializeComponent();
|
|
this.group = group;
|
|
NameEntry.Text = group.Name;
|
|
DetailsEntry.Text = group.Details;
|
|
btnCreate.Text = "Save";
|
|
contentPage.Title = "Edit user";
|
|
}
|
|
|
|
private void OnCreateClicked(object sender, EventArgs e) {
|
|
var isValid = true;
|
|
string text = NameEntry.Text;
|
|
errName.Text = "";
|
|
if(String.IsNullOrWhiteSpace(text)) {
|
|
isValid = false;
|
|
errName.Text = "First name cannot be empty";
|
|
} else if(text.Length > 20) {
|
|
isValid = false;
|
|
errName.Text = "First name cannot be longer than 20 characters";
|
|
}
|
|
text = DetailsEntry.Text;
|
|
errDetails.Text = "";
|
|
if(String.IsNullOrWhiteSpace(text)) {
|
|
isValid = false;
|
|
errDetails.Text = "Last name cannot be empty";
|
|
} else if(text.Length > 500) {
|
|
isValid = false;
|
|
errDetails.Text = "Last name cannot be longer than 20 characters";
|
|
}
|
|
errAll.Text = "";
|
|
if(Data.Groups.Where(x => x.Name == NameEntry.Text).Any()) {
|
|
isValid = false;
|
|
errAll.Text = "Group with the same name already exists";
|
|
}
|
|
if(isValid) {
|
|
if(group != null) { // Update
|
|
var grp = Data.Groups.FirstOrDefault(gr => gr.Id == group.Id);
|
|
grp.Name = NameEntry.Text;
|
|
grp.Details = DetailsEntry.Text;
|
|
} else { // Create
|
|
Data.Groups.Add(new Group {
|
|
Name = NameEntry.Text,
|
|
Details = DetailsEntry.Text,
|
|
});
|
|
}
|
|
Navigation.PopAsync();
|
|
}
|
|
}
|
|
} |