private async void NextButton_Click(object sender, EventArgs e) { progressBar.Visibility = ViewStates.Visible; var firebase = new FirebaseClient(FirebaseURL); string fileName_pastQs = "pastqs_" + myAttributes.attribute1; var pastQs = await firebase.Child("pastqs").Child(fileName_pastQs).OnceAsync <PastQ>(); string time = ""; foreach (var q in pastQs) { if (q.Object.studentid == studentid.ToString()) { time = q.Object.time; } } PastQ updatePastQ = new PastQ(); updatePastQ.studentid = studentid.ToString(); updatePastQ.name = candidateName.Text; updatePastQ.notes = notes.Text; updatePastQ.rating = newRating.ToString(); updatePastQ.time = time; await firebase.Child("pastqs").Child(fileName_pastQs).Child(pastQkey).PutAsync(updatePastQ); Toast.MakeText(this.Activity, "Changes Saved", ToastLength.Short).Show(); progressBar.Visibility = ViewStates.Invisible; }
private async void NextButton_Click(object sender, EventArgs e) { progressBar.Visibility = ViewStates.Visible; stopwatch.Stop(); string dbPath_attributes = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "attributes.db3"); SQLiteConnection db_attributes = new SQLiteConnection(dbPath_attributes); MyAttributes myAttributes = db_attributes.Get <MyAttributes>(1); var firebase = new FirebaseClient(FirebaseURL); // move q to student's past qs, and move student to company pastqs string fileName_companyPastQs = "pastqs_" + myAttributes.attribute1; string fileName_studentPastQs = "pastqs_" + student_id.ToString(); string fileName_careerFair = myAttributes.cfid.ToString(); StudentQ pastStudentQ = new StudentQ(); pastStudentQ.company = myAttributes.attribute1; PastQ pastCompanyQ = new PastQ(); pastCompanyQ.name = candidateName.Text; pastCompanyQ.studentid = student_id.ToString(); pastCompanyQ.notes = notes.Text; pastCompanyQ.rating = rating.ToString(); pastCompanyQ.time = stopwatch.ElapsedTicks.ToString(); // check to see if student is already in past q's var companyPastQs = await firebase.Child("pastqs").Child(fileName_companyPastQs).OnceAsync <PastQ>(); bool studentExists = false; List <string> times = new List <string>(); foreach (var pastq in companyPastQs) { if (pastq.Object.studentid == student_id.ToString()) { studentExists = true; break; } times.Add(pastq.Object.time); } times.Add(stopwatch.ElapsedTicks.ToString()); if (studentExists == false) { await firebase.Child("pastqs").Child(fileName_companyPastQs).PostAsync(pastCompanyQ); await firebase.Child("pastqs").Child(fileName_studentPastQs).PostAsync(pastStudentQ); } // remove student from q, and remove q from student's current qs string fileName_companyQ = "qs_" + myAttributes.cfid.ToString() + "_" + myAttributes.attribute1; string fileName_studentQ = "myqs_" + myAttributes.cfid.ToString() + "_" + student_id; var companyQ = await firebase.Child("qs").Child(fileName_companyQ).OnceAsync <Queue>(); var studentQ = await firebase.Child("qs").Child(fileName_studentQ).OnceAsync <StudentQ>(); int numStudentsInQ = companyQ.Count; string key1 = ""; foreach (var q in companyQ) { if (q.Object.position != "1") { Queue newQ = new Queue(); int currentPos = Convert.ToInt32(q.Object.position); int newPos = currentPos - 1; newQ.position = newPos.ToString(); newQ.studentid = q.Object.studentid; newQ.studentname = q.Object.studentname; string thisKey = q.Key; await firebase.Child("qs").Child(fileName_companyQ).Child(thisKey).PutAsync(newQ); string fileName_thisStudentQ = "myqs_" + myAttributes.cfid.ToString() + "_" + q.Object.studentid; var thisStudentQ = await firebase.Child("qs").Child(fileName_thisStudentQ).OnceAsync <StudentQ>(); foreach (var p in thisStudentQ) { if (p.Object.company == myAttributes.attribute1) { string companyKey = p.Key; StudentQ newStudentQ = new StudentQ(); newStudentQ.position = newPos.ToString(); newStudentQ.company = myAttributes.attribute1; await firebase.Child("qs").Child(fileName_thisStudentQ).Child(companyKey).PutAsync(newStudentQ); } } } else { key1 = q.Key; await firebase.Child("qs").Child(fileName_companyQ).Child(key1).DeleteAsync(); } } foreach (var q in studentQ) { if (q.Object.company == myAttributes.attribute1) { string thisKey = q.Key; await firebase.Child("qs").Child(fileName_studentQ).Child(thisKey).DeleteAsync(); } } // Calculate average time, and update value in database long fiveMinsInTicks = 3000000000; long numTimes = times.Count; long fiveMinsWeight = 10; long otherWeight = 100 - fiveMinsWeight; long indWeight = otherWeight / numTimes; long sum = (fiveMinsInTicks * fiveMinsWeight) / 100; foreach (var time in times) { long timeContribution = (indWeight * Convert.ToInt64(time)) / 100; sum = sum + timeContribution; } var thisCareerFair = await firebase.Child("careerfairs").Child(fileName_careerFair).OnceAsync <Company>(); Company newCompanyInfo = new Company(); string thisCompanyKey = ""; foreach (var company in thisCareerFair) { if (company.Object.name == myAttributes.attribute1) { thisCompanyKey = company.Key; newCompanyInfo.companyid = company.Object.companyid; newCompanyInfo.name = company.Object.name; newCompanyInfo.description = company.Object.description; newCompanyInfo.website = company.Object.website; newCompanyInfo.rak = company.Object.rak; newCompanyInfo.checkedIn = company.Object.checkedIn; newCompanyInfo.waittime = sum.ToString(); newCompanyInfo.numstudents = (numStudentsInQ - 1).ToString(); } } await firebase.Child("careerfairs").Child(fileName_careerFair).Child(thisCompanyKey).PutAsync(newCompanyInfo); progressBar.Visibility = ViewStates.Invisible; Android.Support.V4.App.FragmentTransaction trans = FragmentManager.BeginTransaction(); trans.Replace(Resource.Id.qs_root_frame, new QsFragment()); trans.Commit(); }