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(UploadOfflineMarksViewModel viewModel, List <StudentProjection> studentList, List <UploadOfflineTestMarks> uploadOfflineTestMarks) { var cmsResult = new CMSResult(); var notificationList = new List <SendNotificationByPlayerId>(); foreach (var playerId in uploadOfflineTestMarks) { var student = studentList.Where(x => x.Email == playerId.EmailId).FirstOrDefault(); var message = "Absent for offline test paper." + "$^$" + student.SId + "@0"; if (playerId.IsPresent) { message = "<br />Name - " + student.Name + "<br />Title - " + viewModel.Title + "<br />Marks - " + playerId.ObtainedMarks + "/" + viewModel.TotalMarks + "<br />Percentage - " + playerId.Percentage + "$^$" + student.SId + "@0"; } if (student.parentAppPlayerId != null && student.parentAppPlayerId != "") { var sendParentAppNotification = new SendNotificationByPlayerId { Message = "Marks-" + message, PlayerIds = student.parentAppPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.ParentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.ParentRestAppId] }; notificationList.Add(sendParentAppNotification); } if (student.studentAppPlayerId != null && student.studentAppPlayerId != "") { var sendStudentAppNotification = new SendNotificationByPlayerId { Message = "Marks-" + message, PlayerIds = student.studentAppPlayerId, AppIds = ConfigurationManager.AppSettings[Common.Constants.StudentAppId], RestApiKey = ConfigurationManager.AppSettings[Common.Constants.StudentRestAppId] }; notificationList.Add(sendStudentAppNotification); } } 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(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 bool SendAppNotification(NotificationProjection viewModel, List <string> listOfPlayerId, List <ListOfPlayerId> finalPlayerId, int savedNotificationId) { var sendNotificationService = DependencyResolver.Current.GetService <ISendNotificationService>(); 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(); listOfPlayerId = listOfPlayerId.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList(); if (listOfPlayerId.Count > 0) { var i = 0; SendNotificationByPlayerId[] notification = new SendNotificationByPlayerId[getfinalPlayerId.Count()]; 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] }; notification[i] = sendAppNotification; i++; } if (viewModel.AllUser) { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); } else { HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => sendNotificationService.StartProcessingByPlayerId(notification, cancellationToken)); } } return(true); }
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 SendNotificationSingle(SendNotificationByPlayerId model) { var cmsResult = new CMSResult(); var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest; request.KeepAlive = true; request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; var authorizationValue = string.Format("Basic {0}", model.RestApiKey); request.Headers.Add("authorization", authorizationValue); var serializer = new JavaScriptSerializer(); var obj = new { app_id = model.AppIds, contents = new { en = model.Message }, include_player_ids = new string[] { model.PlayerIds }, content_available = 1, priority = 10 }; var param = serializer.Serialize(obj); byte[] byteArray = Encoding.UTF8.GetBytes(param); string responseContent = null; try { using (var writer = request.GetRequestStream()) { writer.Write(byteArray, 0, byteArray.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reader = new StreamReader(response.GetResponseStream())) { responseContent = reader.ReadToEnd(); } } } catch (WebException ex) { _logger.Error(ex.Message + "SendNotificationSingle"); cmsResult.Results.Add(new Result { Message = ex.Message, IsSuccessful = false }); return(cmsResult); } System.Diagnostics.Debug.WriteLine(responseContent); var jsonResponseObject = (JObject)JsonConvert.DeserializeObject <dynamic>(responseContent); var errorData = (jsonResponseObject["errors"]); if (errorData == null) { cmsResult.Results.Add(new Result { Message = "App notification sent successfully.", IsSuccessful = true }); return(cmsResult); } cmsResult.Results.Add(new Result { Message = "Error occured.", IsSuccessful = false }); return(cmsResult); }
public HttpResponseMessage StudetnList(MachineAttendence data) { List <int> attendanceId = new List <int>(); List <StudentDetails> studentAttendanceList = new List <StudentDetails>(); try { int branchId = _machineSevice.IsMachineExists(data.MachineSerial); if (branchId != 0) { var attendances = _attendanceService.GetAttendanceToSendNotification(branchId, DateTime.Now); foreach (var attendance in attendances) { var students = _studentService.GetStudentsByBranchAndClassIdForAttendance(attendance.ClassId, branchId, attendance.Date); foreach (var student in students) { if (attendance.BatchId == student.BatchId) { var sid = attendance.StudentAttendence.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(int.Parse); if (student.parentAppPlayerId != null) { if (sid.Contains(student.SId)) { studentAttendanceList.Add(new StudentDetails { SId = student.SId, ParentAppPlayerId = student.parentAppPlayerId, date = attendance.Date, batch = student.BatchName, status = "Present" }); } else { studentAttendanceList.Add(new StudentDetails { SId = student.SId, ParentAppPlayerId = student.parentAppPlayerId, date = attendance.Date, batch = student.BatchName, status = "Absent" }); } } } } attendanceId.AddRange(attendances.Select(x => x.AttendanceId)); } } List <string> listOfPlayerId = new List <string>(); var i = 0; SendNotificationByPlayerId[] notification = new SendNotificationByPlayerId[studentAttendanceList.Count()]; foreach (var appNotification in studentAttendanceList) { listOfPlayerId.Add(appNotification.ParentAppPlayerId); if (!(appNotification.ParentAppPlayerId == null || appNotification.ParentAppPlayerId == "")) { var sendAppNotification = new SendNotificationByPlayerId { Message = "Attendance-" + appNotification.status + "Date : " + appNotification.date + "Batch : " + appNotification.batch, PlayerIds = appNotification.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)); var result = _attendanceService.UpdateMultipleAttendance(string.Join(",", attendanceId)); _logger.Info("Send Notification Successfully."); } } catch (Exception ex) { _logger.Error(ex.ToString() + "StudetnList"); } return(Request.CreateResponse(HttpStatusCode.OK, "send notification successfully.")); }
public HttpResponseMessage Post(MachineAttendence data) { var parentAppId = ConfigurationManager.AppSettings[Constants.ParentAppId]; var parentRestAppId = ConfigurationManager.AppSettings[Constants.ParentRestAppId]; var studentAppId = ConfigurationManager.AppSettings[Constants.ParentAppId]; var studentRestAppId = ConfigurationManager.AppSettings[Constants.ParentRestAppId]; var currentDateTime = _localDateTimeService.GetDateTime(); try { _logger.Info("Sync Data started."); int branchId = _machineSevice.IsMachineExists(data.MachineSerial); if (branchId != 0) { List <StudentAttendanceDetails> studentAttendanceList = new List <StudentAttendanceDetails>(); List <int> dataSId = new List <int>(); dataSId.AddRange(data.PunchDataList.Select(x => x.PunchId)); var getStudentDetailsList = _studentService.GetStudentDetailForAttendanceList(dataSId, branchId); if (getStudentDetailsList.Count() != 0) { foreach (var attData in data.PunchDataList) { var id = attData.PunchId; var punchDate = attData.PunchDateTime.Date; var punchTime = attData.PunchDateTime.ToString(Constants.TimeFormat); var getStudentDetails = getStudentDetailsList.Where(x => x.PunchId == attData.PunchId).FirstOrDefault(); if (getStudentDetails != null) { #region Rough //var punchTime = Convert.ToDateTime(attData.PunchDateTime.ToString("hh:mm tt")); //var punchDate = attData.PunchDateTime.Date; //var inTiming = getStudentDetails.InTime.TimeOfDay; //var beforeTime = inTiming.Add(TimeSpan.FromMinutes(-30)); //var outTiming = getStudentDetails.OutTime.TimeOfDay; //var afterTime = outTiming.Add(TimeSpan.FromMinutes(30)); //if (TimeSpan.Compare(punchTime.TimeOfDay, beforeTime) == 1 && TimeSpan.Compare(punchTime.TimeOfDay, afterTime) == -1) //{ //var batchId = 0; //var batchInTime = new DateTime(); //var batchOutTime = new DateTime(); //batchId = getStudentDetails.BatchId; //batchInTime = getStudentDetails.InTime; //batchOutTime = getStudentDetails.OutTime; //} #endregion studentAttendanceList.Add(new StudentAttendanceDetails { SId = getStudentDetails.SId, PunchId = getStudentDetails.PunchId, ClassId = getStudentDetails.ClassId, PunchDateTime = punchDate, BranchId = getStudentDetails.BranchId, BatchId = getStudentDetails.BatchId, Time = punchTime }); } } #region backup for getting list //var id = attData.PunchId; //var getStudentDetails = _studentService.GetStudentDetailForAttendance(attData.PunchId, branchId); //var batchId = 0; //var batchInTime = new DateTime(); //var batchOutTime = new DateTime(); //if (getStudentDetails != null) //{ // foreach (var batch in getStudentDetails.Batches) // { // var punchTime = Convert.ToDateTime(attData.PunchDateTime.ToString("hh:mm tt")); // var punchDate = attData.PunchDateTime.Date; // if (TimeSpan.Compare(punchTime.TimeOfDay, batch.InTime.TimeOfDay) == 1 && TimeSpan.Compare(punchTime.TimeOfDay, batch.OutTime.TimeOfDay) == -1) // { // batchId = batch.BatchId; // batchInTime = batch.InTime; // batchOutTime = batch.OutTime; // studentAttendanceList.Add(new StudentAttendanceDetails // { // SId = getStudentDetails.SId, // PunchId = getStudentDetails.PunchId, // ClassId = getStudentDetails.ClassId, // PunchDateTime = punchDate, // BranchId = getStudentDetails.BranchId, // BatchId = batchId, // BatchInTime = batchInTime, // BatchOutTime = batchOutTime // }); // } // } //} #endregion } var punchesDateTimeWise = data.PunchDataList.OrderBy(x => x.PunchId).ToList(); var punches = data.PunchDataList.OrderBy(x => x.PunchDateTime).ToList(); if (studentAttendanceList.Count > 0) { var result = (from attendance in studentAttendanceList group attendance by new { attendance.ClassId, attendance.BatchId, attendance.PunchDateTime, attendance.BranchId } into grouping select new StudentAttendanceDetails { ClassId = grouping.Key.ClassId, BatchId = grouping.Key.BatchId, PunchDateTime = grouping.Key.PunchDateTime, BranchId = grouping.Key.BranchId, SelectedAttendance = string.Join(",", grouping.Select(x => x.SId).Distinct()) }); var todayAttendanceList = studentAttendanceList.Where(x => x.PunchDateTime == currentDateTime.Date).ToList(); foreach (var item in result) { var projection = _attendanceService.GetExistingAttendance(item.ClassId, item.BatchId, item.PunchDateTime, item.BranchId); if (projection != null) { #region UpdateAttendance _logger.Info("Update section...."); var jsonObjectInTiming = new List <PunchDetails>(); var jsonObjectOutTiming = new List <PunchDetails>(); var inTiming = JsonConvert.DeserializeObject <List <PunchDetails> >(projection.InTime); var outTiming = projection.OutTime != null? JsonConvert.DeserializeObject <List <PunchDetails> >(projection.OutTime) : new List <PunchDetails>(); var oldAttendanceListDb = projection.StudentAttendence.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(int.Parse).ToList(); var getAttendanceList = item.SelectedAttendance.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(int.Parse).ToList(); _logger.Info(item.SelectedAttendance + " = SelectedAttendance"); List <int> finalRollNos = new List <int>(); finalRollNos.AddRange(oldAttendanceListDb); foreach (var sId in getAttendanceList) { var studentDetails = getStudentDetailsList.Where(x => x.SId == sId).FirstOrDefault(); var punchInTime = punches.Where(x => x.PunchId == studentDetails.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).FirstOrDefault().PunchDateTime.ToString(Constants.TimeFormat); if (!oldAttendanceListDb.Contains(sId)) { finalRollNos.Add(sId); jsonObjectInTiming.Add(new PunchDetails { SId = studentDetails.SId, PunchTime = punchInTime }); } else { var isExistsInLeave = outTiming.Where(x => x.SId == studentDetails.SId).FirstOrDefault(); var isExistsInTime = inTiming.Where(x => x.SId == studentDetails.SId).FirstOrDefault(); #region rough //if (oldAttendanceListDb.Contains(studentDetails.SId)) //{ // isExistsInTime = inTiming.Where(x => x.SId == studentDetails.SId).FirstOrDefault(); //} //if (finalRollNos.Contains(studentDetails.SId)) //{ // isExistsInTime = jsonObjectInTiming.Where(x => x.SId == studentDetails.SId).FirstOrDefault(); //} #endregion if (isExistsInLeave == null) { var countOfPunches = punches.Where(x => x.PunchId == studentDetails.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).ToList().Count(); if (countOfPunches >= 1) { var punchOutTimeLists = punches.Where(x => x.PunchId == studentDetails.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).ToList(); foreach (var punchTime in punchOutTimeLists) { string punchOutTime = ""; punchOutTime = punchTime.PunchDateTime.ToString(Constants.TimeFormat); var duration = DateTime.Parse(punchOutTime) - DateTime.Parse(isExistsInTime.PunchTime); _logger.Info(duration.ToString() + " duration"); if (duration.TotalHours >= 1) { _logger.Info(punchOutTime + " out time Added"); jsonObjectOutTiming.Add(new PunchDetails { SId = studentDetails.SId, PunchTime = punchOutTime }); break; } } } } } } _logger.Info("Update started...."); var sIdList = string.Join(",", finalRollNos); if (jsonObjectInTiming.Count != 0) { inTiming.AddRange(jsonObjectInTiming); } if (jsonObjectOutTiming.Count != 0) { outTiming.AddRange(jsonObjectOutTiming); } var inTimeObject = JsonConvert.SerializeObject(inTiming); var outTimeObject = outTiming != null?JsonConvert.SerializeObject(outTiming) : null; _logger.Info("Json serialize completed...."); var cmsResult = _attendanceService.UpdateAutoAttendance(new Attendance { AttendanceId = projection.AttendanceId, ClassId = projection.ClassId, BatchId = projection.BatchId, UserId = projection.UserId, Activity = projection.Activity, Date = projection.Date, StudentAttendence = sIdList, BranchId = projection.BranchId, IsManual = false, InTime = inTimeObject, OutTime = outTimeObject }); _logger.Info("Update Finished...."); #region SendAPPNotification if (item.PunchDateTime == currentDateTime.Date) { int i = 0; List <SendNotificationByPlayerId> appNotificationModelList = new List <SendNotificationByPlayerId>(); foreach (var inTime in jsonObjectInTiming) { var student = getStudentDetailsList.Where(x => x.PunchId == inTime.SId).FirstOrDefault(); var studentDetails = todayAttendanceList.Where(x => x.PunchId == student.PunchId).FirstOrDefault(); var appNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Intime - {1}.", student.StudentName, inTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.studentAppPlayerId, }; appNotificationModelList.Add(appNotificationModel); var parentAppNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Intime - {1}.", student.StudentName, inTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.parentAppPlayerId, }; appNotificationModelList.Add(parentAppNotificationModel); } foreach (var outTime in jsonObjectOutTiming) { var student = getStudentDetailsList.Where(x => x.PunchId == outTime.SId).FirstOrDefault(); var studentDetails = todayAttendanceList.Where(x => x.PunchId == student.PunchId).FirstOrDefault(); var appNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Outtime - {1}.", student.StudentName, outTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.studentAppPlayerId, }; appNotificationModelList.Add(appNotificationModel); var parentAppNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Outtime - {1}.", student.StudentName, outTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.parentAppPlayerId, }; appNotificationModelList.Add(parentAppNotificationModel); } _logger.Info(i + " exists sms"); if (jsonObjectInTiming.Count > 0 || jsonObjectOutTiming.Count > 0) { var appNotificationModelArray = appNotificationModelList.ToArray(); HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(appNotificationModelArray, cancellationToken)); } } #endregion #endregion } else { #region Save Attendance _logger.Info("Save section...."); var jsonObjectInTiming = new List <PunchDetails>(); var jsonObjectOutTiming = new List <PunchDetails>(); var sIdList = item.SelectedAttendance; var finalRollNos = item.SelectedAttendance.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(int.Parse).ToList(); foreach (var rollNo in finalRollNos) { var studentDetailss = studentAttendanceList.Where(x => x.SId == rollNo).FirstOrDefault(); var punchInTime = punches.Where(x => x.PunchId == studentDetailss.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).FirstOrDefault().PunchDateTime.ToString(Constants.TimeFormat); jsonObjectInTiming.Add(new PunchDetails { SId = studentDetailss.SId, PunchTime = punchInTime }); var countOfPunches = punches.Where(x => x.PunchId == studentDetailss.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).ToList().Count(); if (countOfPunches >= 1) { var punchOutTimeLists = punches.Where(x => x.PunchId == studentDetailss.PunchId && x.PunchDateTime.Date == item.PunchDateTime.Date).ToList(); foreach (var punchTime in punchOutTimeLists) { string punchOutTime = ""; punchOutTime = punchTime.PunchDateTime.ToString(Constants.TimeFormat); var duration = DateTime.Parse(punchOutTime) - DateTime.Parse(punchInTime); if (duration.TotalHours >= 1) { jsonObjectOutTiming.Add(new PunchDetails { SId = studentDetailss.SId, PunchTime = punchOutTime }); break; } } } } _logger.Info("Save started...."); var inTimeObject = JsonConvert.SerializeObject(jsonObjectInTiming); var outTimeObject = jsonObjectOutTiming.Count != 0 ? JsonConvert.SerializeObject(jsonObjectOutTiming) : null; _logger.Info("Json serialize completed...."); //var sIdList = string.Join(",", studentAttendance); var cmsResult = _attendanceService.Save(new Attendance { ClassId = item.ClassId, BatchId = item.BatchId, Activity = "NA", StudentAttendence = sIdList, BranchId = item.BranchId, Date = item.PunchDateTime, IsManual = false, InTime = inTimeObject, OutTime = outTimeObject }); _logger.Info("Save Finished...."); #region SendAPPNotification if (item.PunchDateTime == currentDateTime.Date) { int i = 0; List <SendNotificationByPlayerId> appNotificationModelList = new List <SendNotificationByPlayerId>(); foreach (var inTime in jsonObjectInTiming) { var student = getStudentDetailsList.Where(x => x.PunchId == inTime.SId).FirstOrDefault(); var studentDetails = todayAttendanceList.Where(x => x.PunchId == student.PunchId).FirstOrDefault(); var appNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Intime - {1}.", student.StudentName, inTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.studentAppPlayerId, }; appNotificationModelList.Add(appNotificationModel); var parentAppNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Intime - {1}.", student.StudentName, inTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.parentAppPlayerId, }; appNotificationModelList.Add(parentAppNotificationModel); } foreach (var outTime in jsonObjectOutTiming) { var student = getStudentDetailsList.Where(x => x.PunchId == outTime.SId).FirstOrDefault(); var studentDetails = todayAttendanceList.Where(x => x.PunchId == student.PunchId).FirstOrDefault(); var appNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Outtime - {1}.", student.StudentName, outTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.studentAppPlayerId, }; appNotificationModelList.Add(appNotificationModel); var parentAppNotificationModel = new SendNotificationByPlayerId { Message = string.Format("Today {0} is Present. Outtime - {1}.", student.StudentName, outTime.PunchTime), AppIds = parentAppId, RestApiKey = parentRestAppId, PlayerIds = student.parentAppPlayerId, }; appNotificationModelList.Add(parentAppNotificationModel); } _logger.Info(i + " exists sms"); if (jsonObjectInTiming.Count > 0 || jsonObjectOutTiming.Count > 0) { var appNotificationModelArray = appNotificationModelList.ToArray(); HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => _sendNotificationService.StartProcessingByPlayerId(appNotificationModelArray, cancellationToken)); } } #endregion #endregion } } } } else { _logger.Error("Machine Serial does not matched.."); } } catch (Exception ex) { _logger.Error(ex.ToString() + "attendance api"); } _logger.Info("Sync Successfully to server."); return(Request.CreateResponse(HttpStatusCode.OK, "Post Successful!")); }
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); }