//private void btnSubmit_Click(object sender, EventArgs e) //{ //} //private void btnSubmit_Click(object sender, EventArgs e) //{ // try // { // _ctx.SaveChanges(); // MessageBox.Show("Changes written to the Database"); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } //} #endregion Keywords #region Xrefs private void btnLinkXrefs_Click(object sender, EventArgs e) { //Add new project/Xref pair(s) to the ProjectsKeyword source int ProjectId; //Get the selected row in the Projects DGV DataGridViewSelectedRowCollection projectRows = dgvProjects.SelectedRows; if (projectRows.Count == 0) { MessageBox.Show("No rows selected in the Projects DataGridView"); return; } Project proj = projectRows[0].DataBoundItem as Project; ProjectId = proj.ProjectId; //Get the selected row(s) in the Xrefs DGV DataGridViewSelectedRowCollection xrefRows = dgvXrefs.SelectedRows; if (xrefRows.Count == 0) { MessageBox.Show("No rows selected in the Xrefs DataGridView"); return; } List <Xref> lstXrefs = new List <Xref>(); foreach (DataGridViewRow row in xrefRows) { Xref xref = row.DataBoundItem as Xref; lstXrefs.Add(xref); } //Add the links foreach (Xref xref in lstXrefs) { proj.Xrefs.Add(xref); _ctx.SaveChanges(); } }
private void InsertNewData() { Keyword k = new Keyword(); k.Name = _dds.KeywordName; Project p = new Project(); p.Name = _dds.ProjectName; p.Location = _dds.ProjectLocation; Xref r = new Xref(); r.Url = _dds.XrefUrl; r.Description = _dds.XrefDescription; Solution s = new Solution(); s.Name = _dds.SolutionName; s.Location = _dds.SolutionLocation; _ctx.Keywords.Add(k); _ctx.Projects.Add(p); _ctx.Xrefs.Add(r); _ctx.Solutions.Add(s); //add instances to navigation propeties k.Projects.Add(p); p.Keywords.Add(k); p.Xrefs.Add(r); r.Projects.Add(p); s.Projects.Add(p); _ctx.SaveChanges(); }
public void CreateXRef(Xref xref) { _ctx.SaveChanges(); }