public static ulong Add(NotifiedUser newRecord) { return(DbUtils.ConnectAndExecute(conn => { var query = "INSERT INTO engine4_advancedactivity_notificationsettings(action_id,user_ids) " + "VALUES (@action_id,@user_ids)"; var cmd = new MySqlCommand(query, conn); cmd.Parameters.AddWithValue("action_id", newRecord.action_id); cmd.Parameters.AddWithValue("user_ids", newRecord.user_ids); var rc = cmd.ExecuteNonQuery(); Console.WriteLine($"adding notified users {newRecord.user_ids} to action {newRecord.action_id} resulted in {rc}"); return (ulong)rc; })); }
public override void Execute() { //get notifications record for action_id var record = DAL.Adapters.NotifiedUsers.GetRecord(reqParams.action_id); if (record == null) { //if recode does not exist, add it with user and set user as notified in activity NotifiedUser newRecord = new NotifiedUser() { action_id = (int)reqParams.action_id, user_ids = $"[{userId}]" }; activity.NotifiedUsers.Add(userId); DAL.Adapters.NotifiedUsers.Add(newRecord); } else { if (!record.ContainsUser(userId)) { //if record exists and not containing the user, add the user and set as notified in activity record.AddUser(userId); DAL.Adapters.NotifiedUsers.Update(record); activity.NotifiedUsers.Add(userId); } else { //if record exists and contains the user, remove the user and remove it from the activity record.RemoveUser(userId); if (string.IsNullOrEmpty(record.user_ids)) { DAL.Adapters.NotifiedUsers.Remove((uint)record.action_id); } else { DAL.Adapters.NotifiedUsers.Update(record); } activity.NotifiedUsers.Remove(userId); } } }
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 !" })); }
//POST api/notifiedUser public NotifiedUser Post([FromBody] NotifiedUser notifiedUser) { return(DataAccessHelper <NotifiedUser> .AddEntity(notifiedUser)); }
public static void Update(NotifiedUser record) { Remove((uint)record.action_id); Add(record); }