public ActionResult Search(string data)
        {
            if (!Auth())
            {
                return(Message.createErrorReturn("Authentication failed, please try again", Message.API_ERROR_INVALID_CREDENTIALS));
            }

            Message      message = Message.createFromString(data);
            NumberSearch cns     = JsonConvert.DeserializeObject <NumberSearch>(message.data);

            DbUtil.LogActivity("Check-In Number Search: " + cns.search);

            Message response = new Message();

            response.setNoError();

            bool returnPictureUrls = message.device == Message.API_DEVICE_WEB;

            if (cns.search.Contains("!"))
            {
                var    list    = cns.search.Split('!').Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
                string id      = list.First();
                var    pending = CurrentDatabase.CheckInPendings.Where(p => p.Id == id.ToInt()).SingleOrDefault();
                if (pending != null)
                {
                    AttendanceBundle bundle = JsonConvert.DeserializeObject <AttendanceBundle>(pending.Data);
                    List <Family>    result = Family.forAttendanceBundle(CurrentDatabase, CurrentImageDatabase, bundle, cns.campus, cns.date, returnPictureUrls);
                    response.argString = SerializeJSON(bundle, message.version);
                    response.data      = SerializeJSON(result, message.version);
                    return(response);
                }
                else
                {
                    return(Message.createErrorReturn("Invalid barcode.", Message.API_ERROR_PERSON_NOT_FOUND));
                }
            }

            List <Family> families = Family.forSearch(CurrentDatabase, CurrentImageDatabase, cns.search, cns.campus, cns.date, returnPictureUrls);

            response.data = SerializeJSON(families, message.version);

            return(response);
        }
        public ActionResult Search(string data)
        {
            if (!Auth())
            {
                return(Message.createErrorReturn("Authentication failed, please try again", Message.API_ERROR_INVALID_CREDENTIALS));
            }

            Message      message = Message.createFromString(data);
            NumberSearch cns     = JsonConvert.DeserializeObject <NumberSearch>(message.data);

            DbUtil.LogActivity("Check-In Search: " + cns.search);

            Message response = new Message();

            response.setNoError();

            bool returnPictureUrls = message.device == Message.API_DEVICE_WEB;
            Guid guid;

            // handle scanned qr code
            if (Guid.TryParse(cns.search, out guid))
            {
                try
                {
                    var person = CmsData.Person.PersonForQRCode(CurrentDatabase, guid);
                    // first try to find a pending check in for the person scanned
                    var pending = CurrentDatabase.CheckInPendings.Where(p => p.PeopleId == person.PeopleId).SingleOrDefault();
                    if (pending == null)
                    {
                        // if not, see if there's a pending check in for the family
                        pending = CurrentDatabase.CheckInPendings.Where(p => p.FamilyId == person.FamilyId).SingleOrDefault();
                    }
                    if (pending != null)
                    {
                        // found a pending check in, load that data
                        AttendanceBundle bundle = JsonConvert.DeserializeObject <AttendanceBundle>(pending.Data);
                        List <Family>    result = Family.forAttendanceBundle(CurrentDatabase, CurrentImageDatabase, bundle, cns.campus, cns.date, returnPictureUrls);
                        response.argString = SerializeJSON(bundle, message.version);
                        response.data      = SerializeJSON(result, message.version);
                        return(response);
                    }
                    else
                    {
                        // a qr code was scanned without any pending check in, just load the family without attendance data
                        List <Family> scanned = new List <Family>();
                        var           family  = Family.forID(CurrentDatabase, CurrentImageDatabase, person.FamilyId, cns.campus, cns.date, returnPictureUrls);
                        scanned.Add(family);
                        response.data = SerializeJSON(scanned, message.version);
                        return(response);
                    }
                }
                catch (Exception e)
                {
                    return(Message.createErrorReturn(e.Message, Message.API_ERROR_PERSON_NOT_FOUND));
                }
            }

            List <Family> families = Family.forSearch(CurrentDatabase, CurrentImageDatabase, cns.search, cns.campus, cns.date, returnPictureUrls);

            response.data = SerializeJSON(families, message.version);

            return(response);
        }