Exemplo n.º 1
0
 /// <summary>
 /// Remove todas as assinaturas de um usuário com o filtro de topico
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public bool UnsubscribeAll(long userId, string topicPrefix)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         string query = "UPDATE  Push_Subscription SET Status = 0 WHERE  UserId = " + userId + " AND Topic LIKE '" + topicPrefix + "%'";
         int    count = context.Database.ExecuteSqlCommand(query);
         return(count > 0);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Remove todos os devices de um usuário
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public bool RemoveAllDevices(long userId)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         string query = "UPDATE  Push_Device SET Status = 0 WHERE  UserId = " + userId;
         int    count = context.Database.ExecuteSqlCommand(query);
         return(count > 0);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Atualiza uma assinatura para a categoria
 /// </summary>
 /// <param name="subscription"></param>
 public void UpdateSubscription(PushSubscriptionEntity subscription)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         subscription.LastUpdate = DateTime.UtcNow;
         context.PushSubscriptions.Attach(subscription);
         context.Entry(subscription).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Recupera o primeiro device ativo do usuário
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DeviceEntity GetUserDevice(long userId)
        {
            using (BrokerModelContext context = new BrokerModelContext())
            {
                var query = from d in context.Devices
                            where d.UserId == userId && d.Status == GenericStatus.ACTIVE
                            select d;

                return(query.FirstOrDefault());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Busca contas
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List <DeviceEntity> GetAll()
        {
            using (BrokerModelContext context = new BrokerModelContext())
            {
                var query = from d in context.Devices
                            where d.Status == GenericStatus.ACTIVE
                            select d;

                return(query.ToList());
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Cria um novo device
 /// </summary>
 /// <param name="newDevice"></param>
 /// <returns></returns>
 public DeviceEntity UpdateDevice(DeviceEntity updateDevice)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         updateDevice.LastUpdate = DateTime.UtcNow;
         context.Devices.Attach(updateDevice);
         context.Entry(updateDevice).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     return(updateDevice);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Cria uma assinatura para a categoria
 /// </summary>
 /// <param name="subscription"></param>
 public void RegisterSubscription(PushSubscriptionEntity subscription)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         subscription.Status     = GenericStatus.ACTIVE;
         subscription.LastUpdate = DateTime.UtcNow;
         context.PushSubscriptions.Attach(subscription);
         context.Entry(subscription).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Cria um novo device
 /// </summary>
 /// <param name="newDevice"></param>
 /// <returns></returns>
 public DeviceEntity CreateDevice(DeviceEntity newDevice)
 {
     using (BrokerModelContext context = new BrokerModelContext())
     {
         newDevice.Status     = GenericStatus.ACTIVE;
         newDevice.LastUpdate = DateTime.UtcNow;
         context.Devices.Attach(newDevice);
         context.Entry(newDevice).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
     return(newDevice);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Recupera a assinatura de um tópico
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="deviceId"></param>
        /// <param name="topic"></param>
        /// <returns></returns>
        public List <PushSubscriptionEntity> GetPushSubscriptions(long userId, string topic)
        {
            using (BrokerModelContext context = new BrokerModelContext())
            {
                var query = from p in context.PushSubscriptions
                            where p.Status == GenericStatus.ACTIVE &&
                            p.UserId == userId && p.Topic.Contains(topic)
                            select p;

                return(query.ToList());
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Recupera a assinatura de um tópico
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="deviceId"></param>
        /// <param name="topic"></param>
        /// <returns></returns>
        public PushSubscriptionEntity GetPushSubscription(long userId, long deviceId, string topic)
        {
            using (BrokerModelContext context = new BrokerModelContext())
            {
                var query = from p in context.PushSubscriptions
                            where p.Status == GenericStatus.ACTIVE &&
                            p.UserId == userId &&
                            p.DeviceId == deviceId &&
                            p.Topic == topic
                            select p;

                return(query.FirstOrDefault());
            }
        }