public DetailPage(object item) { InitializeComponent(); if (AppState.CurrentAccessLevel >= 2) { ToolbarItems.Add(new ToolbarItem { Text = "Close Task", Command = new Command(CloseTask), }); } if (!(item is Task task)) { return; } _task = task; if (AppState.Colors.ContainsValue(task.Color)) { RoleColorBox.Color = AppState.Colors.First(x => x.Value == task.Color).Key; } else { RoleColorBox.Color = Color.AliceBlue; } NameLabel.Text = task.Name; DescriptionEditor.Text = task.Description; PriorityLabel.Text = $"{GetPriorityTest(task.Priority)}"; RoleLabel.Text = $"{task.Role}"; CreatedDateLabel.Text = task.CreatedDate.ToString("g"); ExpirationDateLabel.Text = task.ExpirationDate.ToString("g"); if (task.ExpirationDate < DateTime.Now) { OutdatedLabel.IsVisible = true; } }
private async void AddTask() { var name = NameEntry.Text; var description = DescriptionEditor.Text; var priority = PriorityPicker.SelectedIndex; var date = ExpirationDatePicker.Date; var time = ExpirationTimePicker.Time; if (name == "" || priority == -1 || RolePicker.SelectedIndex == -1) { await DisplayAlert("Error", "Not all values set", "OK"); return; } var role = Roles[RolePicker.SelectedIndex]; var color = role.Color; var expirationDateTime = new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds); var task = new Task { Id = Guid.NewGuid().ToString(), CreatedDate = DateTime.Now, Description = description, Name = name, ExpirationDate = expirationDateTime, Priority = priority, Color = color, Role = role.Name, RoleId = role.Id }; TaskHelper.AddTask(task); await Navigation.PopModalAsync(); }