public async Task Editar(Notification notification) { var notificacionAntigua = ListaNotifications.Find(x => x.NotificationId == notification.NotificationId); notificacionAntigua = notification; dataService.Update(notificacionAntigua, true); var FechayTiempo = notification.Fecha.Date + notification.Horario; notification.TiempoRestanteEnvio = FechayTiempo - DateTime.Now; var tiempoSchedule = notification.TiempoRestanteEnvio.TotalMinutes; try { CrossLocalNotifications.Current.Cancel(notification.NotificationId); CrossLocalNotifications.Current.Show( notification.Title, notification.Message, notification.NotificationId, DateTime.Now.AddMinutes(tiempoSchedule)); } catch (Exception e) { await dialogService.ShowMessage("Error", e.Message); } CollectionNotification = new ObservableCollection <Notification>(ListaNotifications.OrderByDescending(x => x.TiempoRestanteEnvio.TotalMinutes)); }
private void Refresh() { IsRefreshing = true; ListaNotifications = dataService.Get <Notification>(true); foreach (var notification in ListaNotifications) { var fechaTiempo = notification.Fecha.Date + notification.Horario; if (fechaTiempo <= DateTime.Now) { dataService.Delete(notification); } } ListaNotifications = dataService.Get <Notification>(true); CollectionNotification = new ObservableCollection <Notification>(ListaNotifications.OrderByDescending(x => x.TiempoRestanteEnvio.TotalMinutes)); IsRefreshing = false; }
public async Task Delete(Notification notification) { var confirmacion = await dialogService.ShowMessageConfirmacion("Mensaje", "¿Desea borrar este elemento?"); if (confirmacion) { var notificacionAntigua = ListaNotifications.Find(x => x.NotificationId == notification.NotificationId); CrossLocalNotifications.Current.Cancel(notification.NotificationId); dataService.Delete(notificacionAntigua); ListaNotifications.Remove(notification); CollectionNotification = new ObservableCollection <Notification>(ListaNotifications.OrderByDescending(x => x.TiempoRestanteEnvio.TotalMinutes)); } else { return; } }
private async void Notification() { //Crea el objeto Ingreso, lo agrego a la lista del mes, y después se hace la sumatoria de la lista if (string.IsNullOrEmpty(MensajeNotification) || string.IsNullOrWhiteSpace(MensajeNotification)) { await dialogService.ShowMessage("Error", "Debe contener un mensaje para enviar"); return; } if (Date < DateTime.Now && Time < DateTime.Now.TimeOfDay.Subtract(TimeSpan.FromMinutes(1))) { await dialogService.ShowMessage("Error", "El horario de entrega seleccionado no puede ser anterior al horario actual"); return; } Notificacion = new Notification(); Notificacion.Anio = Date.ToString("yyyy", culture); Notificacion.Mes = Date.ToString("MMM", culture); Notificacion.Dia = Date.ToString("dd", culture); if (int.Parse(Time.Hours.ToString(culture)) < 10) { Notificacion.Hora = string.Format("0{0}", Time.Hours.ToString(culture)); } else { Notificacion.Hora = Time.Hours.ToString(culture); } if (int.Parse(Time.Minutes.ToString(culture)) < 10) { Notificacion.Minutos = string.Format("0{0}", Time.Minutes.ToString(culture)); } else { Notificacion.Minutos = Time.Minutes.ToString(culture); } var FechayTiempo = Date.Date + Time; Notificacion.Fecha = Date.Date; Notificacion.Horario = Time; Notificacion.TiempoRestanteEnvio = FechayTiempo - DateTime.Now; var tiempoSchedule = Notificacion.TiempoRestanteEnvio.TotalMinutes; if (string.IsNullOrEmpty(TituloNotification) || string.IsNullOrWhiteSpace(TituloNotification)) { Notificacion.Title = "Aviso"; } else { Notificacion.Title = string.Format("{0}{1}", TituloNotification.Substring(0, 1).ToUpper(), TituloNotification.Substring(1));; } Notificacion.Message = string.Format("{0}{1}", MensajeNotification.Substring(0, 1).ToUpper(), MensajeNotification.Substring(1)); ListaNotifications.Add(Notificacion); TituloNotification = null; MensajeNotification = null; Date = DateTime.Now; Time = DateTime.Now.TimeOfDay; dataService.Save(ListaNotifications, true); CollectionNotification = new ObservableCollection <Notification>( ListaNotifications.OrderByDescending( x => x.TiempoRestanteEnvio.TotalMinutes)); try { CrossLocalNotifications.Current.Show( Notificacion.Title, Notificacion.Message, Notificacion.NotificationId, DateTime.Now.AddMinutes(tiempoSchedule)); } catch (Exception e) { await dialogService.ShowMessage("Error", e.Message); } }