Exemple #1
0
 protected virtual void AddChanges(string model, string change, IEnumerable <int> ids)
 {
     if (ids.Any())
     {
         var token = new NotifyToken()
         {
             model = model, change = change, ids = ids
         };
         m_lstNotifyToken.Add(token);
     }
 }
        public static async void PostNotifyToken(string token)
        {
            LoggedUser loggedUser = SQLiteDb.GetUser();

            if (!string.IsNullOrEmpty(token))
            {
                var notifyToken = new NotifyToken
                {
                    UserId = loggedUser.Id,
                    Token  = token
                };
                var httpClient = new HttpClient();
                var url        = "https://pwszalarmwebapi.azurewebsites.net/api/accounts/user/fcmtoken";
                //POST /api/accounts/user/token
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loggedUser.Authorization);
                var tokenJson   = JsonConvert.SerializeObject(notifyToken);
                var httpContent = new StringContent(tokenJson, Encoding.UTF8, "application/json");
                await httpClient.PostAsync(url, httpContent);
            }
        }
Exemple #3
0
        public static async Task UpdateTokenAsync(this IRepository <User> repository, string id, NotifyToken token)
        {
            var user = await repository.Collection.Find(Builders <User> .Filter.Eq(e => e.Id, id)).FirstOrDefaultAsync();

            if (user == null)
            {
                return;
            }
            if (user.Tokens == null)
            {
                await repository.Collection.UpdateOneAsync(e => e.Id == id,
                                                           Builders <User> .Update.Set(e => e.Tokens, new List <NotifyToken>()
                {
                    token
                }));

                return;
            }
            await repository.Collection.UpdateOneAsync(e => e.Id == id,
                                                       Builders <User> .Update.PullFilter(e => e.Tokens, notifyToken => notifyToken.Device == MobileDevice.Android));

            await repository.Collection.UpdateOneAsync(e => e.Id == id,
                                                       Builders <User> .Update.Push(e => e.Tokens, token));
        }