示例#1
0
        private void btnEditAssignment_Click(object sender, EventArgs e)
        {
            Assignment current = clbAssignments.SelectedItem as Assignment;

            formCreateNewAssignment assignmentForm = new formCreateNewAssignment(current.ToDo);

            if (assignmentForm.ShowDialog() == DialogResult.OK)
            {
                Assignment modifiedAssignment = assignmentForm.GetAssignment();
                try
                {
                    using (DBEntities context = new DBEntities())
                    {
                        List <Assignment> assignments = context.Assignments.ToList();
                        foreach (Assignment a in assignments)
                        {
                            if (a.Id == current.Id)
                            {
                                a.ToDo = modifiedAssignment.ToDo;
                                context.SaveChanges();
                                refreshAssignments();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("clbAssignments_SelectedValueChanged\n\n" + ex.ToString());
                }
            }
        }
示例#2
0
        private void btnAddAssignment_Click(object sender, EventArgs e)
        {
            formCreateNewAssignment createNewAssignment = new formCreateNewAssignment();

            if (createNewAssignment.ShowDialog() == DialogResult.OK)
            {
                Project p         = lbProjects.SelectedItem as Project;
                int     projectId = p.Id;

                Assignment a = createNewAssignment.GetAssignment();
                a.ProjectId = projectId;

                try
                {
                    using (DBEntities context = new DBEntities())
                    {
                        context.Assignments.Add(a);
                        context.SaveChanges();
                    }

                    this.refreshAssignments();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("btnAddAssignment_click\n\n" + ex.ToString());
                }
            }
        }