Example #1
0
        /// <summary>
        /// Devuelve una notificacion por cada prespuesto que ya haya vencido
        /// o la fecha de vencimiento este dentro de pTiempoDentroDe
        /// </summary>
        /// <param name="pTiempoDentroDe"></param>
        /// <returns></returns>
        public List <NotificacionDTO> getNotificaciones(int pTiempoDentroDe)
        {
            var notificaciones = new List <NotificacionDTO>();

            using (var repo = new Repositorio())
            {
                // Obtener los prespuestos con estado seniado o presupuestado
                // proximos a vencer o vencidos
                DateTime fechaDentroDe = DateTime.Now + TimeSpan.FromDays(pTiempoDentroDe);
                var      presupuestos  = repo.Presupuestos.Where(p =>
                                                                 ((p.Estado == EstadoPresupuesto.Presupuestado) ||
                                                                  (p.Estado == EstadoPresupuesto.Seniado)) &&
                                                                 (p.FechaVencimiento <= fechaDentroDe)
                                                                 );
                foreach (var pre in presupuestos)
                {
                    var not = new NotificacionDTO();
                    not.IdPresupuesto    = pre.Id;
                    not.FechaVencimiento = pre.FechaVencimiento;
                    if (pre.FechaVencimiento <= DateTime.Now)
                    {
                        not.Descripcion = $"Presupuesto {pre.Id} vencido";
                    }
                    else
                    {
                        not.Descripcion = $"Presupuesto {pre.Id} proximo a vencer";
                    }

                    notificaciones.Add(not);
                }
            }

            return(notificaciones);
        }
        public List <NotificacionDTO> getNotificaciones(int pTiempoDentroDe)
        {
            var notificaciones = new List <NotificacionDTO>();

            using (var repo = new Repositorio())
            {
                // Buscar lotes que no esten vencidos y
                // la fecha de vencimiento este dentro de 15 dias
                DateTime fechaDentroDe = DateTime.Now + TimeSpan.FromDays(pTiempoDentroDe);
                var      lotes         = repo.Lotes.Where(l =>
                                                          ((l.Vencido == false) &&
                                                           (l.FechaVencimiento <= fechaDentroDe))
                                                          );
                foreach (var lote in lotes)
                {
                    var notif = new NotificacionDTO();
                    notif.IdLote           = lote.Id;
                    notif.FechaVencimiento = lote.FechaVencimiento;
                    if (lote.FechaVencimiento <= DateTime.Now)
                    {
                        notif.Descripcion = $"Lote {lote.Id} vencido";
                    }
                    else
                    {
                        notif.Descripcion = $"Lote {lote.Id} proximo a vencerse";
                    }
                    notificaciones.Add(notif);
                }
            }

            return(notificaciones);
        }
        public List <NotificacionDTO> verificarNotificaciones(string user)
        {
            Usuarios model = db.Usuarios.Include(x => x.notificaciones).FirstOrDefault(x => x.correo.Equals(user));
            List <NotificacionDTO> response = new List <NotificacionDTO>();

            model.notificaciones.ForEach(x =>
            {
                NotificacionDTO notificacionModel = new NotificacionDTO();
                notificacionModel.notificacion    = x.notificacion;
                notificacionModel.id      = x.id;
                notificacionModel.anuncio = anunciosDAO.getById(x.anuncio.id);
                notificacionModel.fecha   = x.fecha;
                notificacionModel.check   = x.check;
                response.Add(notificacionModel);
            });
            return(response);
        }
        public NotificacionDTO Find(int?id)
        {
            try
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <Notificacion, NotificacionDTO>();
                });

                IMapper mapper = config.CreateMapper();
                //Mapeo de clase
                Notificacion    model    = db.Notificaciones.Find(id);
                NotificacionDTO response = mapper.Map <Notificacion, NotificacionDTO>(model);
                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public void checkNotificaciones(string user)
 {
     try
     {
         Usuarios        usuario      = db.Usuarios.Include(x => x.notificaciones).FirstOrDefault(w => w.correo.Equals(user));
         var             userModel    = FindUser(user);
         NotificacionDTO notificacion = new NotificacionDTO();
         Notificacion    respone      = new Notificacion();
         usuario.notificaciones.ForEach(x =>
         {
             x.check = true;
         });
         db.Entry(usuario).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }
        public void Add(NotificacionDTO notificacion)
        {
            try
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <NotificacionDTO, Notificacion>();
                });

                IMapper mapper = config.CreateMapper();
                //Mapeo de clase

                Notificacion response = mapper.Map <NotificacionDTO, Notificacion>(notificacion);
                db.Notificaciones.Add(response);
                db.SaveChanges();
            }

            catch (Exception)
            {
                throw;
            }
        }
        public NotificacionDTO Update(NotificacionDTO notificacions)
        {
            try
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <NotificacionDTO, Notificacion>();
                });
                IMapper      mapper             = config.CreateMapper();
                Notificacion notificacionsModel = mapper.Map <NotificacionDTO, Notificacion>(notificacions);

                db.Entry(notificacionsModel).State = EntityState.Modified;
                db.SaveChanges();

                notificacions = this.Find(notificacions.id);


                return(notificacions);
            }
            catch (Exception)
            {
                return(notificacions);
            }
        }
        public List <NotificacionDTO> getList(string user)
        {
            try
            {
                Usuarios               usuario            = db.Usuarios.Include(x => x.notificaciones).FirstOrDefault(x => x.correo.Equals(user));
                List <Notificacion>    notificacionsModel = usuario.notificaciones;
                List <NotificacionDTO> responseList       = new List <NotificacionDTO>();

                //Mapeo de clase
                notificacionsModel.ForEach(x =>
                {
                    NotificacionDTO response = new NotificacionDTO();
                    response.notificacion    = x.notificacion;
                    response.anuncio         = anunciosDAO.getById(x.anuncio.id);
                    response.id = x.id;
                    responseList.Add(response);
                });
                return(responseList);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #9
0
 public async Task SendNotification(string user, NotificacionDTO notificacion)
 {
     await Clients.Group(user).SendAsync("ReceiveNotification", user, notificacion);
 }
        public void crearNotificaciones(string user)
        {
            try
            {
                var             userModel    = FindUser(user);
                var             today        = DateTime.Today;
                NotificacionDTO notificacion = new NotificacionDTO();
                Notificacion    respone      = new Notificacion();
                userModel.anuncios.ForEach(x =>
                {
                    TimeSpan fechaResultado = (x.fechaCancelacion - today);
                    int totalDays           = (int)fechaResultado.TotalDays;

                    if (totalDays == 3)
                    {
                        notificacion.notificacion = Helpers.Constants.Anuncios.notif3dias;
                        notificacion.anuncio      = x;
                        notificacion.fecha        = DateTime.Today;
                        notificacion.check        = false;
                    }
                    else if (totalDays == 5)
                    {
                        notificacion.notificacion = Helpers.Constants.Anuncios.notif5dias;
                        notificacion.anuncio      = x;
                        notificacion.fecha        = DateTime.Today;
                        notificacion.check        = false;
                    }
                    else if (totalDays <= 0)
                    {
                        notificacion.notificacion = Helpers.Constants.Anuncios.notif0dias;
                        notificacion.anuncio      = x;
                        notificacion.fecha        = x.fechaCancelacion;
                        notificacion.check        = false;
                    }
                    bool exists        = false;
                    var notificaciones = getList(user);
                    if (!string.IsNullOrEmpty(notificacion.notificacion))
                    {
                        notificaciones.ForEach(y =>
                        {
                            if (notificacion.anuncio.id == y.anuncio.id && notificacion.notificacion.Equals(y.notificacion))
                            {
                                exists = true;
                            }
                        });

                        if (!exists)
                        {
                            Notificacion model = new Notificacion();
                            model.notificacion = notificacion.notificacion;
                            model.fecha        = x.fechaCancelacion;
                            model.check        = false;
                            model.anuncio      = db.Anuncios.First(z => z.id == notificacion.anuncio.id);
                            Usuarios usuario   = db.Usuarios.FirstOrDefault(w => w.correo.Equals(user));
                            usuario.notificaciones.Add(model);
                            db.Entry(usuario).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #11
0
        public List <NotificacionDTO> obtenerNotificacion(NotificacionDTO notificacionDTO)
        {
            List <NotificacionDTO> listaNotificacionDTO = new List <NotificacionDTO>();

            return(listaNotificacionDTO);
        }