private void btnAddFacilitatorAddress_Click(object sender, EventArgs e) { using (frmAddUpdateAddresses frm = new frmAddUpdateAddresses(0)) { frm.ShowDialog(); if (frm.CurrentAddress != null) { if (frm.CurrentAddress.AddressID != 0) { using (var Dbconnection = new MCDEntities()) { Data.Models.Facilitator CurrentFacilitator = ((Data.Models.Facilitator)facilitatorBindingSource.Current); Dbconnection.Facilitators.Attach(CurrentFacilitator); Dbconnection.Addresses.Attach(frm.CurrentAddress); CurrentFacilitator.Individual.Addresses.Add(frm.CurrentAddress); Dbconnection.SaveChanges(); //Dbconnection.Entry(CurrentFacilitator).Reference(a => a.Individual.Addresses).Load(); // Dbconnection.Entry(CurrentFacilitator).Reference(a => a.LookupProvince).Load(); //// Dbconnection.Entry(CurrentFacilitator).Reference(a => a.LookupCountry).Load(); }; refreshFacilitatorAddressDetails(); } } }; }
private void dgvStudentSearchResults_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewLinkColumn && e.RowIndex >= 0) { //TODO - Button Clicked - Execute Code Here CurrentFacilitator = (Data.Models.Facilitator)(senderGrid.Rows[e.RowIndex].DataBoundItem); //if (this.frmParentForm != null) //{ // foreach (Form f in frmParentForm.MdiChildren) // { // if (f.GetType() == typeof(frmAddUpdateStudent)) // { // f.Activate(); // f.WindowState = FormWindowState.Maximized; // this.Close(); // return; // } // } // frmAddUpdateStudent frm = new frmAddUpdateStudent(); // frm.StudentID = stud.StudentID; // frm.MdiParent = frmParentForm; // frm.Show(); // this.Close(); //} //MessageBox.Show(stud.StudentID.ToString()); this.Close(); } }
private void populateFacilitatorContactDetails() { Data.Models.Facilitator CurrentEmpolyeeObj = (Data.Models.Facilitator)facilitatorBindingSource.Current; List <ContactDetail> result = (from a in CurrentEmpolyeeObj.Individual.ContactDetails select a).ToList <ContactDetail>(); contactDetailsBindingSource.DataSource = result; }
private void btnAddEmployee_Click(object sender, EventArgs e) { using (var Dbconnection = new MCDEntities()) { using (System.Data.Entity.DbContextTransaction dbTran = Dbconnection.Database.BeginTransaction()) { try { //CRUD Operations CurrentFaclilitator = new Data.Models.Facilitator { Individual = new Individual { TitleID = Convert.ToInt32(cboEmployeeTitle.SelectedValue), IndividualFirstName = txtEmployeeFirstName.Text.ToString(), IndividualSecondName = txtEmployeeSecondName.Text.ToString(), IndividualLastname = txtEmployeeLastName.Text.ToString(), } }; Dbconnection.Facilitators.Add(CurrentFaclilitator); ////saves all above operations within one transaction Dbconnection.SaveChanges(); this.CurrentFaclilitator = (from a in Dbconnection.Facilitators where a.FacilitatorID == CurrentFaclilitator.FacilitatorID select a).FirstOrDefault <Data.Models.Facilitator>(); //commit transaction dbTran.Commit(); this.Close(); } catch (Exception ex) { if (ex is DbEntityValidationException) { foreach (DbEntityValidationResult entityErr in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Rollback transaction if exception occurs dbTran.Rollback(); } } }; }
private void btnSelectFacilitator_Click(object sender, EventArgs e) { frmStudentSearchForFacilitator frm = new frmStudentSearchForFacilitator(); frm.ShowDialog(); currentFacilitator = frm.CurrentFacilitator; if (currentFacilitator != null) { setFacilitatorDetails(); refreshDepartment(); refreshAvailableCourses(); refreshLinkedCourses(); } }
private void btnAddContactInfo_Click(object sender, EventArgs e) { Data.Models.Facilitator CurrentFacilitatorObj = (Data.Models.Facilitator)facilitatorBindingSource.Current; frmAddUpdateContactDetails frm = new frmAddUpdateContactDetails(0); frm.ShowDialog(); if (frm.CurrentDetail != null) { using (var Dbconnection = new MCDEntities()) { Dbconnection.Facilitators.Attach(CurrentFacilitatorObj); Dbconnection.ContactDetails.Attach(frm.CurrentDetail); CurrentFacilitatorObj.Individual.ContactDetails.Add(frm.CurrentDetail); Dbconnection.SaveChanges(); Dbconnection.Entry(frm.CurrentDetail).Reference("LookupContactType").Load(); }; this.refreshFacilitatorContactDetails(); } }
private void populateFacilitatorAddressDetails() { Data.Models.Facilitator CurrentFacilitator = (Data.Models.Facilitator) this.facilitatorBindingSource.Current; addressesBindingSource.DataSource = (from a in CurrentFacilitator.Individual.Addresses select a).ToList <Address>(); }