コード例 #1
0
ファイル: DataHelper.cs プロジェクト: arranf/RockPlugins
        public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService attendanceService, Request req)
        {
            Attendance newAttendance = ( Attendance )attendance.Clone();

            newAttendance.Id               = 0;
            newAttendance.Guid             = new Guid();
            newAttendance.StartDateTime    = Rock.RockDateTime.Now;
            newAttendance.EndDateTime      = null;
            newAttendance.DidAttend        = true;
            newAttendance.Device           = null;
            newAttendance.SearchTypeValue  = null;
            newAttendance.LocationId       = req.LocationId;
            newAttendance.AttendanceCode   = null;
            newAttendance.AttendanceCodeId = attendance.AttendanceCodeId;
            if (isSubroom)
            {
                newAttendance.ForeignId = location.Id;
            }
            else
            {
                newAttendance.ForeignId = null;
            }
            attendanceService.Add(newAttendance);
            var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0);

            attendance.DidAttend   = stayedFifteenMinutes;
            attendance.EndDateTime = Rock.RockDateTime.Now;
            InMemoryPersonStatus.RemoveFromWorship(attendance.PersonAlias.PersonId);
            InMemoryPersonStatus.RemoveFromWithParent(attendance.PersonAlias.PersonId);
            CheckInCountCache.AddAttendance(newAttendance);
            CheckInCountCache.RemoveAttendance(attendance);
        }
コード例 #2
0
        protected void btnRecordAttendance_Click(object sender, EventArgs e)
        {
            if (!dpAttendedDate.SelectedDateTimeIsBlank)
            {
                var attendendPeopleIds = new List <int>();
                foreach (RepeaterItem item in rptAttendees.Items)
                {
                    var cb = item.FindControl("didAttend") as CheckBox;
                    if (cb.Checked)
                    {
                        var personId = item.FindControl("personId") as HiddenField;
                        attendendPeopleIds.Add(Int32.Parse(personId.Value));
                    }
                }

                if (attendendPeopleIds.Count > 0)
                {
                    var attendanceService = new AttendanceService(ctx);
                    var peopleService     = new PersonService(ctx);
                    var people            = peopleService.GetByIds(attendendPeopleIds);
                    var attendances       = new List <Rock.Model.Attendance>();

                    foreach (Person person in people)
                    {
                        var attendance = new Rock.Model.Attendance();
                        attendance.PersonAlias = person.PrimaryAlias;
                        attendance.Group       = _group;
                        attendance.DidAttend   = true;
                        // ADD GROUP LOCATION ?

                        attendance.StartDateTime = (DateTime)dpAttendedDate.SelectedDateTime;
                        if (attendance.IsValid)
                        {
                            attendanceService.Add(attendance);
                            attendances.Add(attendance);
                        }
                    }

                    ctx.SaveChanges();

                    FlashMessage(string.Format(
                                     "Attendance Recorded for {1} people on {0}",
                                     dpAttendedDate.SelectedDateTime.Value.ToShortTimeString(),
                                     attendendPeopleIds.Count
                                     ), NotificationBoxType.Success);

                    resetCheckBoxes();
                    BindGrid();
                }
                else
                {
                    FlashMessage("Please select at least one Attendee", NotificationBoxType.Danger);
                }
            }
            else
            {
                FlashMessage("Attended Date is required", NotificationBoxType.Danger);
            }
        }
コード例 #3
0
 public ActionResult Create(Attendance attendance)
 {
     try
     {
         attendanceService.Add(attendance);
         Session["Total"] = attendance.TotalDay;
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #4
0
        public Response Insert([FromBody] Request req)
        {
            try
            {
                RockContext       rockContext       = new RockContext();
                AttendanceService attendanceService = new AttendanceService(rockContext);
                LocationService   locationService   = new LocationService(rockContext);

                var location = locationService.Get(req.LocationId);
                if (location == null)
                {
                    return(new Response(false, "Could not find location", false));
                }

                var isSubroom = ValidationHelper.IsSubRoom(location);

                var person = ValidationHelper.TestPin(rockContext, req.PIN);

                if (person == null)
                {
                    return(new Response(false, "Person not authorized", false));
                }
                var newAttendance = new Attendance
                {
                    PersonAlias   = person.PrimaryAlias,
                    LocationId    = location.Id,
                    StartDateTime = Rock.RockDateTime.Now,
                    DidAttend     = true,
                };
                if (isSubroom)
                {
                    newAttendance.LocationId = location.ParentLocationId;
                    newAttendance.ForeignId  = location.Id;
                }
                attendanceService.Add(newAttendance);
                DataHelper.CloseActiveAttendances(rockContext, newAttendance, location, isSubroom);
                DataHelper.AddEntranceHistory(rockContext, location, newAttendance, isSubroom);
                CheckInCountCache.AddAttendance(newAttendance);
                rockContext.SaveChanges();

                return(DataHelper.GetEntryResponse(rockContext, person, location));
            }
            catch (Exception e)
            {
                ExceptionLogService.LogException(e, System.Web.HttpContext.Current);
                return(new Response(false, "An error occured", false));
            }
        }
コード例 #5
0
        protected void lbSave_Click(object sender, EventArgs e)
        {
            if (_groupId != null && _startDateTime != null)
            {
                var rockContext       = new RockContext();
                var attendanceService = new AttendanceService(rockContext);
                var existingAttendees = attendanceService
                                        .Queryable("PersonAlias")
                                        .Where(a =>
                                               a.Occurrence.GroupId == _groupId &&
                                               a.Occurrence.LocationId == _locationId &&
                                               a.Occurrence.ScheduleId == _scheduleId &&
                                               a.StartDateTime == _startDateTime.Value);

                {
                    foreach (var attendee in _attendees)
                    {
                        var attendance = existingAttendees
                                         .FirstOrDefault(a => a.PersonAlias.Id == attendee.PersonAliasId);

                        if (attendance == null)
                        {
                            attendance = new Attendance();
                            attendance.Occurrence.GroupId    = _groupId;
                            attendance.Occurrence.ScheduleId = _scheduleId;
                            attendance.PersonAliasId         = attendee.PersonAliasId;
                            attendance.StartDateTime         = _startDateTime.Value;
                            attendance.Occurrence.LocationId = _locationId;
                            attendance.CampusId = _campusId;
                            attendance.Occurrence.ScheduleId = _scheduleId;
                            attendanceService.Add(attendance);
                        }

                        attendance.DidAttend = attendee.Attended;
                        attendance.Occurrence.DidNotOccur = null;
                    }
                }

                if (_locationId.HasValue)
                {
                    Rock.CheckIn.KioskLocationAttendance.Remove(_locationId.Value);
                }

                rockContext.SaveChanges();
                NavigateToParentPage();
            }
        }
コード例 #6
0
        private void checkInFamily(IQueryable <GroupMember> family, Group attendanceGroup, Campus campus, RockContext rockContext)
        {
            AttendanceService attendanceService = new AttendanceService(rockContext);

            foreach (var member in family)
            {
                Attendance attendance = new Attendance();
                attendance.GroupId       = attendanceGroup.Id;
                attendance.PersonAliasId = member.Person.PrimaryAliasId;
                attendance.StartDateTime = RockDateTime.Now;
                attendance.DidAttend     = true;
                attendance.Campus        = campus;

                attendanceService.Add(attendance);
            }
            rockContext.SaveChanges();
        }
コード例 #7
0
        public void Execute(IJobExecutionContext context)
        {
            var dataMap = context.JobDetail.JobDataMap;

            var rockContext  = new RockContext();
            var groupService = new GroupService(rockContext);
            var rootGroup    = groupService.Get(dataMap.GetString("RootGroup").AsGuid());

            _scheduleCutOffDateTime = RockDateTime.Now.AddDays(dataMap.GetIntValue("DaysAhead"));

            GetChildren(rootGroup);

            string serviceAttributeKey = dataMap.GetString("AssignedServiceAttributeKey");
            string teamAttributeKey    = dataMap.GetString("AssignedTeamAttributeKey");

            var attendanceService = new AttendanceService(rockContext);

            foreach (var groupMember in _groupMembers)
            {
                groupMember.LoadAttributes();

                string groupMemberSchedule = groupMember.AttributeValues[teamAttributeKey] + " - " +
                                             groupMember.AttributeValues[serviceAttributeKey];

                // Check if the group members schedule attributes match a schedule within the window
                if (_validScheduleNames.Contains(groupMemberSchedule))
                {
                    // Add an attendance record with RSVP 'Yes' to indicate it was added by this job and they were scheduled
                    // The start date will be overwritten by Rock.Workflow.Action.CheckIn.SaveAttendance
                    var attendance = new Attendance
                    {
                        Group         = groupMember.Group,
                        GroupId       = groupMember.GroupId,
                        DidAttend     = false,
                        Location      = groupMember.Group.GroupLocations.FirstOrDefault()?.Location,
                        Schedule      = groupMember.Group.Schedule,
                        PersonAlias   = groupMember.Person.PrimaryAlias,
                        StartDateTime = DateTime.MinValue,
                        RSVP          = RSVP.Yes
                    };
                    attendanceService.Add(attendance);
                }
            }
            rockContext.SaveChanges();
        }
コード例 #8
0
        public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService notUsed, Request req)
        {
            RockContext       rockContext       = new RockContext();
            AttendanceService attendanceService = new AttendanceService(rockContext);
            Attendance        newAttendance;

            if (!isSubroom)
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.Id, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            else
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.ParentLocationId, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            newAttendance.StartDateTime    = Rock.RockDateTime.Now;
            newAttendance.EndDateTime      = null;
            newAttendance.DidAttend        = true;
            newAttendance.AttendanceCodeId = attendance.AttendanceCodeId;
            if (isSubroom)
            {
                newAttendance.ForeignId = location.Id;
            }
            else
            {
                newAttendance.ForeignId = null;
            }
            attendanceService.Add(newAttendance);
            var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0);

            attendance.DidAttend   = stayedFifteenMinutes;
            attendance.EndDateTime = Rock.RockDateTime.Now;

            rockContext.SaveChanges();

            AttendanceCache.RemoveWithParent(attendance.PersonAlias.PersonId);
            AttendanceCache.AddOrUpdate(newAttendance);
            AttendanceCache.AddOrUpdate(attendance);
        }
コード例 #9
0
        public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService attendanceService, Request req)
        {
            Attendance newAttendance = null;

            if (!isSubroom)
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.Id, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            else
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.ParentLocationId, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            newAttendance.StartDateTime    = Rock.RockDateTime.Now;
            newAttendance.EndDateTime      = null;
            newAttendance.DidAttend        = true;
            newAttendance.AttendanceCodeId = attendance.AttendanceCodeId;
            if (isSubroom)
            {
                newAttendance.ForeignId = location.Id;
            }
            else
            {
                newAttendance.ForeignId = null;
            }
            attendanceService.Add(newAttendance);
            var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0);

            attendance.DidAttend   = stayedFifteenMinutes;
            attendance.EndDateTime = Rock.RockDateTime.Now;
            InMemoryPersonStatus.RemoveFromWorship(attendance.PersonAlias.PersonId);
            InMemoryPersonStatus.RemoveFromWithParent(attendance.PersonAlias.PersonId);
            CheckInCountCache.AddAttendance(newAttendance);
            CheckInCountCache.RemoveAttendance(attendance);
        }
コード例 #10
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            Guid?    groupGuid          = null;
            Person   person             = null;
            DateTime attendanceDateTime = DateTime.Now;
            bool     addToGroup         = true;

            // get the group attribute
            Guid groupAttributeGuid = GetAttributeValue(action, "Group").AsGuid();

            if (!groupAttributeGuid.IsEmpty())
            {
                groupGuid = action.GetWorklowAttributeValue(groupAttributeGuid).AsGuidOrNull();

                if (!groupGuid.HasValue)
                {
                    errorMessages.Add("The group could not be found!");
                }
            }

            // get person alias guid
            Guid   personAliasGuid = Guid.Empty;
            string personAttribute = GetAttributeValue(action, "Person");

            Guid guid = personAttribute.AsGuid();

            if (!guid.IsEmpty())
            {
                var attribute = AttributeCache.Read(guid, rockContext);
                if (attribute != null)
                {
                    string value = action.GetWorklowAttributeValue(guid);
                    personAliasGuid = value.AsGuid();
                }

                if (personAliasGuid != Guid.Empty)
                {
                    person = new PersonAliasService(rockContext).Queryable().AsNoTracking()
                             .Where(p => p.Guid.Equals(personAliasGuid))
                             .Select(p => p.Person)
                             .FirstOrDefault();
                }
                else
                {
                    errorMessages.Add("The person could not be found in the attribute!");
                }
            }

            // get attendance date
            Guid dateTimeAttributeGuid = GetAttributeValue(action, "AttendanceDatetime").AsGuid();

            if (!dateTimeAttributeGuid.IsEmpty())
            {
                string attributeDatetime = action.GetWorklowAttributeValue(dateTimeAttributeGuid);

                if (!string.IsNullOrWhiteSpace(attributeDatetime))
                {
                    if (!DateTime.TryParse(attributeDatetime, out attendanceDateTime))
                    {
                        errorMessages.Add(string.Format("Could not parse the date provided {0}.", attributeDatetime));
                    }
                }
            }

            // get add to group
            addToGroup = GetAttributeValue(action, "AddToGroup").AsBoolean();

            // get location
            Guid locationGuid          = Guid.Empty;
            Guid locationAttributeGuid = GetAttributeValue(action, "Location").AsGuid();

            if (!locationAttributeGuid.IsEmpty())
            {
                var locationAttribute = AttributeCache.Read(locationAttributeGuid, rockContext);

                if (locationAttribute != null)
                {
                    locationGuid = action.GetWorklowAttributeValue(locationAttributeGuid).AsGuid();
                }
            }

            //// get Schedule
            Guid scheduleGuid          = Guid.Empty;
            Guid scheduleAttributeGuid = GetAttributeValue(action, "Schedule").AsGuid();

            if (!scheduleAttributeGuid.IsEmpty())
            {
                var scheduleAttribute = AttributeCache.Read(scheduleAttributeGuid, rockContext);
                if (scheduleAttribute != null)
                {
                    scheduleGuid = action.GetWorklowAttributeValue(scheduleAttributeGuid).AsGuid();
                }
            }

            // set attribute
            if (groupGuid.HasValue && person != null && attendanceDateTime != DateTime.MinValue)
            {
                var group = new GroupService(rockContext).Queryable("GroupType.DefaultGroupRole")
                            .Where(g => g.Guid == groupGuid)
                            .FirstOrDefault();
                if (group != null)
                {
                    GroupMemberService groupMemberService = new GroupMemberService(rockContext);

                    // get group member
                    var groupMember = groupMemberService.Queryable()
                                      .Where(m => m.Group.Guid == groupGuid &&
                                             m.PersonId == person.Id)
                                      .FirstOrDefault();
                    if (groupMember == null)
                    {
                        if (addToGroup)
                        {
                            if (group != null)
                            {
                                groupMember                   = new GroupMember();
                                groupMember.GroupId           = group.Id;
                                groupMember.PersonId          = person.Id;
                                groupMember.GroupMemberStatus = GroupMemberStatus.Active;
                                groupMember.GroupRole         = group.GroupType.DefaultGroupRole;
                                groupMemberService.Add(groupMember);
                                rockContext.SaveChanges();
                            }
                        }
                        else
                        {
                            action.AddLogEntry(string.Format("{0} was not a member of the group {1} and the action was not configured to add them.", person.FullName, group.Name));
                            return(true);
                        }
                    }

                    AttendanceService attendanceService = new AttendanceService(rockContext);

                    Attendance attendance = new Attendance();
                    attendance.GroupId       = group.Id;
                    attendance.PersonAliasId = person.PrimaryAliasId;
                    attendance.StartDateTime = attendanceDateTime;
                    attendance.DidAttend     = true;

                    if (locationGuid != Guid.Empty)
                    {
                        var location = new LocationService(rockContext).Queryable().AsNoTracking()
                                       .Where(l => l.Guid == locationGuid)
                                       .FirstOrDefault();

                        if (location != null)
                        {
                            attendance.LocationId = location.Id;
                        }
                    }

                    if (scheduleGuid != Guid.Empty)
                    {
                        var schedule = new ScheduleService(rockContext).Queryable().AsNoTracking()
                                       .Where(l => l.Guid == scheduleGuid)
                                       .FirstOrDefault();

                        if (schedule != null)
                        {
                            attendance.ScheduleId = schedule.Id;
                        }
                    }

                    attendanceService.Add(attendance);
                    rockContext.SaveChanges();

                    if (attendance.LocationId.HasValue)
                    {
                        Rock.CheckIn.KioskLocationAttendance.Flush(attendance.LocationId.Value);
                    }
                }
                else
                {
                    errorMessages.Add(string.Format("Could not find group matching the guid '{0}'.", groupGuid));
                }
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            // Set the block title and icon
            string iconCss = GetAttributeValue("BlockIconCSSClass");

            lBlockIcon.Text  = iconCss.IsNotNullOrWhiteSpace() ? string.Format("<i class='{0}'></i>", iconCss) : string.Empty;
            lBlockTitle.Text = GetAttributeValue("BlockTitle");

            using (var rockContext = new RockContext())
            {
                // Get/Validate the Person
                var person = this.ContextEntity <Person>();
                if (person == null)
                {
                    int?personId = PageParameter("PersonId").AsIntegerOrNull();
                    if (personId.HasValue)
                    {
                        person = new PersonService(rockContext).Get(personId.Value);
                    }
                }
                if (person == null)
                {
                    DisplayError("Unknown Person", "Could not determine the person that attendance should be displayed for.");
                    return;
                }

                // Get all the child groups
                Guid?parentGroupGuid = GetAttributeValue("ParentGroup").AsGuidOrNull();
                var  groups          = new GroupService(rockContext)
                                       .Queryable().AsNoTracking()
                                       .Where(g =>
                                              g.ParentGroup != null &&
                                              g.ParentGroup.Guid == parentGroupGuid.Value &&
                                              g.IsActive)
                                       .ToList();

                // Get the groups that person has attended
                var dateRange       = DateRange.FromDelimitedValues(GetAttributeValue("DateRange"));
                var groupIds        = groups.Select(g => g.Id).ToList();
                var groupAttendance = new AttendanceService(rockContext)
                                      .Queryable().AsNoTracking()
                                      .Where(a =>
                                             a.PersonAlias != null &&
                                             a.Occurrence.GroupId.HasValue &&
                                             a.PersonAlias.PersonId == person.Id &&
                                             groupIds.Contains(a.Occurrence.GroupId.Value) &&
                                             a.DidAttend.HasValue &&
                                             a.DidAttend.Value &&
                                             a.StartDateTime >= dateRange.Start &&
                                             a.StartDateTime <= dateRange.End)
                                      .GroupBy(a => a.Occurrence.GroupId.Value)
                                      .Select(a => new GroupAttended
                {
                    GroupId      = a.Key,
                    LastAttended = a.Max(b => b.StartDateTime)
                })
                                      .ToList();
                groupIds = groupAttendance.Select(a => a.GroupId).ToList();

                // Format the root url of each image
                string imageRoot = string.Format("{0}://{1}/GetImage.ashx?maxwidth={2}&maxheight={3}&guid=",
                                                 Request.Url.Scheme, Request.Url.Authority,
                                                 GetAttributeValue("MaxImageWidth"), GetAttributeValue("MaxImageHeight"));

                // Get the blank image's guid
                Guid?blankImageGuid = GetAttributeValue("BlankImage").AsGuidOrNull();

                // Get the name and icon guid for each group that person attended
                string iconAttributeKey = GetAttributeValue("IconAttributeKey");
                foreach (var group in groups.Where(g => groupIds.Contains(g.Id)))
                {
                    var groupAttended = groupAttendance.Where(a => a.GroupId == group.Id).First();
                    groupAttended.GroupName = group.Name;

                    group.LoadAttributes();
                    Guid?groupImageGuid = group.GetAttributeValue(iconAttributeKey).AsGuidOrNull() ?? blankImageGuid;
                    if (groupImageGuid.HasValue)
                    {
                        groupAttended.IconUrl = string.Format("{0}{1}", imageRoot, groupImageGuid);
                    }
                }

                // Order the groups by date attended
                groupAttendance = groupAttendance.OrderBy(g => g.LastAttended).ToList();

                // Add any blank images
                if (blankImageGuid != null)
                {
                    int numberOfOpportunities = GetAttributeValue("NumberOfOpportunities").AsInteger();
                    for (int i = groupAttendance.Count; i < numberOfOpportunities; i++)
                    {
                        groupAttendance.Add(new GroupAttended
                        {
                            IconUrl = string.Format("{0}{1}", imageRoot, blankImageGuid)
                        });
                    }
                }

                // Bind the repeater
                rptIcons.DataSource = groupAttendance;
                rptIcons.DataBind();
            }
        }
        private MobileBlockResponse SaveAttendance(Dictionary <string, string> body)
        {
            GetGroupMembers(body["groupId"]);

            if (group != null)
            {
                if (body["schedule"].AsInteger() != 0)
                {
                    //The drop down stores the time in unix time
                    var occurenceDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)
                                        .AddSeconds(body["schedule"].AsInteger());

                    var attendanceService = new AttendanceService(rockContext);
                    var attendanceData    = attendanceService
                                            .Queryable("PersonAlias")
                                            .Where(a => a.GroupId == group.Id && a.StartDateTime == occurenceDate);

                    var personAliasService = new PersonAliasService(rockContext);

                    foreach (var item in groupMembers)
                    {
                        var personId       = item.PersonId;
                        var attendanceItem = attendanceData.Where(a => a.PersonAlias.PersonId == personId)
                                             .FirstOrDefault();
                        if (attendanceItem == null)
                        {
                            var attendancePerson = new PersonService(rockContext).Get(personId);
                            if (attendancePerson != null)
                            {
                                attendanceItem = new Attendance()
                                {
                                    Id            = 0,
                                    PersonAliasId = attendancePerson.PrimaryAliasId,
                                    GroupId       = group.Id,
                                    ScheduleId    = group.ScheduleId,
                                    StartDateTime = occurenceDate,
                                    CampusId      = group.CampusId
                                };
                                attendanceService.Add(attendanceItem);
                            }
                        }

                        if (body["didNotMeet"].AsBoolean())
                        {
                            attendanceItem.DidAttend   = false;
                            attendanceItem.DidNotOccur = true;
                        }
                        else
                        {
                            List <string> groupMemberAttendedIds = groupMemberAttendedIds = body["groupMembers"].SplitDelimitedValues(false).ToList();
                            attendanceItem.DidNotOccur = false;
                            attendanceItem.DidAttend   = groupMemberAttendedIds.Contains(personId.ToString());
                        }
                    }
                }

                rockContext.SaveChanges();

                var response = new FormResponse
                {
                    Success          = true,
                    Message          = "Attendance Saved",
                    FormElementItems = GetForm(body["schedule"])
                };

                return(new MobileBlockResponse()
                {
                    Request = "save",
                    Response = JsonConvert.SerializeObject(response),
                    TTL = 0
                });
            }

            var errorResponse = new FormResponse
            {
                Success = false,
                Message = "There was an errror saving your attendance."
            };

            return(new MobileBlockResponse()
            {
                Request = "save",
                Response = JsonConvert.SerializeObject(errorResponse),
                TTL = 0
            });
        }
コード例 #13
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var rockContext       = new RockContext();
            var attendanceService = new AttendanceService(rockContext);
            var group             = new GroupService(rockContext).Get(ddlGroup.SelectedValue.AsInteger());
            var person            = new PersonService(rockContext).Get(ppAttendee.PersonId.Value);
            var scheduleId        = ddlSchedule.SelectedValue.AsIntegerOrNull();
            var dateTime          = dpAttendanceDate.SelectedDate.Value;
            var groupLocation     = new GroupLocationService(rockContext).Get(ddlLocation.SelectedValue.AsInteger());

            //
            // Check for existing attendance record.
            //
            var attendance = attendanceService.Queryable()
                             .Where(a => a.GroupId == group.Id && a.PersonAlias.PersonId == person.Id && a.StartDateTime == dateTime && a.LocationId == groupLocation.LocationId && a.ScheduleId == scheduleId)
                             .FirstOrDefault();

            //
            // If the user is using the activate and save button then mark the
            // person as active too.
            //
            if (sender == btnSaveActivate)
            {
                person.RecordStatusValueId = new DefinedValueService(rockContext).Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid()).Id;
            }

            //
            // If not found then create a new one.
            //
            if (attendance == null)
            {
                attendance = new Attendance();

                attendance.GroupId       = group.Id;
                attendance.PersonAliasId = person.PrimaryAliasId;
                attendance.StartDateTime = dateTime;
                attendance.CampusId      = group.CampusId;
                attendance.LocationId    = groupLocation.LocationId;
                attendance.ScheduleId    = scheduleId;

                attendanceService.Add(attendance);
            }

            attendance.DidAttend = true;
            rockContext.SaveChanges();

            //
            // Flush the attendance cache.
            //
            if (attendance.LocationId.HasValue)
            {
                Rock.CheckIn.KioskLocationAttendance.Flush(attendance.LocationId.Value);
            }

            nbAttended.Text = string.Format("{0} has been marked attended.", person.FullName);

            //
            // Clear the person picker and open it so it's ready to go.
            //
            ppAttendee.SetValue(null);
            btnSaveActivate.Visible  = false;
            nbInactivePerson.Visible = false;

            //
            // Autoexpand the person picker for next entry.
            //
            var personPickerStartupScript = @"(function () {
                var runOnce = true;
                Sys.Application.add_load(function () {
                    if ( runOnce ) {
                        var personPicker = $('.js-attendee');
                        var currentPerson = personPicker.find('.picker-selectedperson').html();
                        if (currentPerson != null && currentPerson.length == 0) {
                            $(personPicker).find('a.picker-label').trigger('click');
                        }
                        runOnce = false;
                    }
                })
            })();";

            ScriptManager.RegisterStartupScript(btnSave, this.GetType(), "StartupScript", personPickerStartupScript, true);

            BindAttendees();
        }
コード例 #14
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            if (CurrentGroup != null)
            {
                if (ddlOccurence.SelectedValue.AsInteger() != 0)
                {
                    //The drop down stores the time in unix time
                    var occurenceDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)
                                        .AddSeconds(ddlOccurence.SelectedValue.AsInteger());

                    var attendanceData = new AttendanceService(_rockContext)
                                         .Queryable("PersonAlias")
                                         .Where(a => a.GroupId == CurrentGroup.Id && a.StartDateTime == occurenceDate);

                    var attendanceService  = new AttendanceService(_rockContext);
                    var personAliasService = new PersonAliasService(_rockContext);

                    foreach (var item in lvMembers.Items)
                    {
                        var hfMember       = item.FindControl("hfMember") as HiddenField;
                        var cbMember       = item.FindControl("cbMember") as HtmlInputCheckBox;
                        var personId       = hfMember.Value.AsInteger();
                        var attendanceItem = attendanceData.Where(a => a.PersonAlias.PersonId == personId)
                                             .FirstOrDefault();
                        if (attendanceItem == null)
                        {
                            var attendancePerson = new PersonService(_rockContext).Get(personId);
                            if (attendancePerson != null)
                            {
                                attendanceItem = new Attendance()
                                {
                                    Id            = 0,
                                    PersonAliasId = attendancePerson.PrimaryAliasId,
                                    GroupId       = CurrentGroup.Id,
                                    ScheduleId    = CurrentGroup.ScheduleId,
                                    StartDateTime = occurenceDate,
                                    CampusId      = CurrentGroup.CampusId
                                };
                                attendanceService.Add(attendanceItem);
                            }
                        }

                        if (cbDidNotMeet.Checked)
                        {
                            attendanceItem.DidAttend   = false;
                            attendanceItem.DidNotOccur = true;
                        }
                        else
                        {
                            attendanceItem.DidNotOccur = false;
                            attendanceItem.DidAttend   = cbMember.Checked;
                        }
                    }
                }


                _rockContext.SaveChanges();
                nbNotice.Text = "Attendance Saved";
                nbNotice.NotificationBoxType = NotificationBoxType.Success;
                nbNotice.Visible             = true;
                nbNotice.Dismissable         = true;
            }
        }
コード例 #15
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap     = context.JobDetail.JobDataMap;
            var        rockContext = new RockContext();

            InteractionChannelService   channelService              = new InteractionChannelService(rockContext);
            InteractionComponentService componentService            = new InteractionComponentService(rockContext);
            InteractionService          interactionService          = new InteractionService(rockContext);
            ScheduleService             scheduleService             = new ScheduleService(rockContext);
            LocationService             locationService             = new LocationService(rockContext);
            AttendanceService           attendanceService           = new AttendanceService(rockContext);
            AttendanceOccurrenceService attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            GroupService groupService = new GroupService(rockContext);

            // Load the channel
            InteractionChannelCache channel = InteractionChannelCache.Get(dataMap.GetString("InteractionChannel").AsGuid());

            // Setup
            int    campusLocationTypeId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS).Id;
            var    groupType            = GroupTypeCache.Get(dataMap.GetString("GroupType").AsGuid());
            var    groupLocations       = groupService.GetByGroupTypeId(groupType.Id).Where(g => g.IsActive == true).SelectMany(g => g.GroupLocations).ToList();
            string operation            = !string.IsNullOrWhiteSpace(dataMap.GetString("Operation")) ? dataMap.GetString("Operation") : null;

            // Fetch the job so we can get the last run date/time
            int jobId      = Convert.ToInt16(context.JobDetail.Description);
            var jobService = new ServiceJobService(rockContext);
            var job        = jobService.Get(jobId);

            DateTime  lastRun = job?.LastSuccessfulRunDateTime ?? DateTime.MinValue;
            var       componentCampusMapping = dataMap.GetString("ComponentCampusMapping").AsDictionaryOrNull();
            DateRange dateRange = Rock.Web.UI.Controls.SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(dataMap.GetString("DateRange") ?? "-1||");

            // Flip the component campus mapping around and translate to ids
            Dictionary <int, List <int> > campusComponentIds = new Dictionary <int, List <int> >();

            foreach (CampusCache campus in CampusCache.All())
            {
                var componentNames = componentCampusMapping.Where(ccm => ccm.Value == campus.Name).Select(c => c.Key.ToLower());
                campusComponentIds[campus.Id] = componentService.Queryable().Where(cs => componentNames.Contains(cs.Name.ToLower()) && cs.ChannelId == channel.Id).Select(c => c.Id).ToList();
            }

            foreach (GroupLocation gl in groupLocations)
            {
                if (gl.Group.CampusId.HasValue)
                {
                    Location   location     = gl.Location;
                    List <int> componentIds = campusComponentIds[gl.Group.CampusId.Value];

                    foreach (Schedule schedule in gl.Schedules)
                    {
                        var occurrences = schedule.GetOccurrences(dateRange.Start.Value, dateRange.End.Value);
                        foreach (var occurrence in occurrences)
                        {
                            DateTime startDate = occurrence.Period.StartTime.Value;
                            DateTime endDate   = occurrence.Period.EndTime.Value;

                            var peopleAttended = interactionService.Queryable().Where(
                                i => componentIds.Contains(i.InteractionComponentId) &&
                                i.InteractionDateTime <= endDate &&
                                i.InteractionEndDateTime >= startDate &&
                                i.PersonAliasId != null &&
                                (i.CreatedDateTime > lastRun || i.PersonalDevice.ModifiedDateTime > lastRun || i.PersonalDevice.CreatedDateTime > lastRun) &&
                                (operation == null || i.Operation == operation)
                                ).Select(i => i.PersonAliasId).Distinct();
                            int newAttendance = 0;

                            var occurrenceModel = attendanceOccurrenceService.Get(occurrence.Period.StartTime.Value.Date, gl.GroupId, location.Id, schedule.Id);

                            // Make sure we don't already have an attendance Record
                            var existingAttendees = attendanceOccurrenceService.Queryable().Where(ao => DbFunctions.TruncateTime(ao.OccurrenceDate) == occurrence.Period.StartTime.Value.Date && ao.ScheduleId == schedule.Id && ao.GroupId == gl.GroupId && ao.LocationId == location.Id).SelectMany(a => a.Attendees).Where(a => a.DidAttend == true).Select(a => a.PersonAliasId);
                            foreach (int personAliasId in peopleAttended.Except(existingAttendees))
                            {
                                // Check to see if an occurrence exists already
                                if (occurrenceModel == null)
                                {
                                    var attendance = attendanceService.AddOrUpdate(personAliasId, occurrence.Period.StartTime.Value, gl.GroupId, location.Id, schedule.Id, gl.Group.CampusId);

                                    attendance.EndDateTime = occurrence.Period?.EndTime?.Value;
                                    attendance.DidAttend   = true;
                                    attendance.CampusId    = gl.Group.CampusId;
                                    occurrenceModel        = attendance.Occurrence;
                                }
                                else
                                {
                                    Attendance attendance = new Attendance();
                                    attendance.PersonAliasId = personAliasId;
                                    attendance.OccurrenceId  = occurrenceModel.Id;
                                    attendance.StartDateTime = occurrence.Period.StartTime.Value;
                                    attendance.EndDateTime   = occurrence.Period?.EndTime?.Value;
                                    attendance.DidAttend     = true;
                                    attendance.CampusId      = gl.Group.CampusId;
                                    attendanceService.Add(attendance);
                                }

                                newAttendance++;
                            }
                            if (newAttendance > 0)
                            {
                                rockContext.SaveChanges();
                                context.Result += string.Format("{0} people attended {1} on {2}.\n", newAttendance, gl.Group.Campus.Name, occurrence.Period.StartTime.Value.ToString("MM/dd/yyyy h:mm tt"));
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = Rock.RockDateTime.Now;
                DateTime       today          = startDateTime.Date;
                DateTime       tomorrow       = startDateTime.AddDays(1);

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                        if (primaryAlias != null)
                                        {
                                            // If a like attendance service exists close it before creating another one.
                                            var oldAttendance = attendanceService.Queryable()
                                                                .Where(a =>
                                                                       a.StartDateTime >= today &&
                                                                       a.StartDateTime < tomorrow &&
                                                                       a.Occurrence.LocationId == location.Location.Id &&
                                                                       a.Occurrence.ScheduleId == schedule.Schedule.Id &&
                                                                       a.Occurrence.GroupId == group.Group.Id &&
                                                                       a.PersonAlias.PersonId == person.Person.Id)
                                                                .FirstOrDefault();

                                            if (oldAttendance != null)
                                            {
                                                oldAttendance.EndDateTime = Rock.RockDateTime.Now;
                                                oldAttendance.DidAttend   = false;
                                            }
                                            var attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, group.Group.Id,
                                                                                           location.Location.Id, schedule.Schedule.Id, location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                            attendance.DeviceId                 = checkInState.Kiosk.Device.Id;
                                            attendance.SearchTypeValueId        = checkInState.CheckIn.SearchType.Id;
                                            attendance.SearchValue              = checkInState.CheckIn.SearchValue;
                                            attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId;
                                            attendance.SearchResultGroupId      = family.Group.Id;
                                            attendance.AttendanceCodeId         = attendanceCode.Id;
                                            attendance.StartDateTime            = startDateTime;
                                            attendance.EndDateTime              = null;
                                            attendance.Note      = group.Notes;
                                            attendance.DidAttend = groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean();

                                            attendanceService.Add(attendance);
                                            CheckInCountCache.AddAttendance(attendance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();
                return(true);
            }

            return(false);
        }
        public void Execute(IJobExecutionContext context)
        {
            var rockContext            = new RockContext();
            var jobDataMap             = context.JobDetail.JobDataMap;
            var groupGuid              = jobDataMap.GetString("Group").AsGuidOrNull();
            var locationGuid           = jobDataMap.GetString("Location").AsGuidOrNull();
            var scheduleGuid           = jobDataMap.GetString("Schedule").AsGuidOrNull();
            var interactionChannelGuid = jobDataMap.GetString("InteractionChannel").AsGuidOrNull();
            var daysBack = jobDataMap.GetString("DaysBack").AsIntegerOrNull();

            if (!groupGuid.HasValue || !locationGuid.HasValue || !scheduleGuid.HasValue || !interactionChannelGuid.HasValue || !daysBack.HasValue)
            {
                throw new Exception("Invalid settings. Ensure the group type, location, schedule, interaction channel, and days back are set.");
            }

            var group              = new GroupService(rockContext).Get(groupGuid.Value);
            var location           = new LocationService(rockContext).Get(locationGuid.Value);
            var schedule           = new ScheduleService(rockContext).Get(scheduleGuid.Value);
            var interactionChannel = new InteractionChannelService(rockContext).Get(interactionChannelGuid.Value);

            if (group == null || location == null || schedule == null || interactionChannel == null)
            {
                throw new Exception("One or more of the settings could not be found. Ensure the group type, location, schedule, and interaction channel are valid.");
            }

            var campusId = location.CampusId;

            if (!campusId.HasValue)
            {
                throw new Exception("No campus could be found for " + location.Name);
            }

            var createdCutOff = RockDateTime.Now.AddDays(-1 * daysBack.Value);

            var interactionService = new InteractionService(rockContext);
            var interactions       = interactionService.Queryable("InteractionComponent")
                                     .Where(i =>
                                            i.InteractionComponent.ChannelId == interactionChannel.Id &&
                                            i.InteractionComponent.EntityId == campusId &&
                                            i.CreatedDateTime >= createdCutOff &&
                                            i.ForeignKey != "com_bricksandmortarstudio_Done"
                                            )
                                     .ToList();

            var epochTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            var attendanceService = new AttendanceService(rockContext);
            int counter           = 0;

            foreach (var interaction in interactions)
            {
                var interactionData = JsonConvert.DeserializeObject <InteractionData>(interaction.InteractionData);
                var startTime       = epochTime.AddSeconds(interactionData.Arrive);
                var endTime         = epochTime.AddSeconds(interactionData.Depart);

                // Gets one day worth of check in times, doing this in the loop is very inefficient
                var checkInTimes = schedule.GetCheckInTimes(startTime);
                if (interactionData == null)
                {
                    continue;
                }

                // https://stackoverflow.com/questions/13513932/algorithm-to-detect-overlapping-periods
                if (!checkInTimes.Any(t => t.CheckInStart < endTime && startTime < t.CheckInEnd))
                {
                    continue;
                }

                var attendance = new Attendance();
                attendance.PersonAliasId = interaction.PersonAliasId;
                attendance.ScheduleId    = schedule.Id;
                attendance.CampusId      = campusId;
                attendance.DidAttend     = true;
                attendance.LocationId    = location.Id;
                attendance.GroupId       = group.Id;
                attendance.StartDateTime = startTime;
                attendanceService.Add(attendance);
                interaction.ForeignKey = DONE_KEY;
                counter++;
            }
            rockContext.SaveChanges();
            context.Result = string.Format("Added {0} attendance records", counter);
        }
コード例 #18
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = RockDateTime.Now;

                bool reuseCodeForFamily = GetAttributeValue(action, "ReuseCodeForFamily").AsBoolean();

                int securityCodeLength = 3;
                if (!int.TryParse(GetAttributeValue(action, "SecurityCodeLength"), out securityCodeLength))
                {
                    securityCodeLength = 3;
                }

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);

                foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected))
                {
                    foreach (var person in family.People.Where(p => p.Selected))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GroupTypes.Where(g => g.Selected))
                        {
                            foreach (var group in groupType.Groups.Where(g => g.Selected))
                            {
                                foreach (var location in group.Locations.Where(l => l.Selected))
                                {
                                    if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                        groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                        !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                    {
                                        var groupMember = new GroupMember();
                                        groupMember.GroupId     = group.Group.Id;
                                        groupMember.PersonId    = person.Person.Id;
                                        groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                        groupMemberService.Add(groupMember);
                                    }

                                    foreach (var schedule in location.Schedules.Where(s => s.Selected))
                                    {
                                        // Only create one attendance record per day for each person/schedule/group/location
                                        var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                        if (attendance == null)
                                        {
                                            var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                            if (primaryAlias != null)
                                            {
                                                attendance = rockContext.Attendances.Create();
                                                attendance.Occurrence.LocationId = location.Location.Id;
                                                attendance.CampusId = location.CampusId;
                                                attendance.Occurrence.ScheduleId = schedule.Schedule.Id;
                                                attendance.Occurrence.GroupId    = group.Group.Id;
                                                attendance.PersonAlias           = primaryAlias;
                                                attendance.PersonAliasId         = primaryAlias.Id;
                                                attendance.DeviceId          = checkInState.Kiosk.Device.Id;
                                                attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id;
                                                attendanceService.Add(attendance);
                                            }
                                        }

                                        attendance.AttendanceCodeId = attendanceCode.Id;
                                        attendance.StartDateTime    = startDateTime;
                                        attendance.EndDateTime      = null;
                                        attendance.DidAttend        = false;

                                        KioskLocationAttendance.AddAttendance(attendance);
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();
                return(true);
            }
            errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null.");
            return(false);
        }
コード例 #19
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            if (_group != null && _occurrence != null)
            {
                var rockContext        = new RockContext();
                var attendanceService  = new AttendanceService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);
                var locationService    = new LocationService(rockContext);

                DateTime startDate = _occurrence.Date;
                DateTime endDate   = _occurrence.Date.AddDays(1);

                var existingAttendees = attendanceService
                                        .Queryable("PersonAlias")
                                        .Where(a =>
                                               a.GroupId == _group.Id &&
                                               a.LocationId == _occurrence.LocationId &&
                                               a.ScheduleId == _occurrence.ScheduleId &&
                                               a.StartDateTime >= startDate &&
                                               a.StartDateTime < endDate);

                // If did not meet was selected and this was a manually entered occurrence (not based on a schedule/location)
                // then just delete all the attendance records instead of tracking a 'did not meet' value
                if (cbDidNotMeet.Checked && !_occurrence.ScheduleId.HasValue)
                {
                    foreach (var attendance in existingAttendees)
                    {
                        attendanceService.Delete(attendance);
                    }
                }
                else
                {
                    if (cbDidNotMeet.Checked)
                    {
                        // If the occurrence is based on a schedule, set the did not meet flags
                        foreach (var attendance in existingAttendees)
                        {
                            attendance.DidAttend   = null;
                            attendance.DidNotOccur = true;
                        }
                    }

                    foreach (var attendee in _attendees)
                    {
                        var attendance = existingAttendees
                                         .Where(a => a.PersonAlias.PersonId == attendee.PersonId)
                                         .FirstOrDefault();

                        if (attendance == null)
                        {
                            int?personAliasId = personAliasService.GetPrimaryAliasId(attendee.PersonId);
                            if (personAliasId.HasValue)
                            {
                                attendance               = new Attendance();
                                attendance.GroupId       = _group.Id;
                                attendance.ScheduleId    = _group.ScheduleId;
                                attendance.PersonAliasId = personAliasId;
                                attendance.StartDateTime = _occurrence.Date;
                                attendance.LocationId    = _occurrence.LocationId;
                                attendance.CampusId      = locationService.GetCampusIdForLocation(_occurrence.LocationId);
                                attendance.ScheduleId    = _occurrence.ScheduleId;
                                attendanceService.Add(attendance);
                            }
                        }

                        if (attendance != null)
                        {
                            if (cbDidNotMeet.Checked)
                            {
                                attendance.DidAttend   = null;
                                attendance.DidNotOccur = true;
                            }
                            else
                            {
                                attendance.DidAttend   = attendee.Attended;
                                attendance.DidNotOccur = null;
                            }
                        }
                    }
                }

                rockContext.SaveChanges();

                WorkflowType workflowType     = null;
                Guid?        workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();
                if (workflowTypeGuid.HasValue)
                {
                    var workflowTypeService = new WorkflowTypeService(rockContext);
                    workflowType = workflowTypeService.Get(workflowTypeGuid.Value);
                    if (workflowType != null)
                    {
                        try
                        {
                            var workflow = Workflow.Activate(workflowType, _group.Name);

                            workflow.SetAttributeValue("StartDateTime", _occurrence.Date.ToString("o"));
                            workflow.SetAttributeValue("Schedule", _group.Schedule.Guid.ToString());

                            List <string> workflowErrors;
                            new WorkflowService(rockContext).Process(workflow, _group, out workflowErrors);
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogService.LogException(ex, this.Context);
                        }
                    }
                }

                NavigateToParentPage(new Dictionary <string, string> {
                    { "GroupId", _group.Id.ToString() }
                });
            }
        }
コード例 #20
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var isMobile          = GetAttributeValue(action, "IsMobile").AsBoolean();
            var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id;
            var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id;

            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                KioskService kioskService = new KioskService(rockContext);
                var          kioskTypeId  = kioskService.GetByClientName(checkInState.Kiosk.Device.Name).KioskTypeId;
                var          kioskType    = KioskTypeCache.Get(kioskTypeId.Value);
                var          campusId     = kioskType.CampusId;
                if (campusId == null)
                {
                    var compatableKioskType = KioskTypeCache.All().Where(kt => kt.CampusId.HasValue && kt.CheckinTemplateId == kioskType.CheckinTemplateId).FirstOrDefault();
                    if (compatableKioskType != null)
                    {
                        campusId = compatableKioskType.CampusId;
                    }
                    else
                    {
                        campusId = 0;
                    }
                }

                campusId = GetCampusOrFamilyCampusId(campusId, checkInState.CheckIn.CurrentFamily.Group.CampusId);


                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = Rock.RockDateTime.Now;
                DateTime       today          = startDateTime.Date;
                DateTime       tomorrow       = startDateTime.AddDays(1);

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);

                //This list is just for mobile check-in
                List <Attendance> attendances = new List <Attendance>();

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                        if (primaryAlias != null)
                                        {
                                            int groupId = ActualGroupId(group.Group);
                                            // If a like attendance service exists close it before creating another one.
                                            var oldAttendance = attendanceService.Queryable()
                                                                .Where(a =>
                                                                       a.StartDateTime >= today &&
                                                                       a.StartDateTime < tomorrow &&
                                                                       a.Occurrence.LocationId == location.Location.Id &&
                                                                       a.Occurrence.ScheduleId == schedule.Schedule.Id &&
                                                                       a.Occurrence.GroupId == groupId &&
                                                                       a.PersonAlias.PersonId == person.Person.Id)
                                                                .FirstOrDefault();

                                            if (oldAttendance != null)
                                            {
                                                oldAttendance.EndDateTime = Rock.RockDateTime.Now;
                                                oldAttendance.DidAttend   = false;
                                            }
                                            var attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, groupId,
                                                                                           location.Location.Id, schedule.Schedule.Id, campusId ?? location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                            attendance.DeviceId                 = checkInState.Kiosk.Device.Id;
                                            attendance.SearchTypeValueId        = checkInState.CheckIn.SearchType.Id;
                                            attendance.SearchValue              = checkInState.CheckIn.SearchValue;
                                            attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId;
                                            attendance.SearchResultGroupId      = family.Group.Id;
                                            attendance.AttendanceCodeId         = attendanceCode.Id;
                                            attendance.CreatedDateTime          = startDateTime;
                                            attendance.StartDateTime            = startDateTime;
                                            attendance.EndDateTime              = null;
                                            attendance.Note      = group.Notes;
                                            attendance.DidAttend = isMobile ? false : groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean();
                                            if (isMobile)
                                            {
                                                if (groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean())
                                                {
                                                    attendance.QualifierValueId = mobileDidAttendId;
                                                }
                                                else
                                                {
                                                    attendance.QualifierValueId = mobileNotAttendId;
                                                }
                                            }
                                            ;

                                            attendanceService.Add(attendance);
                                            attendances.Add(attendance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (isMobile)
                {
                    var alreadyExistingMobileCheckin = MobileCheckinRecordCache.GetActiveByFamilyGroupId(checkInState.CheckIn.CurrentFamily.Group.Id);
                    if (alreadyExistingMobileCheckin != null)
                    {
                        //This should never run, it's just in case. Each family should only have 1 mobile check-in reservation.
                        MobileCheckinRecordCache.CancelReservation(alreadyExistingMobileCheckin, true);
                    }

                    campusId = RollUpToParentCampus(campusId);

                    MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext);
                    var mobileCheckinRecord = new MobileCheckinRecord
                    {
                        AccessKey             = "MCR" + Guid.NewGuid().ToString("N").Substring(0, 12),
                        ReservedUntilDateTime = Rock.RockDateTime.Now.AddMinutes(kioskType.MinutesValid ?? 10),
                        ExpirationDateTime    = Rock.RockDateTime.Now.AddMinutes((kioskType.MinutesValid ?? 10) + (kioskType.GraceMinutes ?? 60)),
                        UserName      = checkInState.CheckIn.SearchValue,
                        FamilyGroupId = checkInState.CheckIn.CurrentFamily.Group.Id,
                        CampusId      = campusId.Value
                    };

                    foreach (var attendance in attendances)
                    {
                        mobileCheckinRecord.Attendances.Add(attendance);
                    }

                    mobileCheckinRecordService.Add(mobileCheckinRecord);
                }

                rockContext.SaveChanges();
                foreach (var attendance in attendances)
                {
                    AttendanceCache.AddOrUpdate(attendance);
                }
                return(true);
            }
            errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null.");
            return(false);
        }
コード例 #21
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            btnDone.Visible   = true;
            lblPeople.Visible = true;


            //Create List to Save Registered People

            var peopleList = new List <string>();

            if (Session["peopleList"] != null)
            {
                peopleList = (List <string>)Session["peopleList"];
            }


            AttendanceCodeService attendanceCodeService = new AttendanceCodeService(rockContext);
            AttendanceService     attendanceService     = new AttendanceService(rockContext);
            GroupMemberService    groupMemberService    = new GroupMemberService(rockContext);
            PersonAliasService    personAliasService    = new PersonAliasService(rockContext);

            Session["person"] = ppPerson.SelectedValue.ToString();

            // Only create one attendance record per day for each person/schedule/group/location
            DateTime theTime      = Convert.ToDateTime(Session["startDateTime"]);
            var      attendance   = attendanceService.Get(theTime, int.Parse(Session["location"].ToString()), int.Parse(Session["schedule"].ToString()), int.Parse(Session["group"].ToString()), int.Parse(ppPerson.SelectedValue.ToString()));
            var      primaryAlias = personAliasService.GetPrimaryAlias(int.Parse(ppPerson.SelectedValue.ToString()));

            if (attendance == null)
            {
                if (primaryAlias != null)
                {
                    attendance                   = rockContext.Attendances.Create();
                    attendance.LocationId        = int.Parse(Session["location"].ToString());
                    attendance.CampusId          = int.Parse(Session["campus"].ToString());
                    attendance.ScheduleId        = int.Parse(Session["schedule"].ToString());
                    attendance.GroupId           = int.Parse(Session["group"].ToString());
                    attendance.PersonAlias       = primaryAlias;
                    attendance.PersonAliasId     = primaryAlias.Id;
                    attendance.DeviceId          = null;
                    attendance.SearchTypeValueId = 1;
                    attendanceService.Add(attendance);
                }
            }
            attendance.AttendanceCodeId = null;
            attendance.StartDateTime    = Convert.ToDateTime(Session["startDateTime"]);
            attendance.EndDateTime      = null;
            attendance.DidAttend        = true;

            //KioskLocationAttendance.AddAttendance(attendance);
            rockContext.SaveChanges();

            //Add Person to Dictionary
            peopleList.Add(ppPerson.PersonName);
            repLinks.DataSource = peopleList;
            repLinks.DataBind();
            Session["peopleList"] = peopleList;


            //Clear Person field
            ppPerson.PersonId   = null;
            ppPerson.PersonName = null;


            //Update Current Participants List
        }
コード例 #22
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            RockContext rockContext        = new RockContext();
            var         attendanceService  = new AttendanceService(rockContext);
            var         groupMemberService = new GroupMemberService(rockContext);

            foreach (RepeaterItem item in rptScheduleDates.Items)
            {
                var placeholder = item.FindControl("phGroups") as PlaceHolder;

                if (placeholder != null)
                {
                    // get groups
                    foreach (Control control in placeholder.Controls)
                    {
                        if (control is DropDownList)
                        {
                            var ddlGroup = (DropDownList)control;

                            var groupId         = ddlGroup.SelectedValue.AsInteger();
                            var scheduleId      = ddlGroup.Attributes["schedule-id"].AsInteger();
                            var scheduleDate    = ddlGroup.Attributes["schedule-date"].AsDateTime();
                            var originalGroupId = ddlGroup.Attributes["original-group-id"].AsInteger();

                            // check if person is already registered for this schedule
                            var attending = _personalSchedules.Where(p =>
                                                                     p.Date.Date == scheduleDate.Value.Date &&
                                                                     p.Schedule.Id == scheduleId &&
                                                                     p.Group.Id == groupId)
                                            .Any();

                            if (originalGroupId != 0 && groupId == 0)
                            {
                                RemovePersonRsvp(CurrentPerson, originalGroupId, scheduleId, scheduleDate);
                            }
                            else if (!attending && groupId != 0)
                            {
                                // remove existing record
                                if (originalGroupId != 0)
                                {
                                    RemovePersonRsvp(CurrentPerson, originalGroupId, scheduleId, scheduleDate);
                                }

                                // mark them as coming
                                var attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
                                var attendanceOccurrence        = attendanceOccurrenceService.Queryable()
                                                                  .Where(o =>
                                                                         o.GroupId == groupId &&
                                                                         o.ScheduleId == scheduleId &&
                                                                         o.LocationId == _location.Id
                                                                         )
                                                                  .FirstOrDefault();

                                // Didn't find an attendance occurence to mark the attendance for. This should not happen, but just in case.
                                if (attendanceOccurrence == null)
                                {
                                    nbMessages.NotificationBoxType = NotificationBoxType.Warning;
                                    nbMessages.Text = "Could not find a matching attendance occurrence to add the attendance to.";
                                    return;
                                }

                                var attendanceRecord = new Attendance
                                {
                                    PersonAliasId = CurrentPersonAliasId,
                                    OccurrenceId  = attendanceOccurrence.Id,
                                    StartDateTime = scheduleDate.Value.Date,
                                    RSVP          = RSVP.Yes
                                };

                                attendanceService.Add(attendanceRecord);
                                rockContext.SaveChanges();

                                // add them to the group
                                var groupMember = groupMemberService.Queryable().Where(m => m.PersonId == CurrentPersonId && m.GroupId == groupId).FirstOrDefault();

                                if (groupMember == null)
                                {
                                    bool createAsInactive = GetAttributeValue("GroupMembersInactive").AsBoolean();

                                    groupMember                   = new GroupMember();
                                    groupMember.PersonId          = CurrentPersonId.Value;
                                    groupMember.GroupId           = groupId;
                                    groupMember.GroupMemberStatus = createAsInactive ? GroupMemberStatus.Inactive : GroupMemberStatus.Active;
                                    groupMember.GroupRoleId       = _groupRoleId;

                                    groupMemberService.Add(groupMember);
                                }


                                rockContext.SaveChanges();

                                var scheduleName = new ScheduleService(rockContext).Queryable().Where(s => s.Id == scheduleId).Select(s => s.Name).FirstOrDefault();

                                if (!string.IsNullOrWhiteSpace(GetAttributeValue("DescriptionAttribute")))
                                {
                                    groupMember.LoadAttributes();
                                    groupMember.SetAttributeValue(GetAttributeValue("DescriptionAttribute"), string.Format("{0} {1}", scheduleDate.Value.ToShortDateString(), scheduleName));
                                    groupMember.SaveAttributeValues();
                                }
                            }
                        }
                    }
                }
            }

            nbMessages.NotificationBoxType = NotificationBoxType.Success;
            nbMessages.Text = "Your changes have been saved.";
        }
コード例 #23
0
ファイル: SaveAttendance.cs プロジェクト: timothybaloyi/Rock
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = RockDateTime.Now;

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeLength : 3;

                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);


                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        // Only create one attendance record per day for each person/schedule/group/location
                                        var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                        if (attendance == null)
                                        {
                                            var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                            if (primaryAlias != null)
                                            {
                                                attendance                     = rockContext.Attendances.Create();
                                                attendance.LocationId          = location.Location.Id;
                                                attendance.CampusId            = location.CampusId;
                                                attendance.ScheduleId          = schedule.Schedule.Id;
                                                attendance.GroupId             = group.Group.Id;
                                                attendance.PersonAlias         = primaryAlias;
                                                attendance.PersonAliasId       = primaryAlias.Id;
                                                attendance.DeviceId            = checkInState.Kiosk.Device.Id;
                                                attendance.SearchTypeValueId   = checkInState.CheckIn.SearchType.Id;
                                                attendance.SearchValue         = checkInState.CheckIn.SearchValue;
                                                attendance.SearchResultGroupId = family.Group.Id;
                                                attendanceService.Add(attendance);
                                            }
                                        }

                                        attendance.AttendanceCodeId = attendanceCode.Id;
                                        attendance.StartDateTime    = startDateTime;
                                        attendance.EndDateTime      = null;
                                        attendance.DidAttend        = true;

                                        KioskLocationAttendance.AddAttendance(attendance);
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();
                return(true);
            }

            return(false);
        }
コード例 #24
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            if (_group != null && _occurrence != null)
            {
                var rockContext        = new RockContext();
                var attendanceService  = new AttendanceService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);
                var locationService    = new LocationService(rockContext);

                bool dateAdjusted = false;

                DateTime startDate = _occurrence.Date;

                // If this is a manuall entered occurrence, check to see if date was changed
                if (!_occurrence.ScheduleId.HasValue)
                {
                    DateTime?originalDate = PageParameter("Date").AsDateTime();
                    if (originalDate.HasValue && originalDate.Value.Date != startDate.Date)
                    {
                        startDate    = originalDate.Value.Date;
                        dateAdjusted = true;
                    }
                }
                DateTime endDate = startDate.AddDays(1);

                var existingAttendees = attendanceService
                                        .Queryable("PersonAlias")
                                        .Where(a =>
                                               a.GroupId == _group.Id &&
                                               a.LocationId == _occurrence.LocationId &&
                                               a.ScheduleId == _occurrence.ScheduleId &&
                                               a.StartDateTime >= startDate &&
                                               a.StartDateTime < endDate);

                if (dateAdjusted)
                {
                    foreach (var attendee in existingAttendees)
                    {
                        attendee.StartDateTime = _occurrence.Date;
                    }
                }

                // If did not meet was selected and this was a manually entered occurrence (not based on a schedule/location)
                // then just delete all the attendance records instead of tracking a 'did not meet' value
                if (cbDidNotMeet.Checked && !_occurrence.ScheduleId.HasValue)
                {
                    foreach (var attendance in existingAttendees)
                    {
                        attendanceService.Delete(attendance);
                    }
                }
                else
                {
                    int?campusId = locationService.GetCampusIdForLocation(_occurrence.LocationId);
                    if (!campusId.HasValue)
                    {
                        campusId = _group.CampusId;
                    }
                    if (!campusId.HasValue && _allowCampusFilter)
                    {
                        var campus = CampusCache.Read(ExtensionMethods.SelectedValueAsInt(bddlCampus) ?? 0);
                        if (campus != null)
                        {
                            campusId = campus.Id;
                        }
                    }

                    if (cbDidNotMeet.Checked)
                    {
                        // If the occurrence is based on a schedule, set the did not meet flags
                        foreach (var attendance in existingAttendees)
                        {
                            attendance.DidAttend   = null;
                            attendance.DidNotOccur = true;
                        }
                    }

                    foreach (var attendee in _attendees)
                    {
                        var attendance = existingAttendees
                                         .Where(a => a.PersonAlias.PersonId == attendee.PersonId)
                                         .FirstOrDefault();

                        if (attendance == null)
                        {
                            int?personAliasId = personAliasService.GetPrimaryAliasId(attendee.PersonId);
                            if (personAliasId.HasValue)
                            {
                                attendance               = new Attendance();
                                attendance.GroupId       = _group.Id;
                                attendance.ScheduleId    = _group.ScheduleId;
                                attendance.PersonAliasId = personAliasId;
                                attendance.StartDateTime = _occurrence.Date.Date.Add(_occurrence.StartTime);
                                attendance.LocationId    = _occurrence.LocationId;
                                attendance.CampusId      = campusId;
                                attendance.ScheduleId    = _occurrence.ScheduleId;

                                // check that the attendance record is valid
                                cvAttendance.IsValid = attendance.IsValid;
                                if (!cvAttendance.IsValid)
                                {
                                    cvAttendance.ErrorMessage = attendance.ValidationResults.Select(a => a.ErrorMessage).ToList().AsDelimited("<br />");
                                    return;
                                }

                                attendanceService.Add(attendance);
                            }
                        }

                        if (attendance != null)
                        {
                            if (cbDidNotMeet.Checked)
                            {
                                attendance.DidAttend   = null;
                                attendance.DidNotOccur = true;
                            }
                            else
                            {
                                attendance.DidAttend   = attendee.Attended;
                                attendance.DidNotOccur = null;
                            }
                        }
                    }
                }

                if (_occurrence.LocationId.HasValue)
                {
                    Rock.CheckIn.KioskLocationAttendance.Flush(_occurrence.LocationId.Value);
                }

                rockContext.SaveChanges();

                WorkflowType workflowType     = null;
                Guid?        workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();
                if (workflowTypeGuid.HasValue)
                {
                    var workflowTypeService = new WorkflowTypeService(rockContext);
                    workflowType = workflowTypeService.Get(workflowTypeGuid.Value);
                    if (workflowType != null)
                    {
                        try
                        {
                            var workflow = Workflow.Activate(workflowType, _group.Name);

                            workflow.SetAttributeValue("StartDateTime", _occurrence.Date.ToString("o"));
                            workflow.SetAttributeValue("Schedule", _group.Schedule.Guid.ToString());

                            List <string> workflowErrors;
                            new WorkflowService(rockContext).Process(workflow, _group, out workflowErrors);
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogService.LogException(ex, this.Context);
                        }
                    }
                }

                var qryParams = new Dictionary <string, string> {
                    { "GroupId", _group.Id.ToString() }
                };

                var groupTypeIds = PageParameter("GroupTypeIds");
                if (!string.IsNullOrWhiteSpace(groupTypeIds))
                {
                    qryParams.Add("GroupTypeIds", groupTypeIds);
                }

                NavigateToParentPage(qryParams);
            }
        }
コード例 #25
0
        protected void btnRecord_Click(object sender, EventArgs e)
        {
            var peopleIds = new List <int>();

            foreach (GridViewRow row in gResults.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("chkSelect");
                if (cb.Checked)
                {
                    string dataKey = gResults.DataKeys[row.RowIndex].Value.ToString();
                    if (!String.IsNullOrEmpty(dataKey))
                    {
                        peopleIds.Add(Convert.ToInt32(dataKey));
                    }
                }
            }
            var campusWorshipAttendance = Session["campus-worship-attendance"] as List <CampusWorshipAttendance>;
            CampusWorshipAttendance selectedWorshipService = null;

            if (campusWorshipAttendance != null)
            {
                selectedWorshipService = campusWorshipAttendance.Find(m => m.Text == ddlWorshipService.SelectedValue);
            }
            Guid?groupGuid  = null;
            Guid?campusGuid = null;

            if (selectedWorshipService != null)
            {
                groupGuid  = selectedWorshipService.WorshipService.AsGuid();
                campusGuid = selectedWorshipService.Campus.AsGuid();
            }
            else
            {
                lblMessage.Text = "Could not record attendance, campus worship attendance not set";
                return;
            }
            var people = new PersonService(ctx).GetByIds(peopleIds);

            foreach (Person person in people)
            {
                var lastSunday        = GetLastSunday((DateTime)dpAttendanceDate.SelectedDate);
                var attendanceService = new AttendanceService(ctx);
                var attendance        = attendanceService.Queryable().Where(a => a.PersonAliasId == person.PrimaryAliasId &&
                                                                            a.SundayDate.Year == lastSunday.Year &&
                                                                            a.SundayDate.Month == lastSunday.Month &&
                                                                            a.SundayDate.Day == lastSunday.Day &&
                                                                            a.Group.Guid == groupGuid.Value &&
                                                                            a.Campus.Guid == campusGuid.Value).FirstOrDefault();
                if (attendance == null)
                {
                    attendanceService.Add(new Rock.Model.Attendance
                    {
                        PersonAlias   = person.PrimaryAlias,
                        StartDateTime = (DateTime)dpAttendanceDate.SelectedDate,
                        Group         = new GroupService(ctx).Get(groupGuid.Value),
                        Campus        = new CampusService(ctx).Get(campusGuid.Value),
                        DidAttend     = true
                    });
                    if (lblMessage.Text.Contains("Attendance Recorded For"))
                    {
                        lblMessage.Text += ", " + person.FirstName + " " + person.LastName;
                    }
                    else
                    {
                        lblMessage.Text += "Attendance Recorded For: " + person.FirstName + " " + person.LastName;
                    }
                }
                else
                {
                    lblMessage.Text += "Attendance Already Exists for " + person.FirstName + " " + person.LastName + "<BR>";
                }
            }

            ctx.SaveChanges();

            clearForm();
            clearResults();
        }
コード例 #26
0
ファイル: SaveAttendance.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                DateTime startDateTime = DateTime.Now;

                int securityCodeLength = 3;
                if (!int.TryParse(GetAttributeValue(action, "SecurityCodeLength"), out securityCodeLength))
                {
                    securityCodeLength = 3;
                }

                using (var uow = new Rock.Data.UnitOfWorkScope())
                {
                    var attendanceCodeService = new AttendanceCodeService();
                    var attendanceService     = new AttendanceService();
                    var groupMemberService    = new GroupMemberService();

                    foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected))
                    {
                        foreach (var person in family.People.Where(p => p.Selected))
                        {
                            var attendanceCode = attendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;

                            foreach (var groupType in person.GroupTypes.Where(g => g.Selected))
                            {
                                foreach (var group in groupType.Groups.Where(g => g.Selected))
                                {
                                    foreach (var location in group.Locations.Where(l => l.Selected))
                                    {
                                        if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                            groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                            !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                        {
                                            var groupMember = new GroupMember();
                                            groupMember.GroupId     = group.Group.Id;
                                            groupMember.PersonId    = person.Person.Id;
                                            groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                            groupMemberService.Add(groupMember, null);
                                            groupMemberService.Save(groupMember, null);
                                        }

                                        foreach (var schedule in location.Schedules.Where(s => s.Selected))
                                        {
                                            // Only create one attendance record per day for each person/schedule/group/location
                                            var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                            if (attendance == null)
                                            {
                                                attendance                   = ((Rock.Data.RockContext)uow.DbContext).Attendances.Create();
                                                attendance.LocationId        = location.Location.Id;
                                                attendance.ScheduleId        = schedule.Schedule.Id;
                                                attendance.GroupId           = group.Group.Id;
                                                attendance.PersonId          = person.Person.Id;
                                                attendance.DeviceId          = checkInState.Kiosk.Device.Id;
                                                attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id;
                                                attendanceService.Add(attendance, null);
                                            }

                                            attendance.AttendanceCodeId = attendanceCode.Id;
                                            attendance.StartDateTime    = startDateTime;
                                            attendance.EndDateTime      = null;
                                            attendance.DidAttend        = true;
                                            attendanceService.Save(attendance, null);

                                            KioskLocationAttendance.AddAttendance(attendance);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
コード例 #27
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap     = context.JobDetail.JobDataMap;
            var        rockContext = new RockContext();

            InteractionChannelService   channelService     = new InteractionChannelService(rockContext);
            InteractionComponentService componentService   = new InteractionComponentService(rockContext);
            InteractionService          interactionService = new InteractionService(rockContext);
            ScheduleService             scheduleService    = new ScheduleService(rockContext);
            LocationService             locationService    = new LocationService(rockContext);
            AttendanceService           attendanceService  = new AttendanceService(rockContext);
            GroupService groupService = new GroupService(rockContext);

            // Load the channel
            InteractionChannelCache channel = InteractionChannelCache.Read(dataMap.GetString("InteractionChannel").AsGuid());

            // Setup
            int    campusLocationTypeId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS).Id;
            var    groupType            = GroupTypeCache.Read(dataMap.GetString("GroupType").AsGuid());
            var    groups    = groupService.GetByGroupTypeId(groupType.Id);
            string operation = !string.IsNullOrWhiteSpace(dataMap.GetString("Operation")) ? dataMap.GetString("Operation") : null;

            // Fetch the job so we can get the last run date/time
            int jobId      = Convert.ToInt16(context.JobDetail.Description);
            var jobService = new ServiceJobService(rockContext);
            var job        = jobService.Get(jobId);

            DateTime lastRun = job?.LastSuccessfulRunDateTime ?? DateTime.MinValue;

            var componentCampusMapping = dataMap.GetString("ComponentCampusMapping").AsDictionaryOrNull();

            foreach (var componentName in componentCampusMapping.Keys)
            {
                var         component = componentService.Queryable().Where(cs => cs.Name.ToLower() == componentName.ToLower() && cs.ChannelId == channel.Id).FirstOrDefault();
                CampusCache campus    = CampusCache.All().Where(c => c.Name == componentCampusMapping[componentName]).FirstOrDefault();

                if (campus != null && component != null)
                {
                    Group group = groups.Where(g => g.IsActive == true && g.CampusId == campus.Id).FirstOrDefault();
                    if (group?.GroupLocations != null)
                    {
                        foreach (var gl in group?.GroupLocations)
                        {
                            Location location = gl.Location;
                            foreach (Schedule schedule in gl.Schedules)
                            {
                                var occurrences = schedule.GetOccurrences(DateTime.MinValue, DateTime.Now);
                                foreach (var occurrence in occurrences)
                                {
                                    DateTime startDate = occurrence.Period.StartTime.Value;
                                    DateTime endDate   = occurrence.Period.EndTime.Value;

                                    var peopleAttended = interactionService.Queryable().Where(
                                        i => i.InteractionComponentId == component.Id &&
                                        i.InteractionDateTime <= endDate &&
                                        i.InteractionEndDateTime >= startDate &&
                                        i.PersonAliasId != null &&
                                        (i.CreatedDateTime > lastRun || i.PersonalDevice.ModifiedDateTime > lastRun || i.PersonalDevice.CreatedDateTime > lastRun) &&
                                        (operation == null || i.Operation == operation)
                                        ).Select(i => i.PersonAliasId).Distinct();
                                    int newAttendance = 0;
                                    foreach (int personAliasId in peopleAttended)
                                    {
                                        // Make sure we don't already have an attendance Record
                                        if (!attendanceService.Queryable().Any(a => DbFunctions.TruncateTime(a.StartDateTime) == occurrence.Period.StartTime.Value.Date && a.ScheduleId == schedule.Id && a.PersonAliasId == personAliasId && a.GroupId == group.Id && a.LocationId == location.Id && a.DidAttend == true))
                                        {
                                            Attendance attendance = new Attendance()
                                            {
                                                PersonAliasId = personAliasId,
                                                CampusId      = campus.Id,
                                                GroupId       = group.Id,
                                                LocationId    = location.Id,
                                                ScheduleId    = schedule.Id,
                                                StartDateTime = occurrence.Period.StartTime.Value,
                                                EndDateTime   = occurrence.Period?.EndTime?.Value,
                                                DidAttend     = true
                                            };
                                            attendanceService.Add(attendance);
                                            newAttendance++;
                                        }
                                    }
                                    if (newAttendance > 0)
                                    {
                                        rockContext.SaveChanges();
                                        context.Result += string.Format("{0} people attended {1} on {2} (Component {3}).\n", newAttendance, campus.Name, occurrence.Period.StartTime.Value.ToString("MM/dd/yyyy h:mm tt"), component.Name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            if (_group != null && _occurrence != null)
            {
                var rockContext        = new RockContext();
                var attendanceService  = new AttendanceService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);

                var existingAttendees = attendanceService.Queryable()
                                        .Where(a =>
                                               a.GroupId == _group.Id &&
                                               a.ScheduleId == _group.ScheduleId &&
                                               a.StartDateTime >= _occurrence.StartDateTime &&
                                               a.StartDateTime < _occurrence.EndDateTime)
                                        .ToList();

                // If did not meet was selected and this was a manually entered occurrence (not based on a schedule)
                // then just delete all the attendance records instead of tracking a 'did not meet' value
                if (cbDidNotMeet.Checked && !_occurrence.ScheduleId.HasValue)
                {
                    foreach (var attendance in existingAttendees)
                    {
                        attendanceService.Delete(attendance);
                    }
                }
                else
                {
                    if (cbDidNotMeet.Checked)
                    {
                        // If the occurrence is based on a schedule, set the did not meet flags
                        foreach (var attendance in existingAttendees)
                        {
                            attendance.DidAttend   = null;
                            attendance.DidNotOccur = true;
                        }
                    }

                    foreach (var item in lvMembers.Items)
                    {
                        var hfMember = item.FindControl("hfMember") as HiddenField;
                        var cbMember = item.FindControl("cbMember") as CheckBox;

                        if (hfMember != null && cbMember != null)
                        {
                            int personId = hfMember.ValueAsInt();

                            var attendance = existingAttendees
                                             .Where(a => a.PersonAlias.PersonId == personId)
                                             .FirstOrDefault();

                            if (attendance == null)
                            {
                                int?personAliasId = personAliasService.GetPrimaryAliasId(personId);
                                if (personAliasId.HasValue)
                                {
                                    attendance               = new Attendance();
                                    attendance.GroupId       = _group.Id;
                                    attendance.ScheduleId    = _group.ScheduleId;
                                    attendance.PersonAliasId = personAliasId;
                                    attendance.StartDateTime = _occurrence.StartDateTime;
                                    attendanceService.Add(attendance);
                                }
                            }

                            if (attendance != null)
                            {
                                if (cbDidNotMeet.Checked)
                                {
                                    attendance.DidAttend   = null;
                                    attendance.DidNotOccur = true;
                                }
                                else
                                {
                                    attendance.DidAttend   = cbMember.Checked;
                                    attendance.DidNotOccur = null;
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();

                WorkflowType workflowType     = null;
                Guid?        workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();
                if (workflowTypeGuid.HasValue)
                {
                    var workflowTypeService = new WorkflowTypeService(rockContext);
                    workflowType = workflowTypeService.Get(workflowTypeGuid.Value);
                    if (workflowType != null)
                    {
                        try
                        {
                            var workflowService = new WorkflowService(rockContext);
                            var workflow        = Workflow.Activate(workflowType, _group.Name);

                            workflow.SetAttributeValue("StartDateTime", _occurrence.StartDateTime.ToString("o"));
                            workflow.SetAttributeValue("Schedule", _group.Schedule.Guid.ToString());

                            List <string> workflowErrors;
                            if (workflow.Process(rockContext, _group, out workflowErrors))
                            {
                                if (workflow.IsPersisted || workflow.IsPersisted)
                                {
                                    if (workflow.Id == 0)
                                    {
                                        workflowService.Add(workflow);
                                    }

                                    rockContext.WrapTransaction(() =>
                                    {
                                        rockContext.SaveChanges();
                                        workflow.SaveAttributeValues(_rockContext);
                                        foreach (var activity in workflow.Activities)
                                        {
                                            activity.SaveAttributeValues(rockContext);
                                        }
                                    });
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogService.LogException(ex, this.Context);
                        }
                    }
                }

                NavigateToParentPage(new Dictionary <string, string> {
                    { "GroupId", _group.Id.ToString() }
                });
            }
        }
コード例 #29
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                Guid checkinGroupAttributeGuid = GetAttributeValue(action, "CheckinGroupAttribute").AsGuid();
                if (checkinGroupAttributeGuid == Guid.Empty)
                {
                    throw new Exception("CheckInGroupAttribute not set. Set attribute to continue.");
                }
                string checkinGroupAttributeKey = AttributeCache.Read(checkinGroupAttributeGuid, rockContext).Key;

                string sessionAttributeKey = GetAttributeValue(action, "SessionAttributeKey");

                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = RockDateTime.Now;

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                AttendanceCodeService attendanceCodeService = new AttendanceCodeService(rockContext);
                AttendanceService     attendanceService     = new AttendanceService(rockContext);
                GroupMemberService    groupMemberService    = new GroupMemberService(rockContext);
                PersonAliasService    personAliasService    = new PersonAliasService(rockContext);
                GroupService          groupService          = new GroupService(rockContext);

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                var referenceGroupGuid = group.Group.GetAttributeValue(checkinGroupAttributeKey).AsGuid();
                                var referenceGroup     = groupService.Get(referenceGroupGuid);
                                if (referenceGroup == null)
                                {
                                    group.Selected = false;
                                    continue;
                                }
                                GroupMember groupMember = groupMemberService.GetByGroupIdAndPersonId(referenceGroup.Id, person.Person.Id).FirstOrDefault();
                                if (groupMember == null)
                                {
                                    group.Selected = false;
                                    continue;
                                }
                                groupMember.LoadAttributes();
                                int sessions = groupMember.GetAttributeValue(sessionAttributeKey).AsInteger();

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        if (sessions == 0)
                                        {
                                            continue;
                                        }

                                        // Only create one attendance record per day for each person/schedule/group/location
                                        var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                        if (attendance == null)
                                        {
                                            var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                            if (primaryAlias != null)
                                            {
                                                attendance                   = rockContext.Attendances.Create();
                                                attendance.LocationId        = location.Location.Id;
                                                attendance.CampusId          = location.CampusId;
                                                attendance.ScheduleId        = schedule.Schedule.Id;
                                                attendance.GroupId           = group.Group.Id;
                                                attendance.PersonAlias       = primaryAlias;
                                                attendance.PersonAliasId     = primaryAlias.Id;
                                                attendance.DeviceId          = checkInState.Kiosk.Device.Id;
                                                attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id;
                                                attendanceService.Add(attendance);
                                            }

                                            //decrement sessions and save
                                            sessions--;
                                            groupMember.SetAttributeValue(sessionAttributeKey, sessions);
                                            groupMember.SaveAttributeValues();
                                        }
                                        else
                                        {
                                            foreach (var cPerson in checkInState.CheckIn.Families.SelectMany(f => f.People))
                                            {
                                                cPerson.Selected = false;
                                                cPerson.GroupTypes.ForEach(gt => gt.Selected = false);
                                            }
                                            return(true);
                                        }

                                        attendance.AttendanceCodeId = attendanceCode.Id;
                                        attendance.StartDateTime    = startDateTime;
                                        attendance.EndDateTime      = null;
                                        attendance.DidAttend        = true;

                                        KioskLocationAttendance.AddAttendance(attendance);
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();
                return(true);
            }
            return(false);
        }
コード例 #30
0
 /// <summary>
 /// 新增员工今日考勤信息
 /// </summary>
 /// <param name="temp"></param>
 /// <returns></returns>
 public void NewAtten(Attendance temp)
 {
     temp.ID        = Guid.NewGuid();
     temp.IsDeleted = false;
     attendance.Add(temp);
 }