private void ListOfTasks_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ListOfTasks.SelectedItems.Count == 0) { return; } LastSelectedTask = ((sender as ListBox).SelectedItem as TaskListItem).Task; taskNameTB.Text = LastSelectedTask.Name; dueDateDP.SelectedDate = LastSelectedTask.DueDate; descriptionTB.Text = LastSelectedTask.Description; isActiveBtn.Content = LastSelectedTask.IsActive ? "Сделать неактивной" : "Сделать активной"; isCompletedBtn.Content = LastSelectedTask.IsCompleted ? "Сделать невыполненной" : "Выполнить"; using (TaskListDB db = new TaskListDB()) { if (LastListPicked == "AssignedByMeTasks") { assignedCB.SelectedValue = LastSelectedTask.IDTo; } else { assignedCB.SelectedValue = LastSelectedTask.IDFrom; } } }
public TaskListItem(DB.Task task, bool isAssignedByMe) { Task = task; IsCompleted = task.IsCompleted; Name = task.Name; if (isAssignedByMe) { AssignedUser = $"{task.UserTo.FirstName} {task.UserTo.LastName}"; } else { AssignedUser = $"{task.UserFrom.FirstName} {task.UserFrom.LastName}"; } DueDate = task.DueDate.ToString(); }
private void saveBtn_Click(object sender, RoutedEventArgs e) { if (ListOfTasks.SelectedItems.Count == 0) { MessageBox.Show("Сначала выберите задачу!"); return; } LastSelectedTask.Name = taskNameTB.Text; LastSelectedTask.Description = descriptionTB.Text; LastSelectedTask.DueDate = dueDateDP.SelectedDate; using (TaskListDB db = new TaskListDB()) { if (Convert.ToInt32(assignedCB.SelectedValue) != user.ID) { DB.Task task = new DB.Task(); task.Name = LastSelectedTask.Name; task.IDFrom = LastSelectedTask.IDFrom; task.IDTo = Convert.ToInt32(assignedCB.SelectedValue); task.IsActive = LastSelectedTask.IsActive; task.IsCompleted = LastSelectedTask.IsCompleted; task.DueDate = LastSelectedTask.DueDate; task.Description = LastSelectedTask.Description; db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Deleted; db.Tasks.Add(task); } else { db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); } UpdateLastList(); }