Esempio n. 1
0
        public static async Task <bool> SendPushNotification(string id, string title, string body)
        {
            string deviceToken         = null;
            HttpResponseMessage result = null;

            //get token
            using (OnlineAuctionEntities db = new OnlineAuctionEntities())
            {
                deviceToken = db.tblBiddersInfoes.Where(b => b.BiddersId == id).Select(token => token.FCMToken).FirstOrDefault();
            }

            bool sent = false;

            var messageInformation = new Message()
            {
                notification = new Notification()
                {
                    title = title,
                    body  = body
                },
                to = deviceToken
            };


            HttpRequestMessage httpRequest = null;

            var authorizationKey = string.Format("key={0}", ServerKey);
            var jsonBody         = JsonConvert.SerializeObject(messageInformation);


            httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send");

            httpRequest.Headers.TryAddWithoutValidation("Authorization", authorizationKey);
            httpRequest.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            using (var client = new HttpClient())
            {
                result = await client.SendAsync(httpRequest);

                sent = result.IsSuccessStatusCode;
            }

            return(sent);
        }
Esempio n. 2
0
        public override string[] GetRolesForUser(string username)
        {
            string[] user_role = new string[1];

            using (OnlineAuctionEntities _context = new OnlineAuctionEntities())
            {
                var data = (from a in _context.tblUserManagements
                            join b in _context.tblUsersRoles on a.RoleId equals b.RoleId
                            where a.UserName == username

                            select new
                {
                    b.RoleName
                }).FirstOrDefault();


                user_role[0] = data.RoleName;

                return(user_role);
            }
        }