Пример #1
0
        public ActionResult ClassSearch(string data)
        {
            if (!Auth())
            {
                return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS));
            }

            CheckInMessage     dataIn = CheckInMessage.createFromString(data);
            CheckInClassSearch ccs    = JsonConvert.DeserializeObject <CheckInClassSearch>(dataIn.data);

            DbUtil.LogActivity("Check-In Class Search: " + ccs.peopleID);

            var person = (from p in CurrentDatabase.People
                          where p.PeopleId == ccs.peopleID
                          select new { p.FamilyId, p.BirthDate, p.Grade }).SingleOrDefault();

            if (person == null)
            {
                return(CheckInMessage.createErrorReturn("Person not found", CheckInMessage.API_ERROR_PERSON_NOT_FOUND));
            }

            CheckInMessage br = new CheckInMessage();

            br.setNoError();

            List <CheckInOrganization> orgs = (from o in CurrentDatabase.Organizations
                                               let sc = o.OrgSchedules.FirstOrDefault()
                                                        let meetingHours = CurrentDatabase.GetTodaysMeetingHours(o.OrganizationId, ccs.day)
                                                                           let bdaystart = o.BirthDayStart ?? DateTime.MaxValue
                                                                                           where (o.SuspendCheckin ?? false) == false || ccs.noAgeCheck
                                                                                           where person.BirthDate == null || person.BirthDate <= o.BirthDayEnd || o.BirthDayEnd == null || ccs.noAgeCheck
                                                                                           where person.BirthDate == null || person.BirthDate >= o.BirthDayStart || o.BirthDayStart == null || ccs.noAgeCheck
                                                                                           where o.CanSelfCheckin == true
                                                                                           where (o.ClassFilled ?? false) == false
                                                                                           where (o.CampusId == null && o.AllowNonCampusCheckIn == true) || o.CampusId == ccs.campus || ccs.campus == 0
                                                                                           where o.OrganizationStatusId == OrgStatusCode.Active
                                                                                           orderby sc.SchedTime.Value.TimeOfDay, bdaystart, o.OrganizationName
                                               from meeting in meetingHours
                                               select new CheckInOrganization()
            {
                id = o.OrganizationId,
                leader = o.LeaderName,
                name = o.OrganizationName,
                hour = meeting.Hour.Value,
                birthdayStart = o.BirthDayStart,
                birthdayEnd = o.BirthDayEnd,
                location = o.Location,
                allowOverlap = o.AllowAttendOverlap
            }).ToList();

            // Add lead time adjustment for different timezones here
            int tzOffset = CurrentDatabase.Setting("TZOffset", "0").ToInt();

            foreach (CheckInOrganization org in orgs)
            {
                org.adjustLeadTime(ccs.day, tzOffset);
            }

            br.data = SerializeJSON(orgs, dataIn.version);

            return(br);
        }