Ejemplo n.º 1
0
        public void IsValidCheckInTimeTest()
        {
            CheckInRules ciRules = new CheckInRules();

            DateTime[] checkinMoreThanTwoHoursPriorToStart = { DateTime.Now.AddHours(3), DateTime.Now.AddHours(4) };
            DateTime[] checkinWithinTwoHoursPriorToStart   = { DateTime.Now.AddHours(1), DateTime.Now.AddHours(2) };
            DateTime[] checkinAfterStartBeforeEnd          = { DateTime.Now.AddHours(-1), DateTime.Now.AddHours(1) };
            DateTime[] checkinAfterEnd = { DateTime.Now.AddHours(-2), DateTime.Now.AddHours(-1) };

            Assert.AreEqual(-1, ciRules.IsValidCheckInTime(checkinMoreThanTwoHoursPriorToStart));
            Assert.AreEqual(0, ciRules.IsValidCheckInTime(checkinWithinTwoHoursPriorToStart));
            Assert.AreEqual(0, ciRules.IsValidCheckInTime(checkinAfterStartBeforeEnd));
            Assert.AreEqual(1, ciRules.IsValidCheckInTime(checkinAfterEnd));
        }
Ejemplo n.º 2
0
        public ActionResult CheckIn(string rawBarcode)
        {
            EventQuery       eq      = new EventQuery();
            ParticipantQuery pq      = new ParticipantQuery();
            ParticipantDTO   pDTO    = new ParticipantDTO();
            CheckInQuery     ciq     = new CheckInQuery();
            CheckInDTO       ciDTO   = new CheckInDTO();
            CheckInRules     ciRules = new CheckInRules();
            BarcodeQuery     bcq     = new BarcodeQuery();

            bool   isValidBarcode  = bcq.isValidBarcode(rawBarcode);
            int    CheckInTimeCode = 0;
            bool   isDuplicate     = false;
            string colorCode       = "";

            if (isValidBarcode)
            {
                pDTO            = pq.FindParticipantByBarcode(rawBarcode);
                CheckInTimeCode = ciRules.IsValidCheckInTime(eq.QueryEventTimes(pDTO.eventId));
                isDuplicate     = ciRules.IsDuplicateCheckIn(ciq.QueryCheckInTimes(rawBarcode));
            }

            if (ModelState.IsValid && CheckInTimeCode == 0 && isDuplicate == false && isValidBarcode)
            {
                ciDTO.BarcodeId = bcq.GetBarcodeId(rawBarcode);
                ciq.CreateCheckIn(ciDTO);
                colorCode = "green";
                return(Json(new { errorColor = colorCode, error = "Checkin is Successful!" }));
            }

            string errorMessage = "";

            if (CheckInTimeCode == -1)
            {
                errorMessage += "The checkin period has not started";
                colorCode     = "red";
            }
            else if (CheckInTimeCode == 1)
            {
                errorMessage += "The checkin period has ended";
                colorCode     = "red";
            }

            else if (isDuplicate == true)
            {
                errorMessage += "This participant has already checked in";
                colorCode     = "yellow";
            }

            else if (!isValidBarcode)
            {
                errorMessage += "This is not a valid barcode";
                colorCode     = "red";
            }

            return(Json(new { errorColor = colorCode, error = errorMessage }));
        }