private void Applybutton1_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { Event obj = (Event)dataGridView1.CurrentRow.DataBoundItem;; if (!Services.GetCollectionServices.GetAttendedEvents(Alumn).Contains(obj)) { AlumnEvent alumnEvent = new AlumnEvent() { Alumn = Alumn, Event = obj }; Services.AddServices.AddAlumnEvent(alumnEvent); MessageBox.Show("Du har registrerat dig på eventet: " + obj.Title); LoadDataGridView(); } else { MessageBox.Show("Du har redan registrerat dig på eventet: " + obj.Title); } } else { MessageBox.Show("Inget event valt"); } }
internal void RemoveEvent(Services services, int id) { Alumn a = GetAlumn(services); Event e = services.GetServices.GetEvent(id); AlumnEvent alumnEvent = services.GetCollectionServices.GetAlumnEvents(a).Where(x => x.Event.Equals(e) && x.Alumn.Equals(a)).FirstOrDefault(); services.DeleteServices.RemoveMyEvent(alumnEvent); }
internal void AttendEvent(Services services, int id) { Alumn alumn = GetAlumn(services); Event @event = services.GetServices.GetEvent(id); if (!services.GetCollectionServices.GetAttendedEvents(alumn).Contains(@event)) { AlumnEvent alumnEvent = new AlumnEvent() { Alumn = alumn, Event = @event }; services.AddServices.AddAlumnEvent(alumnEvent); MessageBox.Show("Du har registrerat dig på eventet: " + @event.Title); } }
public void AddAlumnEvent(AlumnEvent alumnEvent) { AppDbContext.AlumnEvent.Add(alumnEvent); AppDbContext.SaveChanges(); }
public void RemoveMyEvent(AlumnEvent alumnEvent) { AppDbContext.AlumnEvent.Remove(alumnEvent); AppDbContext.SaveChanges(); }