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 async Task <ActionResult> updateIncidentStatus(UpdateIncidentStatusRequest updateIncidentStatusRequest) { Incident incident = appDbContex.Incidents.Where(a => a.Id == updateIncidentStatusRequest.Id).FirstOrDefault(); if (incident != null) { if (incident.EmergencyAccountId == null || incident.EmergencyAccountId == updateIncidentStatusRequest.EmergencyAccountId) { incident.EmergencyAccountId = updateIncidentStatusRequest.EmergencyAccountId; incident.Status = updateIncidentStatusRequest.Status; incident.UpdatedAt = DateTime.Now; await appDbContex.SaveChangesAsync(); List <ApplicationUser> usersToNotify = new List <ApplicationUser>(); FindUsers findUsers = new FindUsers(appDbContex, userManager); usersToNotify = findUsers.FindUsersToNotifybyCoordinateXY(incident.CoordinateX, incident.CoordinateY, incident.IncidentTypeId); SendSms sendsms = new SendSms(); string contactNumber = string.Empty; var incidenttypeName = appDbContex.IncidentTypes.Where(a => a.Id == incident.IncidentTypeId).FirstOrDefault(); foreach (var user in usersToNotify) { NotifiedUser notifiedUser = appDbContex.NotifiedUsers.Where(a => a.IncidentId == updateIncidentStatusRequest.Id && a.UserId == user.Id).FirstOrDefault(); if (notifiedUser == null) { NotifiedUser addNotifiedUser = new NotifiedUser { Id = Guid.NewGuid().ToString(), IncidentId = updateIncidentStatusRequest.Id, UserId = user.Id, CreatedAt = DateTime.Now }; appDbContex.NotifiedUsers.Add(addNotifiedUser); await appDbContex.SaveChangesAsync(); } } List <NotifiedUser> lstnotifiedUsers = appDbContex.NotifiedUsers.Where(a => a.IncidentId == updateIncidentStatusRequest.Id).ToList(); List <ApplicationUser> usersToNotify1 = new List <ApplicationUser>(); foreach (var user in lstnotifiedUsers) { ApplicationUser appUser = userManager.Users.Where(a => a.Id == user.UserId).FirstOrDefault(); if (appUser != null) { usersToNotify1.Add(appUser); } } string notificationMessage = string.Empty; string location = "http://maps.google.com/?q=" + incident.CoordinateX + "," + incident.CoordinateY + ""; foreach (var user in usersToNotify1) { 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 User contactNumber = user.InternationalPrefix.ToString() + user.PhoneNumber.ToString(); notificationMessage = "Here is the " + incidenttypeName.Name + " incident happen... please click here " + location; sendsms.SendTextSms(notificationMessage, contactNumber); } IncidentUserMessage incidentUserMessage = new IncidentUserMessage { Id = Guid.NewGuid().ToString(), IncidentId = updateIncidentStatusRequest.Id, UserId = user.Id, Status = updateIncidentStatusRequest.Status, StatusMessage = notificationMessage, CreatedAt = DateTime.Now }; appDbContex.IncidentUserMessages.Add(incidentUserMessage); await appDbContex.SaveChangesAsync(); } } return(Ok(new { Message = "Incident Updated successfully !" })); } return(BadRequest(new { Message = "Incident Not Found !" })); }