Ejemplo n.º 1
0
        public ActionResult RollList(int id, DateTime datetime)
        {
            if (!AccountModel.AuthenticateMobile())
            {
                return(Content("not authorized"));
            }
            var u       = DbUtil.Db.Users.Single(uu => uu.Username == AccountModel.UserName2);
            var meeting = Meeting.FetchOrCreateMeeting(DbUtil.Db, id, datetime);

            return(new RollListResult(meeting));
        }
Ejemplo n.º 2
0
        public ActionResult CreateMeetings(DateTime dt, bool noautoabsents, OrgSearchModel model)
        {
            var orgIds = model.FetchOrgs().Select(oo => oo.OrganizationId).ToList();

            foreach (var oid in orgIds)
            {
                Meeting.FetchOrCreateMeeting(CurrentDatabase, oid, dt, noautoabsents);
            }
            DbUtil.LogActivity("Creating new meetings from OrgSearch");
            return(Content("done"));
        }
Ejemplo n.º 3
0
        public ActionResult PostScheduleAttendance(int orgId, int timestamp)
        {
            var meetingDate = DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime.ToLocalTime();

            if ((DateTime.Now - meetingDate).TotalDays >= 7)
            {
                return(RedirectShowError("This meeting has expired"));
            }
            var meeting = Meeting.FetchOrCreateMeeting(CurrentDatabase, orgId, meetingDate, !CurrentDatabase.Setting("AttendanceAutoAbsents"));

            return(Redirect($"/Meeting/Attendance/{meeting.MeetingId}?currentMembers=true"));
        }
Ejemplo n.º 4
0
        public void RecordAttendTest(string setting)
        {
            var now = DateTime.Now;

            db.SetSetting("AttendCountUpdatesOffline", setting);
            db.SubmitChanges();
            var username = RandomString();
            var password = RandomString();
            var user     = CreateUser(username, password);
            var org      = CreateOrganization();

            org.FirstMeetingDate    = now.AddDays(-7);
            org.RollSheetVisitorWks = 2;
            org.AllowAttendOverlap  = true;
            org.CanSelfCheckin      = true;
            org.NoSecurityLabel     = true;
            org.NumCheckInLabels    = 0;
            db.SubmitChanges();
            var meetingTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - (now.Minute % 15), 0);

            Meeting.FetchOrCreateMeeting(db, org.OrganizationId, meetingTime, noautoabsents: true);

            var requestManager     = FakeRequestManager.Create();
            var context            = requestManager.CurrentHttpContext;
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            roleProvider.UserRoles.Add("Checkin");
            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            context.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);

            var controller = new CheckInAPIController(requestManager);
            var json       = $@"{{
    ""rebranded"": ""false"",
    ""argInt"": ""0"",
    ""version"": ""2"",
    ""id"": ""0"",
    ""data"": ""{{\""orgID\"":{org.OrganizationId},\""present\"":true,\""datetime\"":\""{meetingTime:s}\"",\""peopleID\"":{user.PeopleId}}}"",
    ""device"": ""1"",
    ""argString"": """",
    ""count"": ""0""
}}";
            var result     = controller.RecordAttend(json) as CheckInMessage;

            db.DeleteSetting("AttendCountUpdatesOffline");

            result.error.ShouldBe(0);
            result.count.ShouldBe(1);
        }
Ejemplo n.º 5
0
        public static void SyncWithESpace(this Organization org, CMSDataContext db)
        {
            const string extraValueField = "eSPACE_ID";

            if (org.ESpaceEventId.HasValue)
            {
                var espace = new eSpaceClient
                {
                    Username = db.Setting("eSpaceUserName", ""),
                    Password = db.Setting("eSpacePassword", "")
                };
                var id         = org.OrganizationId;
                var daysToSync = db.Setting("eSpaceDaysToSync", "60");
                var list       = espace.Event.Occurrences(org.ESpaceEventId.Value, new NameValueCollection
                {
                    { "nextDays", daysToSync }
                });

                foreach (var occurrence in list)
                {
                    var occurrenceId = occurrence.OccurrenceId.ToString();
                    var meeting      = db.MeetingExtras
                                       .Where(m => m.Meeting.OrganizationId == org.OrganizationId)
                                       .Where(m => m.Field == extraValueField && m.Data == occurrenceId)
                                       .Select(m => m.Meeting).FirstOrDefault();
                    if (meeting == null)
                    {
                        meeting = Meeting.FetchOrCreateMeeting(db, id, occurrence.EventStart);
                    }
                    meeting.Location = string.Join("\n", occurrence.Items.Where(i => i.ItemType == "Space").Select(i => i.Name));
                    meeting.AddEditExtraText(extraValueField, occurrenceId);
                }
                db.SubmitChanges();

                var current          = list.Select(o => o.OccurrenceId.ToString());
                var meetingsToDelete = db.MeetingExtras
                                       .Where(e => e.Meeting.OrganizationId == org.OrganizationId)
                                       .Where(e => e.Field == extraValueField && e.Data.Length > 0)
                                       .Where(e => !current.Contains(e.Data))
                                       .Where(e => e.Meeting.MeetingDate > DateTime.Now)
                                       .Select(m => m.MeetingId)
                                       .ToList();
                foreach (var m in meetingsToDelete)
                {
                    DeleteMeeting(db, m);
                }
            }
        }
Ejemplo n.º 6
0
        public ActionResult FetchOrgRollList(string data)
        {
            // Authenticate first
            var authError = Authenticate();

            if (authError != null)
            {
                return(authError);
            }

            // Check Role
            if (!CMSRoleProvider.provider.IsUserInRole(AccountModel.UserName2, "Attendance"))
            {
                return(BaseMessage.createErrorReturn("Attendance roles is required to take attendance for organizations"));
            }

            // Check to see if type matches
            BaseMessage dataIn = BaseMessage.createFromString(data);

            if (dataIn.type != BaseMessage.API_TYPE_ORG_ROLL_REFRESH)
            {
                return(BaseMessage.createTypeErrorReturn());
            }

            // Everything is in order, start the return
            MobilePostRollList mprl = JsonConvert.DeserializeObject <MobilePostRollList>(dataIn.data);

            var meeting = Meeting.FetchOrCreateMeeting(DbUtil.Db, mprl.id, mprl.datetime);
            var people  = RollsheetModel.RollList(meeting.MeetingId, meeting.OrganizationId, meeting.MeetingDate.Value);

            BaseMessage           br = new BaseMessage();
            List <MobileAttendee> ma = new List <MobileAttendee>();

            br.id    = meeting.MeetingId;
            br.error = 0;
            br.type  = BaseMessage.API_TYPE_ORG_ROLL_REFRESH;
            br.count = people.Count();

            foreach (var person in people)
            {
                ma.Add(new MobileAttendee().populate(person));
            }

            br.data = JsonConvert.SerializeObject(ma);
            return(br);
        }
Ejemplo n.º 7
0
        public void SyncWithESpaceTest()
        {
            var organization = Organization.CreateOrganization(db, 1, RandomString());

            organization.ESpaceEventId = 874491;
            db.SubmitChanges();

            var meeting = Meeting.FetchOrCreateMeeting(db, organization.OrganizationId, new DateTime(2020, 2, 20, 18, 0, 0));

            meeting.AddEditExtraText("eSPACE_ID", "7392517");
            db.SubmitChanges();

            NetworkFixture.MockResponse($"/event/occurrences\\?nextDays=60&eventId=874491", new MockHttpResponse
            {
                Headers      = NetworkFixture.JsonHeaders,
                ResponseBody = Encoding.Default.GetString(Resources.SyncWithESpaceTestResponse)
            });

            // Tests that we pulled in a new meeting
            organization.SyncWithESpace(db);
            var meetingCount = db.Meetings.Count(m => m.OrganizationId == organization.OrganizationId);

            meetingCount.ShouldBe(2);

            // Tests that we updated an existing meeting
            db.Refresh(RefreshMode.OverwriteCurrentValues, meeting);
            meeting.Location.ShouldBe("Conference Room\nE151");

            NetworkFixture.MockResponse($"/event/occurrences\\?nextDays=60&eventId=874491", new MockHttpResponse
            {
                Headers      = NetworkFixture.JsonHeaders,
                ResponseBody = Encoding.Default.GetString(Resources.SyncWithESpaceTestDeletedResponse)
            });

            // Tests that we deleted a meeting in the future that no longer has an eSpace occurrence
            meeting.MeetingDate = DateTime.Now.AddDays(30);
            db.SubmitChanges();
            organization.SyncWithESpace(db);
            meetingCount = db.Copy().Meetings.Count(m => m.OrganizationId == organization.OrganizationId);
            meetingCount.ShouldBe(1);
        }