public static void SendAnyNotification(ContextService db, int idUsuario) { var device = db.Devices.Get(p => p.IdUsuario == idUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, "No ha marcado el inicio de su Jornada", String.Format("Por favor marque el inicio de su jornada, o ingrese una Justificación."), "MARCACION"); } }
public ActionResult Notificacion(int idAgente, string titulo, string mensaje) { try { if (String.IsNullOrEmpty(titulo) || String.IsNullOrEmpty(mensaje)) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.DatosIncompletos); } if (!this.MessageCollection.HasError()) { var usuario = DataBase.Agentes.Get(p => p.IdUsuario == this.UserId).FirstOrDefault(); string emails = String.Empty; var agente = DataBase.Agentes.Get(p => p.IdAgente == idAgente).FirstOrDefault(); string footer = String.Format("Enviada por: {0} - el {1:g}", usuario.Descripcion, this.GetCurrentDateTime()); if (agente != null && agente.IdUsuario != null) { if (!String.IsNullOrEmpty(agente.Usuario.Contact.Email)) { if (!String.IsNullOrEmpty(emails)) { emails = String.Format("{0};{1}", emails, agente.Usuario.Contact.Email); } else { emails = agente.Usuario.Contact.Email; } } var device = DataBase.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, titulo, mensaje, null, footer); } } if (!String.IsNullOrEmpty(emails)) { DataBase.Notificacions.Send(this.ApplicationId, emails, titulo, String.Format("{0}<br><br>{1}", mensaje, footer), 105); } this.AddDefaultSuccessMessage(); } } catch { this.AddDefaultErrorMessage(); } return(Json()); }
public IHttpActionResult NotificationEveryone(Rp3.AgendaComercial.Web.Services.General.Models.NotificationToUser notification) { try { var usuario = DataBase.Agentes.Get(p => p.IdUsuario == CurrentUser.UserId).FirstOrDefault(); var responsables = DataBase.OportunidadResponsables.Get(p => p.IdOportunidad == notification.IdAgente).ToList(); string emails = ""; string footer = String.Format("Enviada por: {0} - el {1:g}", usuario.Descripcion, this.GetCurrentDateTime()); foreach (var responsable in responsables) { if (!String.IsNullOrEmpty(responsable.Agente.Usuario.Contact.Email)) { if (!String.IsNullOrEmpty(emails)) { emails = String.Format("{0};{1}", emails, responsable.Agente.Usuario.Contact.Email); } else { emails = responsable.Agente.Usuario.Contact.Email; } var device = DataBase.Devices.Get(p => p.IdUsuario == responsable.Agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, notification.Titulo, notification.Mensaje, null, footer); } } } if (!String.IsNullOrEmpty(emails)) { DataBase.Notificacions.Send(this.ApplicationId, emails, notification.Titulo, String.Format("{0}<br><br>{1}", notification.Mensaje, footer), 105); } } catch (Exception ex) { return(BadRequest(ex.StackTrace)); } return(Ok()); }
public static void GetLog(ContextService db, string ids) { List <int> list_ids = new List <int>(); var splitted = ids.Split(','); foreach (var id in splitted) { try { list_ids.Add(int.Parse(id)); } catch (Exception ex) { } } var devices = db.Devices.Get(p => list_ids.Contains(p.IdUsuario)).ToList(); foreach (var device in devices) { AndroidNotificationPusher.PushNotification(device.GCMId, "OBTAINING LOG", "", "LOG"); } }
public static void NotificacionMarcacion(ContextService db) { db.ParametroHelper.Load(); var agentes = db.Agentes.Get(p => p.Estado == Models.Constantes.Estado.Activo && p.IdGrupo != null && p.IdUsuario != null); DateTime fecha = DateTime.Now.Date; foreach (var agente in agentes) { bool esDiaLaboral = db.Agentes.EsDiaLaboral(agente.Grupo.IdCalendario, fecha); if (esDiaLaboral) { var marcacionInicio = db.Marcacions.Get(p => p.IdAgente == agente.IdAgente && p.Fecha == fecha && p.Tipo == Models.Constantes.TipoMarcacion.InicioJornada1).FirstOrDefault(); var marcacionFin = db.Marcacions.Get(p => p.IdAgente == agente.IdAgente && p.Fecha == fecha && p.Tipo == Models.Constantes.TipoMarcacion.FinJornada2).FirstOrDefault(); if (marcacionInicio == null || marcacionFin == null) { int numdia = (int)fecha.DayOfWeek; if (numdia == 0) { numdia = 7; } var dia = agente.Grupo.Calendario.DiasLaborales.Where(p => p.IdDia == Convert.ToString(numdia) && p.EsLaboral).FirstOrDefault(); if (dia != null) { int hini = Convert.ToInt32(dia.HoraInicio1.Substring(0, 2)); int mini = Convert.ToInt32(dia.HoraInicio1.Substring(3, 2)); DateTime horainicio = fecha.AddHours(hini).AddMinutes(mini); int hfin = Convert.ToInt32(dia.HoraFin1.Substring(0, 2)); int mfin = Convert.ToInt32(dia.HoraFin1.Substring(3, 2)); if (dia.HoraFin2 != null) { hfin = Convert.ToInt32(dia.HoraFin2.Substring(0, 2)); mfin = Convert.ToInt32(dia.HoraFin2.Substring(3, 2)); } DateTime horafin = fecha.AddHours(hfin).AddMinutes(mfin); if (marcacionInicio == null && DateTime.Now > horainicio && (DateTime.Now - horainicio).TotalMinutes > db.ParametroHelper.MinutoNotificacionMarcacion) { var device = db.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, "No ha marcado el inicio de su Jornada", String.Format("Por favor marque el inicio de su jornada, o ingrese una Justificación."), "MARCACION"); } } else if (marcacionFin == null && DateTime.Now > horafin && (DateTime.Now - horafin).TotalMinutes > db.ParametroHelper.MinutoNotificacionMarcacion) { var device = db.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, "No ha marcado el fin de su Jornada", String.Format("Por favor marque el fin de su jornada."), "MARCACION"); } } } } } } }
public ActionResult Index(NotificacionAgente model, string[] agentes) { InicializarEdit(); model.Agentes = GetAgenteListDetail(agentes); try { var usuario = DataBase.Agentes.Get(p => p.IdUsuario == this.UserId).FirstOrDefault(); string emails = String.Empty; string footer = String.Format("Enviada por: {0} - el {1:g}", usuario.Descripcion, this.GetCurrentDateTime()); if (!String.IsNullOrEmpty(model.Titulo) && !String.IsNullOrEmpty(model.Mensaje) && usuario != null) { foreach (var item in model.Agentes) { try { var agente = DataBase.Agentes.Get(p => p.IdAgente == item.IdAgente).FirstOrDefault(); if (agente != null && agente.IdUsuario != null) { if (!String.IsNullOrEmpty(agente.Usuario.Contact.Email)) { if (!String.IsNullOrEmpty(emails)) { emails = String.Format("{0};{1}", emails, agente.Usuario.Contact.Email); } else { emails = agente.Usuario.Contact.Email; } } var device = DataBase.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, model.Titulo, model.Mensaje, null, footer); } } } catch { } } if (!String.IsNullOrEmpty(emails)) { DataBase.Notificacions.Send(this.ApplicationId, emails, model.Titulo, String.Format("{0}<br><br>{1}", model.Mensaje, footer), 105); } this.AddDefaultSuccessMessage(); model.Titulo = String.Empty; model.Mensaje = String.Empty; return(View(model)); } else { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.DatosIncompletos); } } catch { this.AddDefaultErrorMessage(); } return(View(model)); }
public IHttpActionResult SendNotification(Models.NotificationToUser notification) { try { var usuario = DataBase.Agentes.Get(p => p.IdUsuario == CurrentUser.UserId).FirstOrDefault(); string footer = String.Format("Enviada por: {0} - el {1:g}", usuario.Descripcion, this.GetCurrentDateTime()); if (notification.IdAgente != 0) { var agente = DataBase.Agentes.Get(p => p.IdAgente == notification.IdAgente).FirstOrDefault(); var device = DataBase.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); string emails = agente.Usuario.Contact.Email; if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, notification.Titulo, notification.Mensaje, null, footer); } if (!String.IsNullOrEmpty(emails)) { DataBase.Notificacions.Send(this.ApplicationId, emails, notification.Titulo, String.Format("{0}<br><br>{1}", notification.Mensaje, footer), 105); } } else { string emails = String.Empty; List <Rp3.AgendaComercial.Models.General.Agente> agentes = null; var sender = DataBase.Agentes.GetAgenteView(this.CurrentUser.UserId); if (sender.EsAdministrador) { agentes = DataBase.Agentes.Get(p => p.Estado == Rp3.AgendaComercial.Models.Constantes.Estado.Activo).ToList(); } else { agentes = DataBase.Agentes.Get(p => p.IdSupervisor == sender.IdAgente && p.Estado == Rp3.AgendaComercial.Models.Constantes.Estado.Activo).ToList(); } foreach (var agente in agentes) { try { if (agente != null && agente.IdUsuario != null) { if (!String.IsNullOrEmpty(agente.Usuario.Contact.Email)) { if (!String.IsNullOrEmpty(emails)) { emails = String.Format("{0};{1}", emails, agente.Usuario.Contact.Email); } else { emails = agente.Usuario.Contact.Email; } } var device = DataBase.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { AndroidNotificationPusher.PushNotification(device.GCMId, notification.Titulo, notification.Mensaje, null, footer); } } } catch (Exception ex) { return(BadRequest(ex.StackTrace)); } } if (!String.IsNullOrEmpty(emails)) { DataBase.Notificacions.Send(this.ApplicationId, emails, notification.Titulo, String.Format("{0}<br><br>{1}", notification.Mensaje, footer), 105); } } } catch (Exception ex) { return(BadRequest(ex.StackTrace)); } return(Ok()); }
public ActionResult Rechazar(int id, string observacionSupervisor) { try { if (String.IsNullOrEmpty(observacionSupervisor)) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.ObservacionSupervisorObligatoria); } if (!this.MessageCollection.HasError()) { var model = DataBase.Permisos.Get(p => p.IdPermiso == id).FirstOrDefault(); model.ObservacionSupervisor = observacionSupervisor; model.Estado = Rp3.AgendaComercial.Models.Constantes.EstadoPermiso.Rechazado; model.UsrMod = this.UserLogonName; model.FecMod = this.GetCurrentDateTime(); DataBase.Permisos.Update(model); DataBase.Save(); try { DataBase.Permisos.Permiso(model.IdPermiso); } catch { } try { var agente = DataBase.Agentes.Get(p => p.IdAgente == model.IdAgente).FirstOrDefault(); if (agente != null && agente.IdUsuario != null) { var device = DataBase.Devices.Get(p => p.IdUsuario == agente.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { var agenteSup = DataBase.Agentes.Get(p => p.Usuario.LogonName == this.UserLogonName).FirstOrDefault(); string footer = String.Format("Enviada por: {0} - el {1:g}", agenteSup.Descripcion, this.GetCurrentDateTime()); AndroidNotificationPusher.PushNotification(device.GCMId, "Justificación Rechazada", String.Format("Su justificación del {0:d} ha sido rechazada.", model.FechaInicio), null, footer); } } } catch { } this.AddDefaultSuccessMessage(); } } catch { this.AddDefaultErrorMessage(); } return(Json()); }
public IHttpActionResult AprobarPermiso(Models.PermisoPorAprobar permiso) { var agente = DataBase.Agentes.Get(p => p.Usuario.LogonName == CurrentUser.LogonName).FirstOrDefault(); var permisoUpdate = DataBase.Permisos.Get(p => p.IdPermiso == permiso.IdPermiso).FirstOrDefault(); if (agente != null && permisoUpdate != null && permisoUpdate.Estado == Rp3.AgendaComercial.Models.Constantes.EstadoPermiso.Pendiente) { try { Rp3.Data.Service.CopyTo(permiso, permisoUpdate, includeProperties: new string[] { "ObservacionSupervisor", "Estado" }); permisoUpdate.UsrMod = CurrentUser.LogonName; permisoUpdate.FecMod = GetCurrentDateTime(); DataBase.Permisos.Update(permisoUpdate); DataBase.Save(); try { DataBase.Permisos.Permiso(permisoUpdate.IdPermiso); } catch { } try { if (agente != null && agente.IdSupervisor != null) { var device = DataBase.Devices.Get(p => p.IdUsuario == agente.Supervisor.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { string footer = String.Format("Enviada por: {0} - el {1:g}", agente.Descripcion, this.GetCurrentDateTime()); if (permisoUpdate.Estado == Rp3.AgendaComercial.Models.Constantes.EstadoPermiso.Aprobado) { AndroidNotificationPusher.PushNotification(device.GCMId, "Justificación Aprobada", String.Format("Su justificación del {0:d} ha sido aprobada.", permisoUpdate.FechaInicio), null, footer); } else { AndroidNotificationPusher.PushNotification(device.GCMId, "Justificación Rechazada", String.Format("Su justificación del {0:d} ha sido rechazada.", permisoUpdate.FechaInicio), null, footer); } } } } catch { } } catch (Exception ex) { return(BadRequest(ex.Message)); } } return(Ok()); }
public IHttpActionResult InsertPermisoPrevio(Models.Permiso permiso) { var agente = DataBase.Agentes.Get(p => p.Usuario.LogonName == CurrentUser.LogonName).FirstOrDefault(); var permisoInsert = new Rp3.AgendaComercial.Models.Marcacion.Permiso(); if (agente != null) { try { Rp3.Data.Service.CopyTo(permiso, permisoInsert, includeProperties: new string[] { "TipoTabla", "Tipo", "MotivoTabla", "Motivo", "FechaInicio", "FechaFin", "HoraInicio", "HoraFin", "Observacion", "EsPrevio", "EstadoTabla", "Estado" }); permisoInsert.AsignarId(); permisoInsert.IdAgente = agente.IdAgente; permisoInsert.IdGrupo = agente.IdGrupo; permisoInsert.UsrIng = CurrentUser.LogonName; permisoInsert.FecIng = GetCurrentDateTime(); permisoInsert.EsPrevio = true; DataBase.Permisos.Insert(permisoInsert); DataBase.Save(); try { DataBase.Permisos.Permiso(permisoInsert.IdPermiso); } catch { } try { if (agente != null && agente.IdSupervisor != null) { var device = DataBase.Devices.Get(p => p.IdUsuario == agente.Supervisor.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { string footer = String.Format("Enviada por: {0} - el {1:g}", agente.Descripcion, this.GetCurrentDateTime()); AndroidNotificationPusher.PushNotification(device.GCMId, "Solicitud de Justificación", String.Format("{0} ha solicitado una Justificación.", agente.Descripcion), "APROBAR_JUSTIFICACION", footer); } } } catch { } } catch (Exception ex) { return(BadRequest(ex.Message)); } } return(Ok(permisoInsert.IdPermiso)); }
public ActionResult Crear(PermisoEdit permisoEdit) { try { DateTime fechaActual = GetCurrentDateTime(); //CLIENTE/CONTACTO EXISTA if (permisoEdit.IdAgente == null && permisoEdit.IdGrupo == null) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.PermisoAgenteOGrupoRequerido); } //TIEMPO VALIDACION else if (permisoEdit.FechaInicio > permisoEdit.FechaFin) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.HoraInicioMayorHoraFin); } else if (permisoEdit.FechaFin < this.GetCurrentDateTime()) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.PermisoPrevioFechaMenorFechaActual); } else if (String.IsNullOrEmpty(permisoEdit.ObservacionSupervisor)) { this.AddErrorMessage(Rp3.AgendaComercial.Resources.ErrorMessageValidation.ObservacionSupervisorObligatoria); } if (!this.MessageCollection.HasError()) { var model = new Rp3.AgendaComercial.Models.Marcacion.Permiso(); model.AsignarId(); model.IdAgente = permisoEdit.IdAgente; model.IdGrupo = permisoEdit.IdGrupo; model.FechaInicio = permisoEdit.FechaInicio.Date; model.FechaFin = permisoEdit.FechaFin.Date; model.HoraInicio = permisoEdit.FechaInicio; model.HoraFin = permisoEdit.FechaFin; model.MotivoTabla = Rp3.AgendaComercial.Models.Constantes.MotivoPermiso.Tabla; model.Motivo = permisoEdit.Motivo; model.TipoTabla = Rp3.AgendaComercial.Models.Constantes.TipoPermiso.Tabla; model.Tipo = permisoEdit.Tipo; model.EstadoTabla = Rp3.AgendaComercial.Models.Constantes.EstadoPermiso.Tabla; model.Estado = Rp3.AgendaComercial.Models.Constantes.EstadoPermiso.Aprobado; model.Observacion = permisoEdit.Observacion; model.ObservacionSupervisor = permisoEdit.ObservacionSupervisor; model.EsPrevio = true; model.UsrIng = this.UserLogonName; model.FecIng = this.GetCurrentDateTime(); DataBase.Permisos.Insert(model); DataBase.Save(); try { DataBase.Permisos.Permiso(model.IdPermiso); var agente = DataBase.Agentes.Get(p => p.IdAgente == permisoEdit.IdAgente).FirstOrDefault(); if (agente != null && agente.IdSupervisor != null) { var device = DataBase.Devices.Get(p => p.IdUsuario == agente.Supervisor.IdUsuario).FirstOrDefault(); if (device != null && !String.IsNullOrEmpty(device.GCMId)) { var agenteSup = DataBase.Agentes.Get(p => p.Usuario.LogonName == this.UserLogonName).FirstOrDefault(); string footer = String.Format("Enviada por: {0} - el {1:g}", agenteSup.Descripcion, this.GetCurrentDateTime()); AndroidNotificationPusher.PushNotification(device.GCMId, "Solicitud de Justificación", String.Format("{0} ha solicitado una Justificación.", agente.Descripcion), "APROBAR_JUSTIFICACION", footer); } } } catch { } this.AddDefaultSuccessMessage(); } } catch { this.AddDefaultErrorMessage(); } return(Json()); }