private void dgvAttendees_Click(object sender, EventArgs e) { attendeeCode = int.Parse(dgvAttendees.CurrentRow.Cells["AttendeeId"].Value.ToString()); int columnIndex = dgvAttendees.CurrentCell.ColumnIndex; if (dgvAttendees.CurrentRow.Cells[columnIndex].Value.ToString().Equals("Edit")) { btnAdd.Text = "UPDATE"; attendee = dbContext.Attendees.Find(attendeeCode); txtFirstName.Text = attendee.AttendeeFName; txtLastName.Text = attendee.AttendeeLName; txtEmail.Text = attendee.AttendeeEmail; txtContact.Text = attendee.AttendeeContact; txtTicketType.Text = attendee.TicketType; txtAddress.Text = attendee.AttendeeAddress; txtAttendingDays.Text = attendee.AttendingDays.ToString(); } else if (dgvAttendees.CurrentRow.Cells[columnIndex].Value.ToString().Equals("Delete")) { DialogResult dialogResult = MessageBox.Show("Are you sure ?", "Confirm Delete", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { dbContext.Attendees.Remove(dbContext.Attendees.Find(attendeeCode)); dbContext.SaveChanges(); reloadDGV(); } btnAdd.Text = "ADD"; } }
public void Seed() { this.Attendees.RemoveRange(this.Attendees); this.Events.RemoveRange(this.Events); this.Organizers.RemoveRange(this.Organizers); var user1 = new Model.Attendee() { name = "Jakob", email = "*****@*****.**", phoneNumber = 03663252, }; var user2 = new Model.Attendee() { name = "Bengt", email = "*****@*****.**", phoneNumber = 078456555 }; this.Attendees.AddRange(new List <Model.Attendee>() { user1 // new Model.Attendee(){name = "Bengt", email = "*****@*****.**", phoneNumber = 078456555}, //new Model.Attendee(){name = "Gustav", email = "*****@*****.**", phoneNumber = 070811223} }); this.Events.AddRange(new List <Model.Event>() { new Model.Event() { title = "Summerburst", organizer_id = 1, description = "This is the sickest festival !", place = "Globen", address = "Globengatan", date = new DateTime(20200101), spots_avalible = 10000, Attendee = new List <Model.Attendee> { user1, user2 } }, new Model.Event() { title = "PoolDay", organizer_id = 1, description = "Fun pool day for the whole family, comedians and artist will entertain you the whole day", place = "Flahultsbadet", address = "Grågatan", date = new DateTime(20200102), spots_avalible = 500, Attendee = new List <Model.Attendee> { user2 } }, new Model.Event() { title = "WhiteParty", organizer_id = 2, description = "Small party with dress code: White clothes only", place = "Puben runt hörnet", address = "Bargatan", date = new DateTime(20200510), spots_avalible = 50 } }); this.Organizers.AddRange(new List <Model.Organizer>() { new Model.Organizer() { name = "SwedishClub AB", email = "*****@*****.**", phoneNumber = 082334566 }, new Model.Organizer() { name = "FestFixarna", email = "*****@*****.**", phoneNumber = 070665544 }, new Model.Organizer() { name = "SickestParty", email = "*****@*****.**", phoneNumber = 08114477 } }); this.SaveChanges(); }
private void btnAdd_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtFirstName.Text)) { MessageBox.Show("Please enter first name!!!"); txtFirstName.Focus(); return; } else if (String.IsNullOrEmpty(txtLastName.Text)) { MessageBox.Show("Please enter last name!!!"); txtLastName.Focus(); return; } else if (String.IsNullOrEmpty(txtEmail.Text)) { MessageBox.Show("Please enter email!!!"); txtEmail.Focus(); return; } else if (String.IsNullOrEmpty(txtContact.Text)) { MessageBox.Show("Please enter contact number!!!"); txtContact.Focus(); return; } else if (String.IsNullOrEmpty(txtTicketType.Text)) { MessageBox.Show("Please enter ticket type!!!"); txtTicketType.Focus(); return; } else if (String.IsNullOrEmpty(txtAddress.Text)) { MessageBox.Show("Please enter address!!!"); txtAddress.Focus(); return; } else if (String.IsNullOrEmpty(txtAttendingDays.Text)) { MessageBox.Show("Please enter number of attending days!!!"); txtAttendingDays.Focus(); return; } else { if (btnAdd.Text.Equals("ADD")) { attendee = new Attendee(); } else if (btnAdd.Text.Equals("UPDATE")) { attendee.AttendeeId = attendeeCode; // set code to update while save changes } attendee.AttendeeFName = txtFirstName.Text.Trim(); attendee.AttendeeLName = txtLastName.Text.Trim(); attendee.AttendeeEmail = txtEmail.Text.Trim(); attendee.AttendeeContact = txtContact.Text.Trim(); attendee.TicketType = txtTicketType.Text.Trim(); attendee.AttendeeAddress = txtAddress.Text.Trim(); attendee.AttendingDays = Convert.ToInt32(txtAttendingDays.Text.Trim()); try { if (btnAdd.Text.Equals("ADD")) { dbContext.Attendees.Add(attendee); } dbContext.SaveChanges(); MessageBox.Show(String.Format("Attendee {0} successfully!!!", btnAdd.Text.Equals("ADD")?"added":"updated")); btnAdd.Text = "ADD"; // clear txtFirstName.Clear(); txtLastName.Clear(); txtEmail.Clear(); txtContact.Clear(); txtTicketType.Clear(); txtAddress.Clear(); txtAttendingDays.Clear(); // refresh reloadDGV(); txtFirstName.Focus(); return; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }