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);
        }
Ejemplo n.º 2
0
        public void SavePrintJobTest()
        {
            var model = new CheckInModel(db);

            model.SavePrintJob("TestKiosk1", null, "{\"fake\":\"test json\"}");

            db.PrintJobs.Where(m => m.Id == "TestKiosk1").Count().ShouldBeGreaterThan(0);
        }
Ejemplo n.º 3
0
        public ContentResult UploadPrintJob(string id)
        {
            if (!Authenticate())
            {
                return(Content("not authorized"));
            }

            var reader = new StreamReader(Request.InputStream);
            var job    = reader.ReadToEnd();

            var m = new CheckInModel();

            m.SavePrintJob(id, job);
            return(Content("done"));
        }
Ejemplo n.º 4
0
        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);
        }