internal List<ScheduleByUnconference> GetSchedulesByUnconference() { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { return (from unconference in context.ScheduleByUnconferences select unconference).ToList(); } }
internal Schedule GetSchedule(int identifier) { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { return (from schedule in context.Schedules where schedule.Identifier == identifier select schedule).FirstOrDefault(); } }
internal Places GetPlace(int identifier) { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { return (from place in context.Places where place.Identifier == identifier select place).FirstOrDefault(); } }
internal void CreateDatabase() { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { if (!context.DatabaseExists()) { context.CreateDatabase(); } } }
internal bool IsUnconferenceFavorite(int unconferenceId, int scheduleId, int placeId) { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { ScheduleByUnconference selectedUnconference = (from unconference in context.ScheduleByUnconferences where unconference.PlaceId == placeId && unconference.ScheduleId == scheduleId && unconference.UnconferenceId == unconferenceId select unconference).FirstOrDefault(); if (selectedUnconference == null) return false; else return true; } }
internal Unconferences GetUnconference(int identifier) { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { return (from unconference in context.Unconferences where unconference.Identifier == identifier select unconference).FirstOrDefault(); } }
internal void SetAsFavorite(UnconferenceViewModel selectedUnconference) { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { var query = (from unconference in context.ScheduleByUnconferences where unconference.PlaceId == selectedUnconference.Place.Identifier && unconference.ScheduleId == selectedUnconference.Schedule.Identifier && unconference.UnconferenceId == selectedUnconference.Identifier select unconference).FirstOrDefault(); if (query == null) { var newPlace = (from p in context.Places where p.Identifier == selectedUnconference.Place.Identifier select p).FirstOrDefault(); if (newPlace == null) { newPlace = new Places() { Identifier = selectedUnconference.Place.Identifier, Description = selectedUnconference.Place.Description, Name = selectedUnconference.Place.Name, }; context.Places.InsertOnSubmit(newPlace); context.SubmitChanges(); } var unconference = (from u in context.Unconferences where u.Identifier == selectedUnconference.Identifier select u).FirstOrDefault(); if (unconference == null) { Unconferences newUnconference = new Unconferences() { Description = selectedUnconference.Description, Identifier = selectedUnconference.Identifier, Keywords = selectedUnconference.Keywords, Name = selectedUnconference.Name, Speakers = selectedUnconference.Speakers, }; context.Unconferences.InsertOnSubmit(newUnconference); context.SubmitChanges(); } var selectedSchedule = (from s in context.Schedules where s.Identifier == selectedUnconference.Schedule.Identifier select s).FirstOrDefault(); if (selectedSchedule == null) { Schedule newSchedule = new Schedule() { Identifier = selectedUnconference.Schedule.Identifier, StartTime = selectedUnconference.Schedule.StartTime, EndTime = selectedUnconference.Schedule.EndTime, }; context.Schedules.InsertOnSubmit(newSchedule); context.SubmitChanges(); } ScheduleByUnconference newScheduleByUnconference = new ScheduleByUnconference() { ScheduleId = selectedUnconference.Schedule.Identifier, UnconferenceId = selectedUnconference.Identifier, PlaceId = selectedUnconference.Place.Identifier, }; context.ScheduleByUnconferences.InsertOnSubmit(newScheduleByUnconference); context.SubmitChanges(); } context.SubmitChanges(); } }
internal void RemoveFromFavorites(UnconferenceViewModel selectedUnconference) { try { using (DatabaseDataContext context = new DatabaseDataContext(Settings.ConnectionString)) { ScheduleByUnconference scheduleByUnconference = (from unconference in context.ScheduleByUnconferences where unconference.PlaceId == selectedUnconference.Place.Identifier && unconference.ScheduleId == selectedUnconference.Schedule.Identifier && unconference.UnconferenceId == selectedUnconference.Identifier select unconference).FirstOrDefault(); context.ScheduleByUnconferences.DeleteOnSubmit(scheduleByUnconference); context.SubmitChanges(); } } catch (Exception) { //TODO: Notificar error - Deadline } }