private void btnAttach_Click(object sender, EventArgs e) { try { if (txtStudentMatric.Text.Trim() != _studentData.StudentProfileData.MatricNumber) { MessageBox.Show( @"Please request for the Student you wish to Tag. Some modifications have been made to the information retrieved."); return; } if (_tag == null) { MessageBox.Show( @"Lets start over. Close this message and Place a blank Tag"); return; } if (!CheckTagValidity()) { var dialogResult = MessageBox.Show( @"The Current Tag has some data on it? This operation will totally overwrite it. Should I proceed?", @"Waiting for Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult != DialogResult.Yes) { return; } } if (!RemoteTagClean()) { return; } var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/TagStudent?matricNumber={txtStudentMatric.Text.Trim()}&tagId={_tagUID}"); if (!settings.Result.Status) { MessageBox.Show( @"Cannot Write Tag at the moment. Why? " + settings.Result.Message); return; } var smartPoster = new RtdSmartPoster(); smartPoster.Title.Add(new RtdText(_studentData.StudentProfileData.MatricNumber, "US")); Ndef ndefData = smartPoster; using (var localEntities = new LocalEntities()) { var recordInDb = localEntities.Student_ProfileData.FirstOrDefault(x => x.MatricNumber == txtStudentMatric.Text.Trim()); if (recordInDb != null) { recordInDb.TagId = _tagUID; localEntities.Entry(recordInDb).State = EntityState.Modified; localEntities.SaveChanges(); } } _tag.Content.Clear(); _tag.Content.Add(ndefData); _cardthread = new Thread(() => { card_write_proc(_tag); }); _cardthread.Start(); } catch (Exception exception) { ErrorHandler.TreatError(exception); } }
private void PullStudents() { try { var listOfProfileData = new List <List <Data.Student_ProfileData> >(); var listOfAcademicData = new List <List <Student_RegistrationData> >(); var done = 0; _consoleInfoData = "Starting Pull of Student Data"; while (true) { var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/PullStudentsCompleteData?done={done}"); if (settings.Result.Status) { var batch = Newtonsoft.Json.JsonConvert.DeserializeObject <List <StudentCompleteData> >( Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data)); if (!batch.Any()) { break; } listOfProfileData.Add(batch.Select(x => x.StudentProfileData).ToList()); listOfAcademicData.Add(batch .Select(x => x.StudentData.FirstOrDefault()?.StudentRegistrationData).ToList()); done += batch.Count; _consoleInfoData = $"Pulled Student Batch of {batch.Count}. Total Pulled is {done}"; } else { _consoleInfoData = $"Issue with Synchronization of Student Data. Please contact the Adminsitrator"; return; } } if (listOfProfileData.Any()) { _consoleInfoData = @"Discarding all Previous Records"; DatabaseManager.ExecuteScripts("truncate table dbo.Student_ProfileData"); using (var data = new LocalEntities()) { _consoleInfoData = @" Persisting Student Profile Data"; foreach (var list in listOfProfileData) { _consoleInfoData = @"Processing ..."; data.Student_ProfileData.AddRange(list.Select(innerList => new Student_ProfileData() { MatricNumber = innerList.MatricNumber, TagId = innerList.TagId, IsDeleted = false, Phone = innerList.Phone, FirstName = innerList.FirstName, Email = innerList.Email, LastName = innerList.LastName, Sex = innerList.Sex, Picture = innerList.Picture, BloodGroup = innerList.BloodGroup ?? "", PictureEncoded = string.IsNullOrEmpty(innerList.Picture) ? null : Convert.FromBase64String(innerList.Picture), StudentProfileData = Newtonsoft.Json.JsonConvert.SerializeObject(innerList), RemoteId = innerList.Id })); data.SaveChanges(); } _consoleInfoData = @"Student Profile Data Persistence Successful"; _consoleInfoData = @"Persisting Student Academic Data"; foreach (var acadBatch in listOfAcademicData) { _consoleInfoData = @"Processing ..."; foreach (var acad in acadBatch) { var profile = data.Student_ProfileData.FirstOrDefault(x => x.RemoteId == acad.StudentId); if (profile == null) { continue; } var school = DatabaseManager.AcademicSetUpData.AcademicSetUpDatum.FirstOrDefault(x => x.SchoolSubSchool.Id == acad.SubSchoolId); if (school == null) { continue; } profile.Program = school.SchoolSubSchool.SubSchoolName; profile.Department = school.SchoolSubSchoolDepartment .FirstOrDefault(x => x.Id == acad.SubSchoolDepartmentId)?.SubSchoolDepartmentName; data.Entry(profile).State = EntityState.Modified; } data.SaveChanges(); } _consoleInfoData = @"Student Academic Data Persistence Successful"; } _consoleInfoData = @"Completed Pull of Student Data"; } else { _consoleInfoData = @"No Records found at this time."; } } catch (Exception e) { ErrorHandler.TreatError(e); } }