Exemplo n.º 1
0
        public void CreateReminder(UnconferenceViewModel unconference)
        {
            try
            {
                string id = Settings.HashTag + "-" + unconference.Identifier.ToString() +
                    "-" + unconference.Place.Identifier.ToString() +
                    "-" + unconference.Schedule.Identifier.ToString();

                if (ScheduledActionService.Find(id) != null)
                {
                    ScheduledActionService.Remove(id);
                }

                Reminder reminder = new Reminder(id)
                {
                    Title = unconference.Name.Length > 50
                                        ? unconference.Name.Substring(0, 50) + "..."
                                        : unconference.Name,
                    Content = unconference.Description.Length > 100
                                        ? unconference.Description.Substring(0, 100) + "..."
                                        : unconference.Description,
                    BeginTime = unconference.Schedule.StartTime.AddMinutes(-10),
                    RecurrenceType = RecurrenceInterval.None,
                    ExpirationTime = unconference.Schedule.EndTime,
                    NavigationUri = new Uri(string.Format("/UnconferenceDetail.xaml?UnconferenceId={0}&PlaceId={1}&ScheduleId={2}", unconference.Identifier, unconference.Place.Identifier,unconference.Schedule.Identifier), UriKind.Relative)
                };

                ScheduledActionService.Add(reminder);

                this.ManipulationDataResult = Result.Successful;
            }
            catch (Exception ex)
            {
                this.ManipulationDataResult = Result.ApplicationError;
            }
        }
        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;
        }
        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
            }
        }
        private void SetPlacesFromServicesData()
        {
            foreach (Place place in servicesModel.Places)
            {
                PlaceViewModel newPlace = new PlaceViewModel()
                {
                    Identifier = place.id,
                    Name = place.nombre,
                    Description = place.descripcion,
                    PhotoSource = place.imagen,
                    ViewModel = this,
                    Unconferences = new ObservableCollection<UnconferenceViewModel>()
                };

                foreach (Unconference unconference in place.Conferencias)
                {
                    UnconferenceViewModel newUnconference = new UnconferenceViewModel()
                        {
                            Identifier = unconference.id,
                            Name = unconference.nombre,
                            Description = unconference.resumen,
                            ShortDescription =
                                unconference.resumen.Length > 100
                                    ? unconference.resumen.Substring(0, 100) + "..."
                                    : unconference.resumen,
                            Keywords = unconference.palabrasClave,
                            Place = newPlace,
                            Speakers = unconference.expositores,
                            Schedule = new ScheduleViewModel()
                                {
                                    Identifier = unconference.horario.id,
                                    StartTime = unconference.horario.fechaInicio,
                                    EndTime = unconference.horario.fechaFin,
                                },
                            IsFavorite = databaseModel.IsUnconferenceFavorite(unconference.id, unconference.horario.id, newPlace.Identifier),
                            ViewModel = this
                        };

                    newPlace.Unconferences.Add(newUnconference);
                    this.Unconferences.Clear();
                    this.Unconferences.Add(newUnconference);
                }

                //Search the Next Unconference
                newPlace.NextUnconference = (from unconference in place.Conferencias
                                             where unconference.horario.fechaInicio > DateTime.Now
                                             orderby unconference.horario.fechaFin ascending
                                             select new UnconferenceViewModel()
                                                 {
                                                     Identifier = unconference.id,
                                                     Name = unconference.nombre,
                                                     Description = unconference.resumen,
                                                     ShortDescription = unconference.resumen.Length > 100 ? unconference.resumen.Substring(0, 100) + "..." : unconference.resumen,
                                                     Keywords = unconference.palabrasClave,
                                                     Place = newPlace,
                                                     Speakers = unconference.expositores,
                                                     Schedule = new ScheduleViewModel()
                                                     {
                                                         Identifier = unconference.horario.id,
                                                         StartTime = unconference.horario.fechaInicio,
                                                         EndTime = unconference.horario.fechaFin,
                                                     },
                                                     IsFavorite = false,
                                                     ViewModel = this
                                                 }).FirstOrDefault();

                if (newPlace.NextUnconference == null)
                {
                    newPlace.NextUnconference = new UnconferenceViewModel()
                    {
                        Name = Messages.Thanks,
                    };
                }

                this.Places.Add(newPlace);
            }
        }