private void btnAdd_Click(object sender, EventArgs e) { //using (dbContext = new ConventionManagerDbContext()) //{ MethodController methodController = new MethodController(); if (methodController.stallCapacityStatus((int)cbxStall.SelectedValue)) { AttendeeStall attendeeStall = new AttendeeStall() { AttendeeId = (int)cbxAttendee.SelectedValue, StallId = (int)cbxStall.SelectedValue, IsExhibitor = chkIsExhibitor.Checked }; Stall stall = dbContext.Stalls.Find(attendeeStall.StallId); if (methodController.attendeeStatus(attendeeStall.AttendeeId, stall.StallStartDate, stall.StallEndDate)) { dbContext.AttendeeStalls.Add(attendeeStall); try { dbContext.SaveChanges(); MessageBox.Show("Attendee added to the stall successfully!!!"); updateGBXStall((int)cbxStall.SelectedValue); loadDGV(); return; } catch (Exception ex) { MessageBox.Show("Duplicate entry!!!"); return; } } else { MessageBox.Show("Attendee busy on other event or seminar or stall"); } } else { MessageBox.Show("Stall full!!!"); return; } //} }
private void dgvAttendeeStall_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dgvAttendeeStall.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.Equals("Delete")) { DialogResult dialogResult = MessageBox.Show("Are you sure?", "Confirm deletion", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { int attendeeId = Convert.ToInt32(dgvAttendeeStall.Rows[e.RowIndex].Cells["AttendeeId"].Value); int stallId = Convert.ToInt32(dgvAttendeeStall.Rows[e.RowIndex].Cells["StallId"].Value); AttendeeStall attendeeStall = dbContext.AttendeeStalls.Where(a => a.AttendeeId == attendeeId).Where(a => a.StallId == stallId).Single(); dbContext.AttendeeStalls.Remove(attendeeStall); dbContext.SaveChanges(); MessageBox.Show("Attendee removed from the stall!!!"); loadDGV(); return; } } }