public TaskMaster() { InitializeComponent(); dbContext = new tmDbContext(); var statuses = dbContext.Statuses.ToList(); foreach (var s in statuses) { cbStatuses.Items.Add(s); } RefreshData(); }
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 = ""; }