public static bool SaveTalk(TalkInformation newTalk) { var speaker = DATABASE.Speakers.SingleOrDefault(s => s.FirstName == newTalk.SpeakerFirstName && s.LastName == newTalk.SpeakerLastName); if (speaker == null) { // Warn the user that no speaker exists with that name MessageBox.Show($"No speaker exists with the name {newTalk.SpeakerFirstName} {newTalk.SpeakerLastName}", "Canceling Save", MessageBoxButton.OK); return(false); } // If the database doesn't have any existing sessions matching the new one, save to the database if (!DATABASE.Talks.Any(talk => talk.DateGiven == newTalk.TalkDate && talk.Title == newTalk.TalkTitle && talk.Summary == newTalk.TalkSummary)) { DATABASE.Talks.InsertOnSubmit(new Talk { DateGiven = newTalk.TalkDate, Title = newTalk.TalkTitle, Summary = newTalk.TalkSummary, SpeakerID = speaker.ID, UpdateTime = DateTime.Now, DiagnosticInformation = new StackTrace().ToString() }); DATABASE.SubmitChanges(); return(true); } return(false); }
public static void RemoveTalk(TalkInformation removeTalk) { var speakerID = DATABASE .Speakers.Single(s => s.FirstName == removeTalk.SpeakerFirstName && s.LastName == removeTalk.SpeakerLastName).ID; var removedItem = DATABASE.Talks.Single(talk => talk.DateGiven == removeTalk.TalkDate && talk.Title == removeTalk.TalkTitle && talk.Summary == removeTalk.TalkSummary && talk.SpeakerID == speakerID); DATABASE.Talks.DeleteOnSubmit(removedItem); DATABASE.SubmitChanges(); }