コード例 #1
0
        public async Task <ReportToTeacherByScheduleIdResponse> ReportToTeacherByScheduleId(ReportToTeacherByScheduleIdRequest request)
        {
            int scheduleId       = Convert.ToInt32(request.ScheduleId);
            var reportedSchedule = _context.Schedules
                                   .Where(s => s.ScheduleId == scheduleId)
                                   .FirstOrDefault();

            if (reportedSchedule != null)
            {
                // Change attendance report status to Reported
                reportedSchedule.ReportStatus = "Reported";
                _context.SaveChanges();

                FirebaseNotificationModel firebaseNotiModel = new FirebaseNotificationModel()
                {
                    To           = "/topics/teacher_" + reportedSchedule.TeacherId,
                    Notification = new NotificationModel()
                    {
                        Title = "Attendance Report Date " + reportedSchedule.Date,
                        Body  = "Student with ID " + reportedSchedule.StudentId + " has reported attendance on slot " + reportedSchedule.SlotId
                    }
                };

                // Send notification to the responsible teacher and return response
                return(await FirebaseNotificationPusher.Send(firebaseNotiModel));
            }

            return(null);
        }
コード例 #2
0
    public static async void Send(FirebaseNotificationModel firebaseModel)
    {
        HttpRequestMessage httpRequest = null;
        HttpClient         httpClient  = null;
        //var authorizationKey = string.Format("key={0}", "YourFirebaseServerKey");
        var jsonBody = JsonConvert.SerializeObject(firebaseModel);

        try
        {
            string server_api_key = ConfigurationManager.AppSettings["SERVER_API_KEY"];
            string sender_id      = ConfigurationManager.AppSettings["SENDER_ID"];
            httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send");

            var authorizationKey = string.Format("key={0}", server_api_key);
            httpRequest.Headers.TryAddWithoutValidation("Authorization", authorizationKey);
            httpRequest.Headers.Add("Sender", sender_id);

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

            httpClient = new HttpClient();
            using (await httpClient.SendAsync(httpRequest))
            {
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            httpRequest.Dispose();
            httpClient.Dispose();
        }
    }
コード例 #3
0
        public IHttpActionResult Teste()
        {
            try
            {
                var nomeRanking = db.BarragemView.Find(8).nome;
                var titulo      = nomeRanking + ": classificação atualizada e nova rodada gerada!";
                var conteudo    = "Clique aqui e entre em contato com seu adversário o mais breve possível e bom jogo.";

                var fbmodel = new FirebaseNotificationModel()
                {
                    to = "/topics/ranking8", notification = new NotificationModel()
                    {
                        title = titulo, body = conteudo
                    }, data = new DataModel()
                    {
                        title = titulo, body = conteudo, type = "nova_rodada_aberta", idRanking = 8
                    }
                };
                new FirebaseNotification().SendNotification(fbmodel);
            }
            catch (Exception e)
            {
                return(InternalServerError(new Exception("Erro: " + e.Message)));
            }
            return(Ok("Teste"));
        }
コード例 #4
0
        public async static Task SendNotification(FirebaseNotificationModel model)
        {
            var client = Helpers.BsdHttpClient.Instance();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("key", "=" + Configuration.ApiConfig.FIREBASE_SERVER_KEY);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            string      objContent = JsonConvert.SerializeObject(model);
            HttpContent content    = new StringContent(objContent, Encoding.UTF8, "application/json");
            var         response   = await client.PostAsync("https://fcm.googleapis.com/fcm/send", content);
        }
コード例 #5
0
 public void SendNotification(FirebaseNotificationModel data)
 {
     try {
         string server_api_key = ConfigurationManager.AppSettings["SERVER_API_KEY"];
         string sender_id      = ConfigurationManager.AppSettings["SENDER_ID"];
         var    httpWebRequest = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
         httpWebRequest.Method      = "post";
         httpWebRequest.ContentType = "application/json";
         httpWebRequest.Headers.Add($"Authorization: key={server_api_key}");
         using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())){
             string json = new JavaScriptSerializer().Serialize(data);
             streamWriter.Write(json);
         }
         var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
         using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
         {
             var result = streamReader.ReadToEnd();
         }
     } catch (Exception e) {
         throw e;
     }
 }
コード例 #6
0
        public void NotificacaoApp(int barragemId)
        {
            try
            {
                var nomeRanking = db.BarragemView.Find(barragemId).nome;
                var titulo      = nomeRanking + ": Classificação atualizada e nova rodada gerada!";
                var conteudo    = "Clique aqui e entre em contato com seu adversário o mais breve possível e bom jogo.";

                var fbmodel = new FirebaseNotificationModel()
                {
                    to = "/topics/ranking" + barragemId, notification = new NotificationModel()
                    {
                        title = titulo, body = conteudo
                    }, data = new DataModel()
                    {
                        title = titulo, body = conteudo, type = "nova_rodada_aberta", idRanking = barragemId
                    }
                };
                new FirebaseNotification().SendNotification(fbmodel);
            }
            catch (Exception e)
            {
            }
        }
コード例 #7
0
        public static async Task <ReportToTeacherByScheduleIdResponse> Send(FirebaseNotificationModel firebaseNotifiModel)
        {
            HttpRequestMessage httpRequest = null;
            HttpClient         httpClient  = null;

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

            try
            {
                httpRequest = new HttpRequestMessage(HttpMethod.Post, FIREBASE_PUSH_URL);
                httpRequest.Headers.TryAddWithoutValidation("Authorization", authorizationKey);
                httpRequest.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

                httpClient = new HttpClient();
                HttpResponseMessage responseMessage = await httpClient.SendAsync(httpRequest);

                return(null);
            }
            catch
            {
                throw;
            }
        }