partial void DeleteScheduleByUnconference(ScheduleByUnconference instance);
 partial void UpdateScheduleByUnconference(ScheduleByUnconference instance);
 partial void InsertScheduleByUnconference(ScheduleByUnconference instance);
        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();
            }
        }
        private UnconferenceViewModel SetUnconference(ScheduleByUnconference selectedUnconference)
        {
            DataAccess.Places place = databaseModel.GetPlace(selectedUnconference.PlaceId);
            DataAccess.Schedule schedule = databaseModel.GetSchedule(selectedUnconference.ScheduleId);
            DataAccess.Unconferences unconference = databaseModel.GetUnconference(selectedUnconference.UnconferenceId);

            UnconferenceViewModel newUnconference = new UnconferenceViewModel()
            {
                Identifier = unconference.Identifier,
                Name = unconference.Name,
                Description = unconference.Description,
                ShortDescription =
                    unconference.Description.Length > 100
                        ? unconference.Description.Substring(0, 100) + "..."
                        : unconference.Description,
                Keywords = unconference.Keywords,
                Place = new PlaceViewModel()
                {
                    Identifier = place.Identifier,
                    Name = place.Name,
                    Description = place.Description,
                    PhotoSource = place.Image,
                    ViewModel = this,
                    Unconferences = new ObservableCollection<UnconferenceViewModel>()
                },
                Schedule = new ScheduleViewModel()
                {
                    Identifier = schedule.Identifier,
                    StartTime = schedule.StartTime,
                    EndTime = schedule.EndTime,
                },
                Speakers = unconference.Speakers,
                IsFavorite = true,
                ViewModel = this
            };

            this.FavoritesUnconferences.Add(newUnconference);
            return newUnconference;
        }
        public UnconferenceViewModel GetUnconference(int unconferenceId, int placeId, int scheduleId)
        {
            DataAccess.ScheduleByUnconference selectedUnconference = new ScheduleByUnconference()
            {
                PlaceId = placeId,
                UnconferenceId = unconferenceId,
                ScheduleId = scheduleId
            };

            return SetUnconference(selectedUnconference);
        }