List <TTask> GetTTasks(List <Task> tasks) { List <TTask> TTask = new List <TTask>(); using (var db = new TaskContext()) { foreach (Task task in tasks) { TaskStatus status = db.TaskStatuses.Where(x => x.Id == task.StatusId).FirstOrDefault(); TaskPriority priority = db.TaskPriorities.AsNoTracking().Where(x => x.Id == task.PriorityId).FirstOrDefault(); string date = getDate(task); TTask.Add(new DataModel.TTask { Id = task.Id, PriorityId = priority.Id, StatusId = status.Id, TaskContent = task.TaskContent, TaskDate = date, TaskName = task.TaskName, TaskPriority = priority.PriorityName, TaskStatus = status.StatusName }); } } return(TTask); }
private void btnSave_Click(object sender, EventArgs e) { string title = txtTaskTitle.Text; string detail = txtTaskDetail.Text; TaskPriority priority = (TaskPriority)Enum.Parse(typeof(TaskPriority), cmbPriority.SelectedItem.ToString()); int selectedTaskId; int.TryParse(lblSelectedTask.Text, out selectedTaskId); BaseTask task; if (selectedTaskId > 0) { int assignToUserId = (cmbUsers.SelectedItem as User).Id; //ToDo: Call Business Logic Service TaskManagerService Method AssignATask to Assign an User to the Task. selectedTask = taskManagerService.AssignATask(selectedTask, assignToUserId); var status = (TaskManagerBusinessLogic.BusinessEntities.TaskStatus)Enum.Parse(typeof(TaskManagerBusinessLogic.BusinessEntities.TaskStatus), cmbStatus.SelectedItem.ToString()); if (status == TaskManagerBusinessLogic.BusinessEntities.TaskStatus.Closed) { string closingComments = txtClosingComments.Text; //ToDo: Call Business Logic Service TaskManagerService Method ResolveTask to Resolve a Task with comment. selectedTask = taskManagerService.ResolveTask(selectedTask, $"Resolved with comments: {closingComments}"); } else { //ToDo: Call Business Logic Service TaskManagerService Method UpdateStatus to Update Status of a Task selectedTask = taskManagerService.UpdateStatus(selectedTask, status); } } else { //ToDo: Call Business Logic Service TaskManagerService Method CreateATask to create a new Task task = taskManagerService.CreateATask(title, detail, priority, chkInternalTask.Checked); } ClearData(); BindAllTasks(); }
private void PopulateTasksInGridView() { var allTasksInProject = FindTasksInProject(_selectedProjectId).OrderBy(x => x.IsDone).ToList(); _allTasksInProject = new BindingList <TaskInGridView>(allTasksInProject); taskGrid.DataSource = _allTasksInProject; taskGrid.AutoGenerateColumns = false; // Second time in this method, we need to remove the priority combobox column, because it's added again later _gridUtils.RemoveColumn("Priority"); _gridUtils.RemoveColumn("Id"); _gridUtils.RemoveColumn("ProjectId"); _gridUtils.RemoveColumn("Priority"); _gridUtils.RemoveColumn("Note"); if (taskGrid.Columns.Contains("Title")) { taskGrid.Columns["Title"].ReadOnly = true; } if (taskGrid.Columns.Contains("Deadline")) { taskGrid.Columns["Deadline"].ReadOnly = true; } if (taskGrid.Columns.Contains("IsDone")) { DataGridViewColumn isDoneColumn = taskGrid.Columns["IsDone"]; isDoneColumn.HeaderText = "Done"; isDoneColumn.Name = "Done"; } int indexOfHasNoteColumn; if (!taskGrid.Columns.Contains("HasNote")) { DataGridViewCheckBoxColumn hasNoteColumn = new DataGridViewCheckBoxColumn(); hasNoteColumn.ReadOnly = true; hasNoteColumn.HeaderText = "Has Note"; hasNoteColumn.Name = "HasNote"; indexOfHasNoteColumn = taskGrid.Columns.Add(hasNoteColumn); } else { var hasNoteColumn = taskGrid.Columns["HasNote"]; indexOfHasNoteColumn = hasNoteColumn.Index; } DataGridViewComboBoxColumn priorityColumn = new DataGridViewComboBoxColumn(); priorityColumn.HeaderText = "Priority"; priorityColumn.Name = "Priority"; var indexOfPriorityColumn = taskGrid.Columns.Add(priorityColumn); priorityColumn.DataSource = TaskPriority.GetAll().Select(x => x.DisplayName).ToList(); if (!_allTasksInProject.Any()) { if (NoTaskSelected != null) { var eventArgs = new NoTaskSelectedEventArgs(); NoTaskSelected(this, eventArgs); } return; } for (int i = 0; i < taskGrid.RowCount; i++) { var row = taskGrid.Rows[i]; row.Cells[indexOfHasNoteColumn].Value = !string.IsNullOrWhiteSpace(_allTasksInProject[i].Note); row.Cells[indexOfPriorityColumn].Value = _allTasksInProject[i].Priority; var task = (TaskInGridView)row.DataBoundItem; if (task != null && task.IsDone) { _gridUtils.FadeOut(i); } } var rowToBeSelected = taskGrid.Rows[0]; rowToBeSelected.Selected = true; taskGrid.CurrentCell = rowToBeSelected.Cells[0]; }