Ejemplo n.º 1
0
        // ProcessSwipe handles the workflow for a student swiping their id
        // card at the Learning Factory.

        public String ProcessSwipe(String studentId)
        {
            String message = "";

            StudentDataService    sds = new StudentDataService();
            AttendanceDataService ads = new AttendanceDataService();

            Student student = sds.GetStudent(studentId);

            if (student == null) // new student swipes id card
            {
                String house_assignment = HouseAssignment();
                Console.WriteLine(house_assignment);

                if (sds.CreateStudent(studentId, house_assignment) && ads.CreateAttendance(studentId))
                {
                    message = "Welcome to the Learning Factory! " +
                              "Your house assignment is " + house_assignment +
                              ". Please see our FAQ page if you have questions about this house " +
                              "assignment or the point tracking process.";
                }
                else
                {
                    message = "An error occurred when processing your card. Please try again or " +
                              "find a staff member if error continues to occur.";
                }
            }

            else // existing student swipes id card
            {
                Attendance attendance = ads.GetLatestAttendance(studentId);

                if ((attendance.check_in != null) && (attendance.check_out != null))
                {
                    if (ads.CreateAttendance(studentId))
                    {
                        message = "Hi " + student.first_name + ", you have signed " +
                                  "into the Learning Factory. You currently have "
                                  + student.total_points + " points. Have fun building!";
                    }
                    else
                    {
                        message = "An error occurred when processing your card. Please try again or " +
                                  "find a staff member if error continues to occur.";
                    }
                }

                else
                {
                    if (ads.UpdateSession(attendance.session_id.ToString()))
                    {
                        message = "You have been signed out. You received " +
                                  ads.GetLatestAttendance(studentId).session_points + " points for this visit, " +
                                  " and you have " + sds.GetStudent(studentId).total_points + " points " +
                                  "total. Thanks for coming " + student.first_name + "!";
                    }
                    else
                    {
                        message = "An error occurred when processing your card. Please try again or " +
                                  "find a staff member if error continues to occur.";
                    }
                }
            }
            return(message);
        }