public OrderStatusController(DataContext context, UserManager <User> userManager) { _userManager = userManager; _dataContext = context; _pushNotificationLogic = new PushNotificationLogic(context); }
static void Main(string[] args) { string title = ""; string body = ""; var data = new { action = "Play", userId = 5 }; Console.WriteLine("Hello Everyone!"); Console.WriteLine("Let's send push notifications!!!"); Console.Write("Title of Notification: "); title = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Ok, so now I have the title, I'll need a description"); body = Console.ReadLine(); Console.WriteLine(); Console.Write("How many devices are going to receive this notification? "); int.TryParse(Console.ReadLine(), out int devicesCount); var tokens = new string[devicesCount]; Console.WriteLine(); for (int i = 0; i < devicesCount; i++) { Console.Write($"Token for device number {i + 1}: "); tokens[i] = Console.ReadLine(); Console.WriteLine(); } Console.WriteLine("Do you want to send notifications?"); Console.WriteLine("1 - Yes!!!!"); Console.WriteLine("0 - No, I'm wasting my time!!!"); int.TryParse(Console.ReadLine(), out int sendNotification); if (sendNotification == 1) { var pushSent = PushNotificationLogic.SendPushNotification(tokens, title, body, data); Console.WriteLine($"Notification sent"); } else { Console.WriteLine("BUUUUUU"); } Console.ReadKey(); }
//3. התראה כאשר עבר הדדליין והתלמיד לא הצליח את האתגר עם מלל מנחם ומעודד public void passDeadlineStudentsAlert() { DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable passDeadlineStudentsAlert = dbs.passDeadlineStudentsAlert(); foreach (DataRow row in passDeadlineStudentsAlert.Rows) { string title = "אוי לא הצלחת את האתגר בזמן"; string body = row["firstName"] + " " + row["lastName"] + " היית צריך לסיים את האתגר: " + row["challengeName"] + " עד אתמול "; string toToken = dbs.getStudentToken(Convert.ToInt32(row["studentID"])); if (toToken != "" && toToken != null) { string imgPath = getAvatarImg(Convert.ToInt32(row["studentID"])); PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
//2. התראה עם ספירה לאחור לביצוע האתגר הקרוב אם לא בוצע public void preDeadlineStudentsAlert() { int preDeadlineDays = 5; // החל מ5 ימים לפני דדליין תשלח התראה לתלמיד בכל יום DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable preDeadlineStudentsAlert = dbs.preDeadlineStudentsAlert(preDeadlineDays); foreach (DataRow row in preDeadlineStudentsAlert.Rows) { string title = "צריך לסיים את האתגר"; string body = ""; if (preDeadlineDays == 0) { body = row["firstName"] + " " + row["lastName"] + " יש לך רק את היום להשלים את האתגר: " + row["challengeName"]; } if (preDeadlineDays == 1) { body = row["firstName"] + " " + row["lastName"] + " נשאר לך יום אחד להשלים את האתגר: " + row["challengeName"]; } if (preDeadlineDays == 2) { body = row["firstName"] + " " + row["lastName"] + " נשארו לך יומיים להשלים את האתגר: " + row["challengeName"]; } else { body = row["firstName"] + " " + row["lastName"] + " נשארו לך " + row["daysPreDeadline"] + " ימים להשלים את האתגר: " + row["challengeName"]; } string toToken = dbs.getStudentToken(Convert.ToInt32(row["studentID"])); if (toToken != "" && toToken != null) { string imgPath = getAvatarImg(Convert.ToInt32(row["studentID"])); PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
//----END--התראות אוטומטיות מורה-------- //----START---התראות אוטומטיות לתלמיד------- //1. התראה כל מספר ימים שהתלמיד לא נכנס לאפליקציה public void idleStudentsAlert() { int idleDays = 3; // כל 3 ימים תשלח התראה לתלמיד DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable idleStudentsAlert = dbs.idleStudentsAlert(idleDays); foreach (DataRow row in idleStudentsAlert.Rows) { string title = "שכחת ממני"; string body = "תמשיך לעשות אתגרים כדי שאוכל לגדול"; string toToken = dbs.getStudentToken(Convert.ToInt32(row["studentID"])); if (toToken != "" && toToken != null) { string imgPath = getAvatarImg(Convert.ToInt32(row["studentID"])); PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
//3. לתלמיד נשאר ___ זמן לבצע אתגר public void preDeadlineAlert() { DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable preDeadlineChallenges = dbs.preDeadlineChallenges(); foreach (DataRow row in preDeadlineChallenges.Rows) { string title = "לתלמיד נשארו ימים ספורים להשלים את האתגר"; string body = "לתלמיד " + row["firstName"] + " " + row["lastName"] + " נשארו " + row["daysPreDeadline"] + " ימים להשלים את האתגר: " + row["challengeName"]; string toToken = dbs.getTeacherToken(Convert.ToInt32(row["teacherID"])); Alert alert = new Alert(0, Convert.ToInt32(row["teacherID"]), Convert.ToInt32(row["studentID"]), title, body, alertDate, DateTime.Now.ToString("HH:mm"), false, 5); postAlert(alert); if (toToken != "" && toToken != null) { string imgPath = HostingEnvironment.MapPath("~/logo") + "//logoSmall.svg"; PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
//2. תלמיד לא נכנס לאפליקציה ___ זמן public void idleStudentAlert() { DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable idleStudents = dbs.idleStudents(); foreach (DataRow row in idleStudents.Rows) { string title = "תלמיד לא פעיל"; string body = "התלמיד " + row["firstName"] + " " + row["lastName"] + " לא נכנס לאפליקציה כבר " + row["idleTime"] + " ימים"; string toToken = dbs.getTeacherToken(Convert.ToInt32(row["teacherID"])); Alert alert = new Alert(0, Convert.ToInt32(row["teacherID"]), Convert.ToInt32(row["studentID"]), title, body, alertDate, DateTime.Now.ToString("HH:mm"), false, 6); postAlert(alert); if (toToken != "" && toToken != null) { string imgPath = HostingEnvironment.MapPath("~/logo") + "//logoSmall.svg"; PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
//----START---התראות אוטומטיות למורה------- //1. התראה כאשר עבר דדליין של אתגר והסטטוס שונה מהצליח public void passDeadlineAlert() { DBservices dbs = new DBservices(); DateTime date = DateTime.Now; string alertDate = date.ToString("yyyy-MM-dd"); DataTable passDeadline = dbs.passedDeadlineChallenges(); foreach (DataRow row in passDeadline.Rows) { string title = "אתגר לא בוצע בזמן"; string body = "לתלמיד מכיתה " + row["firstName"] + " " + row["lastName"] + " נגמר הזמן לביצוע האתגר " + row["challengeName"]; string toToken = dbs.getTeacherToken(Convert.ToInt32(row["teacherID"])); Alert alert = new Alert(0, Convert.ToInt32(row["teacherID"]), Convert.ToInt32(row["studentID"]), title, body, alertDate, DateTime.Now.ToString("HH:mm"), false, 4); postAlert(alert); if (toToken != "" && toToken != null) { string imgPath = HostingEnvironment.MapPath("~/logo") + "//logoSmall.svg"; PushNotificationLogic.PushNotification(title, body, toToken, imgPath); } } }
public async Task <ActionResult> addnewIncident(IncidentRequest incidentRequest) { string incidentId = Guid.NewGuid().ToString(); Incident incident = new Incident { Id = incidentId, UserAccountId = incidentRequest.UserAccountId, IncidentTypeId = incidentRequest.IncidentTypeId, IncidentPic = incidentRequest.IncidentPic, Address = incidentRequest.Address, AddressLine = incidentRequest.AddressLine, CoordinateX = incidentRequest.CoordinateX, CoordinateY = incidentRequest.CoordinateY, CustomerComments = incidentRequest.CustomerComments, Status = incidentRequest.Status, Deleted = false, CreatedAt = DateTime.Now }; appDbContex.Incidents.Add(incident); await appDbContex.SaveChangesAsync(); List <ApplicationUser> usersToNotify = new List <ApplicationUser>(); FindUsers findUsers = new FindUsers(appDbContex, userManager); usersToNotify = findUsers.FindUsersToNotifybyCoordinateXY(incidentRequest.CoordinateX, incidentRequest.CoordinateY, incidentRequest.IncidentTypeId); PushNotificationLogic pushNotificationLogic = new PushNotificationLogic(); // string[] androidDeviceTocken; List <string> androidDeviceTocken = new List <string>(); SendSms sendsms = new SendSms(); var incidenttypeName = appDbContex.IncidentTypes.Where(a => a.Id == incidentRequest.IncidentTypeId).FirstOrDefault(); string contactNumber = string.Empty; string location = "http://maps.google.com/?q=" + incidentRequest.CoordinateX + "," + incidentRequest.CoordinateY + ""; string notificationMessage = string.Empty; foreach (var user in usersToNotify) { //if (user.Source == "Android") //{ // androidDeviceTocken.Add(user.PushTokenId); //} if (user.EmergencyContactNo != null) { //Notification to Emergency Contact contactNumber = user.InternationalPrefix.ToString() + user.PhoneNumber.ToString(); notificationMessage = "Here is the " + incidenttypeName.Name + " incident happen... please click here " + location; // sendsms.SendTextSms(notificationMessage, contactNumber); } else { //Notification to Application Users contactNumber = user.InternationalPrefix.ToString() + user.PhoneNumber.ToString(); notificationMessage = "Here is the " + incidenttypeName.Name + " incident happen... please click here " + location; // sendsms.SendTextSms(notificationMessage, contactNumber); } NotifiedUser notifiedUser = new NotifiedUser { Id = Guid.NewGuid().ToString(), IncidentId = incidentId, UserId = user.Id, CreatedAt = DateTime.Now }; appDbContex.NotifiedUsers.Add(notifiedUser); await appDbContex.SaveChangesAsync(); IncidentUserMessage incidentUserMessage = new IncidentUserMessage { Id = Guid.NewGuid().ToString(), IncidentId = incidentId, UserId = user.Id, Status = incidentRequest.Status, StatusMessage = notificationMessage, CreatedAt = DateTime.Now }; appDbContex.IncidentUserMessages.Add(incidentUserMessage); await appDbContex.SaveChangesAsync(); } try { // androidDeviceTocken = null; // androidDeviceTocken.Add("f4e9GJxSvYA:APA91bGkImijMYelYhFCqFTE6qDzEfzeEdM6H3Q1XwxxCDvYWZGdyviRGtPSdTcyeXy4787JPwfb04pFNWo5dXIc420EVZEQ15UtHqTCAn8kk8zdAJ8pgRLLMNbKkJ1dfR5ABMoMJd71"); // androidDeviceTocken.Add("ccSVgC04gaM:APA91bGt8rDg-1CyG5N9pxW5aXWs9x4jpf6rXYXRu0usnaiMzgfosr5Guv89iJbiHBvUcOYkGf2RIJBx_-jtK_76bZwk__d3Xn94TSXLmaC8rs9GEnIvX5AOldPXqp1EiUvIrt1zfQcr"); androidDeviceTocken.Add("dndndqNSHbs:APA91bFrO7Au5DvoYIgFaWY1S7PLAzzcwZ9EcuwjKvqFBdM-733zwDKCWnT5JZ9FcSVsUb1JwYUWCElXmFpgd6BXkTcUn9ejhvrwvB0eIC9Mpn4komqfT_APS2TaX9ZtZ_a_TbjfFswH"); if (androidDeviceTocken != null) { // Myobject myobj = new Myobject // { // Name = "Bhavin", // City = "vapi" // }; var myobj = new { Name = "Bhavin", City = "Vapi" }; await pushNotificationLogic.SendPushNotification(androidDeviceTocken, "SecureAfrica", notificationMessage, myobj); } } catch (Exception ex) { } await _hubContext.Clients.All.BroadcastMessage("success", "this is our msg"); return(Ok(new { Message = "Incident added successfully !" })); }
public PushNotifResp SendPushNotification(SendPushNotifReq req) { PushNotifResp res = new PushNotifResp(); //Send Notif here var tokens = req.Tokens; var pushSent = PushNotificationLogic.SendPushNotification(tokens, req.MesssageTitle, req.MesssageBody, req.Image).Result; if (pushSent) { SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@Title", req.MesssageTitle), new SqlParameter("@Body", req.MesssageBody), new SqlParameter("@Image", req.Image), new SqlParameter("@SentStatus", 1), }; SqlResModel insertToken = SqlDbHelper.InsertWithParam(ConstantManager.EOneConnString(), "proc_InsertPushMessage", CommandType.StoredProcedure, sqlParams); if (insertToken.ResponseCode == "00" && insertToken.ResultInt > 0) { ErrHandler.Log("Push Notification Sent and logged successfully on PUshMessages DB for target token Ids"); } else { ErrHandler.Log("Push Notification successfully Sent to target token Ids but an error occured while trying to log the Message on PushMessages DB"); } res.ResponseCode = "00"; res.ResponseDescription = "successful"; res.TokenCount = tokens.Length; res.CustomerId = req.CustomerId; res.SentStatus = 1; } else { SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@Title", req.MesssageTitle), new SqlParameter("@Body", req.MesssageBody), new SqlParameter("@Image", req.Image), new SqlParameter("@SentStatus", 0), }; SqlResModel insertToken = SqlDbHelper.InsertWithParam(ConstantManager.EOneConnString(), "proc_InsertPushMessage", CommandType.StoredProcedure, sqlParams); if (insertToken.ResponseCode == "00" && insertToken.ResultInt > 0) { ErrHandler.Log("Failed to send Push Notification for target token Ids. Messages details has been logged to the PushMessages DB"); } else { ErrHandler.Log("Failed in logging Message details for the failed Push Notification"); } res.ResponseCode = "01"; res.ResponseDescription = "failed"; res.TokenCount = 0; res.CustomerId = req.CustomerId; res.SentStatus = 0; } return(res); }