public DojoAttendanceEntryCollection Clone() { DojoAttendanceEntryCollection clonedDojoAttendanceEntry = new DojoAttendanceEntryCollection(count); lock (this) { foreach (DojoAttendanceEntry item in this) { clonedDojoAttendanceEntry.Add(item); } } return(clonedDojoAttendanceEntry); }
private void saveAttendance() { DojoMember member; string whereQuery; DojoAttendanceEntryManager aManager; DojoAttendanceEntryCollection attendance; int[] selectedClasses; string[] ids; bool removeEntry; bool formChanged; AttendanceScanner aScanner; // Load Member and set LastSignIn to present time member = new DojoMember(memberID); member.LastSignin = DateTime.Now; // Get classes on the attendance form. classIdArray = Context.Request.Form["___" + ClientID + "Classes"].Split(','); // Build query to get member's attendance for the classes on // the attendance form and get the memberTypeTemplates. whereQuery = "MemberID=" + member.iD; if (classIdArray.Length > 0) { whereQuery += " AND ("; for (int x = 0; x < classIdArray.Length; x++) { if (x == 0) { whereQuery += "ClassID=" + classIdArray[x] + " "; } else { whereQuery += "OR ClassID=" + classIdArray[x] + " "; } } whereQuery += ") "; } aManager = new DojoAttendanceEntryManager(); attendance = aManager.GetCollection(whereQuery, string.Empty, null); // Load selected classes from form. if (Page.Request.Form[this.ClientID + "classoptions"] != null) { ids = Page.Request.Form[this.ClientID + "classoptions"].Split(','); selectedClasses = new int[ids.Length]; for (int x = 0; x < ids.Length; x++) { selectedClasses[x] = int.Parse(ids[x]); } } else { // What the hell is this? selectedClasses = new int[0]; } // Assume that the form has not been changed. formChanged = false; // Save newly checked classes. for (int x = 0; x < selectedClasses.Length; x++) { // Ignore classes already checked! foreach (DojoAttendanceEntry aEntry in attendance) { if (selectedClasses[x] == aEntry.Class.iD) { goto NEXT_ENTRY; } } DojoAttendanceEntry entry = new DojoAttendanceEntry(); entry.Class = DojoClass.NewPlaceHolder(selectedClasses[x]); entry.Member = member; entry.Rank = member.rank; entry.SigninTime = localTime; attendance.Add(entry); entry.Save(); formChanged = true; NEXT_ENTRY: continue; } // Delete unchecked classes. foreach (DojoAttendanceEntry aEntry in attendance) { removeEntry = true; for (int x = 0; x < selectedClasses.Length; x++) { if (aEntry.Class.iD == selectedClasses[x]) { removeEntry = false; } } if (removeEntry) { aEntry.Delete(); formChanged = true; } } // Run attendance scan if form has changed if (formChanged) { aScanner = new AttendanceScanner(); aScanner.RunMemberAttendanceScan(member, TimeSpan.FromHours(1)); member.Save(); } }