public ActionResult PrintJobs(string data) { if (!Auth()) { return(Message.createErrorReturn("Authentication failed, please try again", Message.API_ERROR_INVALID_CREDENTIALS)); } Message message = Message.createFromString(data); Message response = new Message(); string[] kiosks = message.getArgStringAsArray(","); List <PrintJob> printJobs = (from label in CurrentDatabase.PrintJobs where kiosks.Contains(label.Id) select label).ToList(); List <List <Label> > labels = new List <List <Label> >(); foreach (PrintJob printJob in printJobs) { AttendanceBundle attendanceBundle = JsonConvert.DeserializeObject <AttendanceBundle>(printJob.JsonData); attendanceBundle.labelSize = message.argInt; List <Label> labelGroup = attendanceBundle.createLabelData(CurrentDatabase); labels.Add(labelGroup); } response.setNoError(); response.count = labels.Count; response.data = SerializeJSON(labels); return(response); }
public ActionResult UpdateAttend(string data) { // Authenticate first if (!Auth()) { return(Message.createErrorReturn("Authentication failed, please try again", Message.API_ERROR_INVALID_CREDENTIALS)); } Message message = Message.createFromString(data); Message response = new Message(); AttendanceBundle bundle = JsonConvert.DeserializeObject <AttendanceBundle>(message.data); bundle.recordAttendance(CurrentDatabase); if (message.device == Message.API_DEVICE_WEB) { string bundleData = SerializeJSON(bundle); CheckInModel checkInModel = new CheckInModel(CurrentDatabase); checkInModel.SavePrintJob(message.kiosk, null, bundleData); response.setNoError(); response.count = 1; response.data = bundleData; } else { response.setNoError(); response.count = 1; response.data = SerializeJSON(bundle.createLabelData(CurrentDatabase)); } 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 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 UpdateAttend(string data) { // Authenticate first if (!Auth()) { return(Message.createErrorReturn("Authentication failed, please try again", Message.API_ERROR_INVALID_CREDENTIALS)); } Message response = new Message(); Message message = Message.createFromString(data); AttendanceBundle bundle = JsonConvert.DeserializeObject <AttendanceBundle>(message.data); foreach (Attendance attendance in bundle.attendances) { foreach (AttendanceGroup group in attendance.groups) { CmsData.Attend.RecordAttend(CurrentDatabase, attendance.peopleID, group.groupID, group.present, group.datetime); CmsData.Attend attend = CurrentDatabase.Attends.FirstOrDefault(a => a.PeopleId == attendance.peopleID && a.OrganizationId == group.groupID && a.MeetingDate == group.datetime); if (attend == null) { continue; } if (group.present) { attend.SubGroupID = group.subgroupID; attend.SubGroupName = group.subgroupName; } else { attend.SubGroupID = 0; attend.SubGroupName = ""; } if (group.join) { JoinToOrg(attendance.peopleID, group.groupID); } } CurrentDatabase.SubmitChanges(); } if (message.device == Message.API_DEVICE_WEB) { string bundleData = SerializeJSON(bundle); var m = new CheckInModel(); m.SavePrintJob(message.kiosk, null, bundleData); response.setNoError(); response.count = 1; response.data = bundleData; return(response); } List <Label> labels = new List <Label>(); string securityCode = CurrentDatabase.NextSecurityCode().Select(c => c.Code).Single().Trim(); using (var db = new SqlConnection(Util.ConnectionString)) { Dictionary <int, LabelFormat> formats = LabelFormat.forSize(db, bundle.labelSize); foreach (Attendance attendance in bundle.attendances) { attendance.load(); attendance.labelSecurityCode = securityCode; labels.AddRange(attendance.getLabels(formats, bundle.securityLabels, bundle.guestLabels, bundle.locationLabels, bundle.nameTagAge)); } if (labels.Count > 0 && bundle.attendances.Count > 0 && bundle.securityLabels == Attendance.SECURITY_LABELS_PER_FAMILY) { labels.AddRange(bundle.attendances[0].getSecurityLabel(formats)); } } response.setNoError(); response.count = 1; response.data = SerializeJSON(labels); 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); }