public CMSResult SendAppNotification(StudentTimetableViewModel viewModel, int studentClassTimetableId) { CMSResult cmsResult = new CMSResult(); var notificationList = new List <SendNotificationByPlayerId>(); try { var studentsList = _studentService.GetAllStudentParentList(); if (viewModel.SelectedBranches != null) { var branches = viewModel.SelectedBranches.Split(',').Select(x => int.Parse(x)).ToList(); studentsList = studentsList.Where(x => branches.Contains(x.BranchId)); } if (viewModel.SelectedClasses != null) { var classes = viewModel.SelectedClasses.Split(',').Select(x => int.Parse(x)).ToList(); studentsList = studentsList.Where(x => classes.Contains(x.ClassId)); } if (viewModel.SelectedBatches != null) { var batches = viewModel.SelectedBatches.Split(',').Select(x => int.Parse(x)).ToList(); studentsList = studentsList.Where(x => batches.Contains(x.BatchId)); } var parentPlayerIds = studentsList.Where(x => !string.IsNullOrEmpty(x.parentAppPlayerId)).ToList(); foreach (var playerId in parentPlayerIds) { var studentSId = playerId.SId; var sendAppNotification = new SendNotificationByPlayerId { Message = "CTT-" + viewModel.Description + "$^$" + playerId.SId + "@" + studentClassTimetableId, PlayerIds = playerId.parentAppPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notificationList.Add(sendAppNotification); } var notification = notificationList.ToArray(); if (notificationList.Count > 0) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); cmsResult.Results.Add(new Result { Message = "App Notification sent successfully.", IsSuccessful = true }); } else { cmsResult.Results.Add(new Result { Message = "No one is registered in parent app.", IsSuccessful = true }); } } catch (Exception ex) { cmsResult.Results.Add(new Result { Message = ex.Message, IsSuccessful = true }); } return(cmsResult); }
public CMSResult SendAppNotification(OfflineTestPaperViewModel viewModel, List <ListOfPlayerId> listOfPlayerId, List <ListOfPlayerId> listOfStudentId, int offlineTestPaperId) { var cmsResult = new CMSResult(); var notificationList = new List <SendNotificationByPlayerId>(); foreach (var playerId in listOfPlayerId) { var studentSId = playerId.SId; var sendAppNotification = new SendNotificationByPlayerId { Message = "OfflineTest-<br />" + viewModel.Title + " offline test paper on " + viewModel.TestDate.ToString("dd-MM-yyyy") + ", Total Marks - " + viewModel.TotalMarks + "$^$" + playerId.SId + "@" + offlineTestPaperId, PlayerIds = playerId.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notificationList.Add(sendAppNotification); } foreach (var playerId in listOfStudentId) { var studentSId = playerId.SId; var sendAppNotification = new SendNotificationByPlayerId { Message = "OfflineTest-<br />" + viewModel.Title + " offline test paper on " + viewModel.TestDate.ToString("dd-MM-yyyy") + ", Total Marks - " + viewModel.TotalMarks + "$^$" + playerId.SId + "@" + offlineTestPaperId, PlayerIds = playerId.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.StudentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.StudentRestAppId] }; notificationList.Add(sendAppNotification); } var notification = notificationList.ToArray(); if (notificationList.Count > 0) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); cmsResult.Results.Add(new Result { Message = "App Notification sent successfully.", IsSuccessful = true }); } else { cmsResult.Results.Add(new Result { Message = "No one is registered in parent app.", IsSuccessful = true }); } return(cmsResult); }
public CMSResult SendAppNotification(TestPaperDeleteViewModel viewmodel, List <ListOfPlayerId> listOfParentPlayerId, List <ListOfPlayerId> listOfStudentPlayerId, int arrangeTestId) { var notificationList = new List <SendNotificationByPlayerId>(); var cmsResult = new CMSResult(); listOfParentPlayerId = listOfParentPlayerId.Where(s => !string.IsNullOrWhiteSpace(s.ParentPlayerId)).ToList(); listOfStudentPlayerId = listOfStudentPlayerId.Where(s => !string.IsNullOrWhiteSpace(s.ParentPlayerId)).ToList(); foreach (var playerid in listOfParentPlayerId) { var sendAppNotification = new SendNotificationByPlayerId { Message = "Test-" + viewmodel.Title + "$^$Date:" + viewmodel.Date.ToString("dd-MM-yyyy").Split(' ')[0] + "$^$Start Time:" + viewmodel.StartTime + "$^$Duration:" + viewmodel.TimeDuration + "$^$TestPaperId:" + viewmodel.TestPaperId + "$^$" + 1 + "," + arrangeTestId, PlayerIds = playerid.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notificationList.Add(sendAppNotification); } foreach (var playerid in listOfStudentPlayerId) { var sendAppNotification = new SendNotificationByPlayerId { Message = "Test-" + viewmodel.Title + "$^$Date:" + viewmodel.Date.ToString("dd-MM-yyyy").Split(' ')[0] + "$^$Start Time:" + viewmodel.StartTime + "$^$Duration:" + viewmodel.TimeDuration + "$^$TestPaperId:" + viewmodel.TestPaperId + "$^$" + 1 + "," + arrangeTestId, PlayerIds = playerid.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.StudentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.StudentRestAppId] }; notificationList.Add(sendAppNotification); } if (notificationList.Count > 0) { var notification = notificationList.ToArray(); HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); cmsResult.Results.Add(new Result { Message = "App Notification sent successfully.", IsSuccessful = true }); return(cmsResult); } else { cmsResult.Results.Add(new Result { Message = "No one is registered in parent app.", IsSuccessful = false }); return(cmsResult); } }
public CMSResult SendAppNotification(IEnumerable <SendAttendanceClass> resultGroup) { var cmsResult = new CMSResult(); List <string> listOfPlayerId = new List <string>(); var i = 0; SendNotificationByPlayerId[] notification = new SendNotificationByPlayerId[resultGroup.Count()]; foreach (var sms in resultGroup) { listOfPlayerId.Add(sms.ParentAppPlayerId); var listOfContact = string.Join(",", listOfPlayerId); if (!(sms.ParentAppPlayerId == "null" || sms.ParentAppPlayerId == "")) { var sendAppNotification = new SendNotificationByPlayerId { Message = "Attendance-" + sms.Message, PlayerIds = sms.ParentAppPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notification[i] = sendAppNotification; i++; } } if (listOfPlayerId.Count > 0) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); cmsResult.Results.Add(new Result { Message = "Send Addendance Notification Successfully.", IsSuccessful = true }); } else { cmsResult.Results.Add(new Result { Message = "No one is registered in parent app.", IsSuccessful = false }); } return(cmsResult); }
public CMSResult SendAppNotification(NotificationViewModel viewModel, List <string> listOfPlayerId, List <ListOfPlayerId> finalPlayerId, int savedNotificationId, List <string> listOfStudentPlayerId, List <ListOfPlayerId> finalStudentPlayerId) { var notificationList = new List <SendNotificationByPlayerId>(); var getfinalPlayerId = (from list in finalPlayerId group finalPlayerId by new { list.SId, list.ParentPlayerId } into grouping select new ListOfPlayerId { SId = grouping.Key.SId, ParentPlayerId = grouping.Key.ParentPlayerId }).ToList(); var getstudentfinalPlayerId = (from list in finalStudentPlayerId group finalStudentPlayerId by new { list.SId, list.ParentPlayerId } into grouping select new ListOfPlayerId { SId = grouping.Key.SId, ParentPlayerId = grouping.Key.ParentPlayerId }).ToList(); var cmsResult = new CMSResult(); listOfPlayerId = listOfPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList(); listOfStudentPlayerId = listOfStudentPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList(); foreach (var playerId in getfinalPlayerId) { var studentSId = playerId.SId; var sendAppNotification = new SendNotificationByPlayerId { Message = "Notice-" + viewModel.NotificationMessage + "$^$" + playerId.SId + "@" + savedNotificationId, PlayerIds = playerId.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notificationList.Add(sendAppNotification); } foreach (var playerId in getstudentfinalPlayerId) { var studentSId = playerId.SId; var sendAppNotification = new SendNotificationByPlayerId { Message = "Notice-" + viewModel.NotificationMessage + "$^$" + playerId.SId + "@" + savedNotificationId, PlayerIds = playerId.ParentPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.StudentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.StudentRestAppId] }; notificationList.Add(sendAppNotification); } var notification = notificationList.ToArray(); if (viewModel.AllUser) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); } else if (notificationList.Count > 0) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); } else if (notificationList.Count == 0) { cmsResult.Results.Add(new Result { Message = "No one is registered in app.", IsSuccessful = false }); return(cmsResult); } cmsResult.Results.Add(new Result { Message = "App Notification Sent Successfully.", IsSuccessful = true }); return(cmsResult); }