Ejemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvTasks.SelectedRows.Count <= 0)
            {
                MessageBox.Show("Please select a row before clicking delete"); return;
            }
            var t = dbContext.Tasks.Find(dgvTasks.SelectedCells[0].Value);

            dbContext.Tasks.Remove(t);
            dbContext.SaveChanges();
            RefreshData();
        }
Ejemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtTask.Text))
            {
                MessageBox.Show("Please enter task before clicking Create button!");
                return;
            }
            if (cbStatuses.SelectedItem == null)
            {
                MessageBox.Show("Please select a status for the task!");
                return;
            }
            var dbContext = new tmDbContext();
            var status    = (cbStatuses.SelectedItem as Status);
            var newTask   = new Models.Task {
                Name = txtTask.Text, DueDate = dtDueDate.Value, StatusId = status.Id
            };

            dbContext.Tasks.Add(newTask);
            dbContext.SaveChanges();
            RefreshData();
            txtTask.Text = "";
        }