public GoalForm(BussinessObject.Entities.Task task, ObservableCollection <BussinessObject.Entities.Task> weekyList) { InitializeComponent(); this.weekyList = weekyList; this.task = task; txtTitle.Text = task.Title; txtDescription.Text = task.Description; nodeList = new ObservableCollection <BussinessObject.Entities.Task>(); lvNodeTask.ItemsSource = nodeList; lvNodeTaskOld.ItemsSource = task.Items; btnAdd.Visibility = Visibility.Hidden; lvNodeTaskOld.Visibility = Visibility.Visible; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (!validInput()) { return; } WeekyTaskData weekyTaskData = new WeekyTaskData(); BussinessObject.Entities.Task roottask = new BussinessObject.Entities.Task() { Title = txtTitle.Text, Description = txtDescription.Text }; if (weekyTaskData.SaveRootTask(roottask)) { weekyList.Add(roottask); try { DataTable dtId = weekyTaskData.GetInsertTaskId(); roottask.Id = dtId.Select()[0].ItemArray[0] as dynamic; foreach (dynamic node in nodeList) { node.SuperTask = roottask.Id; if (weekyTaskData.SaveNodeTask(node)) { dtId = weekyTaskData.GetInsertTaskId(); node.Id = dtId.Select()[0].ItemArray[0] as dynamic; roottask.Items.Add(node); } } this.Close(); } catch (Exception ex) { tbMessage.Text = "Something fail! Please try again."; } } else { tbMessage.Text = "Add fail! Please try again."; } }