Пример #1
0
        private void ShowAttendance()
        {
            lMtgDate.Text  = groupDate.ToLongDateString();
            lbNext.Visible = groupDate.AddDays(7) <= DateTime.Today;

            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("person_id", typeof(Int32)));
            dt.Columns.Add(new DataColumn("person_name", typeof(string)));
            dt.Columns.Add(new DataColumn("attended", typeof(bool)));

            List <int> people = new List <int>();

            GroupOccurrence occurrence = FindOccurrenceByDate(group.Occurrences, groupDate);

            if (occurrence != null)
            {
                cbNoMeet.Checked = occurrence.OccurrenceClosed;

                SqlDataReader rdr = occurrenceData.GetOccurrenceAttendanceByOccurrenceID(occurrence.OccurrenceID, -1);
                while (rdr.Read())
                {
                    int personId = (int)rdr["person_id"];
                    people.Add(personId);

                    dt.Rows.Add(BuildAttendanceRow(dt,
                                                   personId,
                                                   rdr["person_name"].ToString(),
                                                   (bool)rdr["attended"]));
                }
                rdr.Close();
            }
            else
            {
                cbNoMeet.Checked = false;
            }

            if (group.Leader.PersonID != -1 && !people.Contains(group.Leader.PersonID))
            {
                dt.Rows.Add(BuildAttendanceRow(dt, group.Leader.PersonID, group.Leader.FullName, false));
            }

            foreach (GroupMember member in group.Members)
            {
                if (member.Active && !people.Contains(member.PersonID))
                {
                    dt.Rows.Add(BuildAttendanceRow(dt, member.PersonID, member.FullName, false));
                }
            }

            lvMembers.DataSource = dt;
            lvMembers.DataBind();

            ViewState["GroupDate"] = groupDate;
        }
Пример #2
0
        /// <summary>
        /// Map an Arena group occurrence to a SmallGroupOccurance Contract
        /// </summary>
        /// <param name="arena">The Occurrence from arena</param>
        /// <returns>A new SmallGroupOccurance</returns>
        public SmallGroupOccurrence FromArena(GroupOccurrence arena)
        {
            SmallGroupOccurrence occurrence = new SmallGroupOccurrence();

            occurrence.OccurrenceID = arena.OccurrenceID;
            occurrence.Name         = arena.Name;
            occurrence.Start        = arena.StartTime;
            occurrence.End          = arena.EndTime;
            occurrence.Description  = arena.Description;
            occurrence.Attendees    = new List <GenericReference>();
            foreach (var attender in arena.OccurrenceAttendances)
            {
                if (attender.Attended)
                {
                    GenericReference person = new GenericReference(attender.Person);
                    occurrence.Attendees.Add(person);
                }
            }

            return(occurrence);
        }
Пример #3
0
        public void btnCloseFinish_Click(object sender, EventArgs e)
        {
            DropDownList ddl;
            TableRow     tr;
            int          i;


            //
            // Walk through each occurrence row and make sure they have
            // selected a new target location.
            //
            for (i = 1; i < (tblClose.Rows.Count - 1); i++)
            {
                tr  = tblClose.Rows[i];
                ddl = (DropDownList)tr.Cells[kCloseNewLocationColumn].Controls[0];
                if (ddl.SelectedValue == "")
                {
                    lbCloseError.Text = "You must select a new target location for each occurrence.";

                    return;
                }
                else
                {
                    lbCloseError.Text = "";
                }
            }

            //
            // Walk through each occurrence row and open a new occurrence
            // if they have selected a new location. After the occurrence
            // is opened, close the old occurrence.
            //
            for (i = 1; i < (tblClose.Rows.Count - 1); i++)
            {
                tr  = tblClose.Rows[i];
                ddl = (DropDownList)tr.Cells[kCloseNewLocationColumn].Controls[0];
                try
                {
                    Occurrence oldOccurrence;
                    int        locationID = Convert.ToInt32(ddl.SelectedValue);

                    oldOccurrence = new Occurrence(Convert.ToInt32(((Label)tr.Cells[kCloseOccurrenceIDColumn].Controls[0]).Text));

                    //
                    // Setup the new location.
                    //
                    if (locationID != -1)
                    {
                        ProfileOccurrence po            = new ProfileOccurrence(oldOccurrence.OccurrenceID);
                        GroupOccurrence   go            = new GroupOccurrence(oldOccurrence.OccurrenceID);
                        Occurrence        newOccurrence = new Occurrence();

                        newOccurrence.AreaID             = oldOccurrence.AreaID;
                        newOccurrence.CheckInEnd         = oldOccurrence.CheckInEnd;
                        newOccurrence.CheckInStart       = oldOccurrence.CheckInStart;
                        newOccurrence.Description        = oldOccurrence.Description;
                        newOccurrence.EndTime            = oldOccurrence.EndTime;
                        newOccurrence.LocationID         = locationID;
                        newOccurrence.Location           = new Location(locationID).FullName;
                        newOccurrence.MembershipRequired = oldOccurrence.MembershipRequired;
                        newOccurrence.Name             = oldOccurrence.Name;
                        newOccurrence.OccurrenceTypeID = oldOccurrence.OccurrenceTypeID;
                        newOccurrence.StartTime        = oldOccurrence.StartTime;
                        newOccurrence.Title            = oldOccurrence.Title;
                        newOccurrence.Save(CurrentUser.Identity.Name);

                        //
                        // Create the link to the profile, if there is one.
                        //
                        if (po.ProfileID != -1)
                        {
                            ProfileOccurrence npo = new ProfileOccurrence(newOccurrence.OccurrenceID);
                            npo.ProfileID = po.ProfileID;
                            npo.Save(CurrentUser.Identity.Name);
                        }

                        //
                        // Create the link to the group, if there is one.
                        //
                        if (go.GroupID != -1)
                        {
                            GroupOccurrence ngo = new GroupOccurrence(newOccurrence.OccurrenceID);
                            ngo.GroupID = go.GroupID;
                            ngo.Save(CurrentUser.Identity.Name);
                        }
                    }

                    //
                    // Close the old occurrence.
                    //
                    oldOccurrence.OccurrenceClosed = true;
                    oldOccurrence.Save(CurrentUser.Identity.Name);
                }
                catch
                {
                }
            }

            btnCloseCancel_Click(sender, e);
        }
Пример #4
0
        /// <summary>
        /// Process a single small group. Determine if the small group leader has taken
        /// attendance for their last small group and if not send the leader (and
        /// optionally assistant-leaders) an e-mail to remind them.
        /// </summary>
        /// <param name="group">The small group to check attendance for.</param>
        /// <returns>True/false status indicating if a fatal error occurred.</returns>
        Boolean ProcessGroup(Group group)
        {
            GroupOccurrence occurrence = null;
            DayOfWeek       dow;
            DateTime        meetingDate;


            //
            // If this small group is not active, ignore it.
            //
            if (group.Active == false)
            {
                return(true);
            }

            //
            // If they have limited the cluster types and this cluster type is not in
            // the list of valid cluster types, then skip it.
            //
            if (Topics.Length > 0 && Topics.Contains(group.Topic.LookupID) == false)
            {
                return(true);
            }

            //
            // Determine the meeting day of the week.
            //
            if (group.MeetingDay == null)
            {
                return(true);
            }
            if (group.MeetingDay.Value.Equals("Sunday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Sunday;
            }
            else if (group.MeetingDay.Value.Equals("Monday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Monday;
            }
            else if (group.MeetingDay.Value.Equals("Tuesday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Tuesday;
            }
            else if (group.MeetingDay.Value.Equals("Wednesday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Wednesday;
            }
            else if (group.MeetingDay.Value.Equals("Thursday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Thursday;
            }
            else if (group.MeetingDay.Value.Equals("Friday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Friday;
            }
            else if (group.MeetingDay.Value.Equals("Saturday", StringComparison.CurrentCultureIgnoreCase))
            {
                dow = DayOfWeek.Saturday;
            }
            else
            {
                if (Debug)
                {
                    _message.AppendFormat("Could not determine meeting day of week for small group {0}, value was '{1}'<br />", group.Name, group.MeetingDay.Value);
                }

                return(true);
            }

            //
            // Walk backwards from today. We don't consider "today" a valid day
            // so start on the previous day.
            //
            for (DateTime dt = DateTime.Now.AddDays(-1); ; dt = dt.AddDays(-1))
            {
                if (dt.DayOfWeek == dow)
                {
                    meetingDate = dt;
                    break;
                }
            }

            //
            // Find the existing occurrence for this group.
            //
            foreach (GroupOccurrence occ in group.Occurrences)
            {
                //
                // The occurrence must match the date portion of the expected meeting date.
                //
                if (occ.StartTime.Year == meetingDate.Year && occ.StartTime.Month == meetingDate.Month &&
                    occ.StartTime.Day == meetingDate.Day)
                {
                    occurrence = occ;
                    break;
                }
            }

            //
            // If the occurrence already has attendance taken, then they are all good.
            //
            if (occurrence != null && occurrence.Attendance > 0)
            {
                if (Debug)
                {
                    _message.AppendFormat("Small group '{0}' has already taken attendance on '{1}'.<br />", group.Name, occurrence.StartTime.ToShortDateString());
                }

                return(true);
            }

            //
            // Make sure the grace period has passed.
            //
            DateTime a, b;

            a           = DateTime.Now.AddDays(-(GracePeriod + 1));
            b           = DateTime.Now.AddDays(-GracePeriod);
            meetingDate = new DateTime(meetingDate.Year, meetingDate.Month, meetingDate.Day, 23, 59, 59);
            if (meetingDate.CompareTo(a) > 0 &&
                meetingDate.CompareTo(b) < 0)
            {
                List <Person> leaders = new List <Person>();

                //
                // Add the primary group leader to the list.
                //
                leaders.Add(group.Leader);

                //
                // Make a list of all the assistant leaders.
                //
                if (AssistantLeaderRoles.Length > 0)
                {
                    foreach (GroupMember gm in group.Members)
                    {
                        if (gm.Active && AssistantLeaderRoles.Contains(gm.Role.LookupID))
                        {
                            leaders.Add(gm);
                        }
                    }
                }

                //
                // Send an e-mail to each person in the list.
                //
                foreach (Person leader in leaders)
                {
                    AttendanceReminder          reminder = new AttendanceReminder();
                    Dictionary <string, string> fields   = new Dictionary <string, string>();

                    _message.AppendFormat("Sending e-mail to leader '{1}' of Small Group '{0}' which meets on {2}<br />", new object[] { group.Name, leader.FullName, group.MeetingDay.Value });

                    reminder.LoadFields(fields, leader, group);

                    //
                    // Send an e-mail to the first active e-mail address the leader has.
                    //
                    foreach (PersonEmail email in leader.Emails)
                    {
                        if (email.Active)
                        {
                            //
                            // Send the e-mail and then stop looking for a valid e-mail address.
                            //
                            reminder.Send(email.Email, fields);

                            break;
                        }
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Map an Arena group occurrence to a SmallGroupOccurance Contract
        /// </summary>
        /// <param name="arena">The Occurrence from arena</param>
        /// <returns>A new SmallGroupOccurance</returns>
        public SmallGroupOccurrence FromArena(GroupOccurrence arena)
        {
            SmallGroupOccurrence occurrence = new SmallGroupOccurrence();
            occurrence.OccurrenceID = arena.OccurrenceID;
            occurrence.Name = arena.Name;
            occurrence.Start = arena.StartTime;
            occurrence.End = arena.EndTime;
            occurrence.Description = arena.Description;
            occurrence.Attendees = new List<GenericReference>();
            foreach (var attender in arena.OccurrenceAttendances)
            {
                if (attender.Attended)
                {
                    GenericReference person = new GenericReference(attender.Person);
                    occurrence.Attendees.Add(person);
                }
            }

            return occurrence;
        }
        /// <summary>
        /// Updates an existing Small Group Occurrence
        /// </summary>
        /// <param name="id">The GroupId</param>
        /// <param name="occurrence">The occurrence.</param>
        /// <returns>A ModifyResult object that indicates success or failure of the call.</returns>
        internal Services.Contracts.ModifyResult Update( int id, SmallGroupOccurrence occurrence )
        {
            GroupOccurrence arenaOccurrence = new GroupOccurrence( occurrence.OccurrenceID );
            Services.Contracts.ModifyResult result = new Services.Contracts.ModifyResult();

            if ( arenaOccurrence.GroupID <= 0 )
            {
                result.Successful = "False";
                result.ErrorMessage = "Occurrence was not found.";
            }
            if ( arenaOccurrence.GroupID != id )
            {
                result.Successful = "False";
                result.ErrorMessage = "Occurrence does not belong to the current group.";
                return result;
            }

            arenaOccurrence.Name = occurrence.Name;
            arenaOccurrence.Description = occurrence.Description;
            arenaOccurrence.StartTime = occurrence.Start;
            arenaOccurrence.EndTime = occurrence.End;

            arenaOccurrence.Save( ArenaContext.Current.User.Identity.Name );

            var didNotAttend = arenaOccurrence.OccurrenceAttendances.Attendees
                        .Where( a => a.Attended )
                        .Where( a => !occurrence.Attendees.Select( oa => oa.ID ).Contains( a.PersonID ) )
                        .Select( a => a.PersonID ).ToList();

            var attendeesToAdd = occurrence.Attendees.Where( a => !arenaOccurrence.OccurrenceAttendances.Attendees.Where( aa => aa.Attended )
                                                            .Select( aa => aa.PersonID ).Contains( a.ID ) )
                                                .Select( a => a.ID );

            foreach ( var nonAttendeePersonId in didNotAttend )
            {
                var notTheAttendee = arenaOccurrence.OccurrenceAttendances.Where( a => a.PersonID == nonAttendeePersonId ).FirstOrDefault();

                notTheAttendee.Attended = false;
                notTheAttendee.Save( ArenaContext.Current.User.Identity.Name );
            }

            foreach ( var attendeePersonId in attendeesToAdd )
            {
                var attendee = arenaOccurrence.OccurrenceAttendances.Where( a => a.PersonID == attendeePersonId ).FirstOrDefault();

                if ( attendee != null )
                {
                    attendee.Attended = true;
                }
                else
                {
                    attendee = new OccurrenceAttendance();
                    attendee.OccurrenceID = arenaOccurrence.OccurrenceID;
                    attendee.PersonID = attendeePersonId;
                    attendee.Attended = true;
                }

                attendee.Save( ArenaContext.Current.User.Identity.Name );

            }

            result.Successful = "True";
            return result;
        }
        /// <summary>
        /// Creates a new Small Group Occurrence
        /// </summary>
        /// <param name="id">The GroupId.</param>
        /// <param name="occurrence">The occurrence.</param>
        /// <returns></returns>
        internal Services.Contracts.ModifyResult Create( int id, SmallGroupOccurrence occurrence )
        {
            Services.Contracts.ModifyResult result = new Services.Contracts.ModifyResult();
            Group group = new Group( id );

            if ( group.GroupID <= 0 )
            {
                result.Successful = "False";
                result.ErrorMessage = "Group not found.";
            }

            DayOfWeek todayDOW = DateTime.Now.DayOfWeek;
            DayOfWeek meetingDOW = DayOfWeek.Sunday;

            if ( occurrence.Start == new DateTime( 1900, 1, 1 ) || occurrence.Start == DateTime.MinValue )
            {
                switch ( group.MeetingDay.Value.ToLower() )
                {
                    case "sunday":
                        meetingDOW = DayOfWeek.Sunday;
                        break;
                    case "monday":
                        meetingDOW = DayOfWeek.Monday;
                        break;
                    case "tuesday":
                        meetingDOW = DayOfWeek.Tuesday;
                        break;
                    case "wednesday":
                        meetingDOW = DayOfWeek.Wednesday;
                        break;
                    case "thursday":
                        meetingDOW = DayOfWeek.Thursday;
                        break;
                    case "friday":
                        meetingDOW = DayOfWeek.Friday;
                        break;
                    case "saturday":
                        meetingDOW = DayOfWeek.Saturday;
                        break;
                    default:
                        result.Successful = "False";
                        result.ErrorMessage = "Meeting Date was not provided and could not be determined from the group";
                        return result;
                }

                if ( meetingDOW <= todayDOW )
                {
                    //if meeting day for this week is the current day or a day in the past assume this week's meeting
                    occurrence.Start = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, group.MeetingStartTime.Hour, group.MeetingStartTime.Minute, group.MeetingStartTime.Second )
                        .AddDays( -( todayDOW - meetingDOW ) );
                }
                else
                {
                    //if meeting day has not occurred yet assume last week's meeting.
                    int daysToSubtract = 7 - meetingDOW - todayDOW;
                    occurrence.Start = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, group.MeetingStartTime.Hour, group.MeetingStartTime.Minute, group.MeetingStartTime.Second )
                        .AddDays( -daysToSubtract );
                }

                occurrence.End = new DateTime( occurrence.Start.Year, occurrence.Start.Month, occurrence.Start.Day, group.MeetingEndTime.Hour, group.MeetingEndTime.Minute, group.MeetingEndTime.Second );

            }

            if ( group.Occurrences.Where( o => o.StartTime.Date == occurrence.Start.Date ).Count() > 0 )
            {
                result.Successful = "False";
                result.ErrorMessage = string.Format( "Could not create an occurrence.  An occurrence already exists for {0}", occurrence.Start.Date );
                return result;
            }

            GroupOccurrence arenaOccurrence = new GroupOccurrence();
            if ( String.IsNullOrWhiteSpace( occurrence.Name ) )
            {
                arenaOccurrence.Name = string.Format( "{0} Occurrence", group.Name );
            }
            else
            {
                arenaOccurrence.Name = occurrence.Name;
            }

            arenaOccurrence.GroupID = group.GroupID;
            arenaOccurrence.OccurrenceTypeID = 230;
            arenaOccurrence.CheckInStart = new DateTime( 1900, 1, 1 );
            arenaOccurrence.CheckInEnd = new DateTime( 1900, 1, 1 );
            arenaOccurrence.StartTime = occurrence.Start;
            arenaOccurrence.EndTime = occurrence.End;
            //arenaOccurrence.Description = "Occurrence";
            arenaOccurrence.MembershipRequired = false;

            arenaOccurrence.Save( ArenaContext.Current.User.Identity.Name );

            foreach ( var a in occurrence.Attendees )
            {
                OccurrenceAttendance attendance = new OccurrenceAttendance();
                attendance.OccurrenceID = arenaOccurrence.OccurrenceID;
                attendance.PersonID = a.ID;
                attendance.Attended = true;
                attendance.Save( ArenaContext.Current.User.Identity.Name );
            }

            result.Successful = "True";
            return result;
        }
Пример #8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            GroupOccurrence occurrence = FindOccurrenceByDate(group.Occurrences, groupDate);

            if (occurrence == null)
            {
                occurrence                  = new GroupOccurrence();
                occurrence.GroupID          = group.GroupID;
                occurrence.OccurrenceID     = -1;
                occurrence.OccurrenceTypeID = Convert.ToInt32(OccurrenceTypeSetting);
                occurrence.Name             = group.Title;
                occurrence.StartTime        = groupDate;
                occurrence.EndTime          = groupDate;
                group.Occurrences.Add(occurrence);
            }

            occurrence.OccurrenceClosed = cbNoMeet.Checked;
            occurrence.Save(CurrentUser.Identity.Name);

            if (occurrence.OccurrenceClosed)
            {
                foreach (OccurrenceAttendance attendance in occurrence.OccurrenceAttendances)
                {
                    attendance.Delete();
                }
            }
            else
            {
                foreach (ListViewDataItem item in lvMembers.Items)
                {
                    CheckBox cb = (CheckBox)item.FindControl("cbMember");
                    if (cb != null)
                    {
                        int personId = Int32.Parse(cb.Attributes["memberid"]);
                        OccurrenceAttendance attendance = new OccurrenceAttendance(occurrence.OccurrenceID, personId);
                        attendance.OccurrenceID = occurrence.OccurrenceID;
                        attendance.PersonID     = personId;
                        attendance.Attended     = cb.Checked;

                        if (attendance.Attended)
                        {
                            attendance.Save(CurrentUser.Identity.Name);
                        }
                        else
                        {
                            if (attendance.OccurrenceAttendanceID != -1)
                            {
                                if (attendance.PersonID == -1 || attendance.Notes == string.Empty)
                                {
                                    attendance.Delete();
                                }
                                else
                                {
                                    attendance.Save(CurrentUser.Identity.Name);
                                }
                            }
                        }
                    }
                }
            }

            ShowMessage(string.Format("Attendance has been saved for {0}", groupDate.ToLongDateString()), false);

            ShowAttendance();
        }
        /// <summary>
        /// Generate a new occurrence in the database from the values given
        /// in the parameters.
        /// </summary>
        /// <param name="type">The OccurrenceType to use for this occurrence.</param>
        /// <param name="profileID">The profile to associate the occurrence with if it is not already linked in the occurrence type.</param>
        /// <param name="forceProfile">Force the occurrence to be associated with the profileID given.</param>
        /// <param name="name">The name of the occurrence.</param>
        /// <param name="location">The Location object to use for check-in.</param>
        /// <param name="startTime">The time the occurrence should start.</param>
        /// <param name="endTime">The time the occurrence should end.</param>
        /// <param name="checkinStart">The time that check-in should start.</param>
        /// <param name="checkinEnd">The time that check-in should end.</param>
        /// <param name="membershipRequired">If the membership required flag on the occurrence should be set.</param>
        /// <returns>The ID number of the new occurrence that was generated.</returns>
        private Int32 CreateOccurrence(OccurrenceType type, int profileID, Boolean forceProfile, String name, Location location, DateTime startTime, DateTime endTime, DateTime checkinStart, DateTime checkinEnd, Boolean membershipRequired)
        {
            Occurrence occurrence = null;


            //
            // Allow the occurrence to override if forceProfile is not true.
            //
            if (forceProfile == false)
            {
                if (type.SyncWithProfile != -1)
                {
                    profileID = type.SyncWithProfile;
                }
                if (type.SyncWithGroup != -1)
                {
                    profileID = -1;
                }
            }

            //
            // Create the appropriate type of occurrence object.
            //
            if (profileID != -1)
            {
                ProfileOccurrence pOccurrence = new ProfileOccurrence();

                pOccurrence.ProfileID = profileID;

                occurrence = pOccurrence;
            }
            else if (type.SyncWithGroup != -1)
            {
                GroupOccurrence gOccurrence = new GroupOccurrence();

                gOccurrence.GroupID = type.SyncWithGroup;

                occurrence = gOccurrence;
            }
            else
            {
                throw new ArgumentException("Occurrences must be tied to either a tag or group.");
            }

            //
            // Set all the common information.
            //
            occurrence.OccurrenceID       = -1;
            occurrence.OccurrenceType     = type;
            occurrence.Name               = name;
            occurrence.Location           = location.FullName;
            occurrence.LocationID         = location.LocationId;
            occurrence.Description        = "";
            occurrence.StartTime          = startTime;
            occurrence.EndTime            = endTime;
            occurrence.CheckInStart       = checkinStart;
            occurrence.CheckInEnd         = checkinEnd;
            occurrence.MembershipRequired = membershipRequired;

            //
            // Save the new occurrence.
            //
            occurrence.Save(CurrentUser.Identity.Name);

            return(occurrence.OccurrenceID);
        }
Пример #10
0
        /// <summary>
        /// Updates an existing Small Group Occurrence
        /// </summary>
        /// <param name="id">The GroupId</param>
        /// <param name="occurrence">The occurrence.</param>
        /// <returns>A ModifyResult object that indicates success or failure of the call.</returns>
        internal Services.Contracts.ModifyResult Update(int id, SmallGroupOccurrence occurrence)
        {
            GroupOccurrence arenaOccurrence = new GroupOccurrence(occurrence.OccurrenceID);

            Services.Contracts.ModifyResult result = new Services.Contracts.ModifyResult();

            if (arenaOccurrence.GroupID <= 0)
            {
                result.Successful   = "False";
                result.ErrorMessage = "Occurrence was not found.";
            }
            if (arenaOccurrence.GroupID != id)
            {
                result.Successful   = "False";
                result.ErrorMessage = "Occurrence does not belong to the current group.";
                return(result);
            }

            arenaOccurrence.Name        = occurrence.Name;
            arenaOccurrence.Description = occurrence.Description;
            arenaOccurrence.StartTime   = occurrence.Start;
            arenaOccurrence.EndTime     = occurrence.End;

            arenaOccurrence.Save(ArenaContext.Current.User.Identity.Name);

            var didNotAttend = arenaOccurrence.OccurrenceAttendances.Attendees
                               .Where(a => a.Attended)
                               .Where(a => !occurrence.Attendees.Select(oa => oa.ID).Contains(a.PersonID))
                               .Select(a => a.PersonID).ToList();

            var attendeesToAdd = occurrence.Attendees.Where(a => !arenaOccurrence.OccurrenceAttendances.Attendees.Where(aa => aa.Attended)
                                                            .Select(aa => aa.PersonID).Contains(a.ID))
                                 .Select(a => a.ID);


            foreach (var nonAttendeePersonId in didNotAttend)
            {
                var notTheAttendee = arenaOccurrence.OccurrenceAttendances.Where(a => a.PersonID == nonAttendeePersonId).FirstOrDefault();

                notTheAttendee.Attended = false;
                notTheAttendee.Save(ArenaContext.Current.User.Identity.Name);
            }

            foreach (var attendeePersonId in attendeesToAdd)
            {
                var attendee = arenaOccurrence.OccurrenceAttendances.Where(a => a.PersonID == attendeePersonId).FirstOrDefault();

                if (attendee != null)
                {
                    attendee.Attended = true;
                }
                else
                {
                    attendee = new OccurrenceAttendance();
                    attendee.OccurrenceID = arenaOccurrence.OccurrenceID;
                    attendee.PersonID     = attendeePersonId;
                    attendee.Attended     = true;
                }

                attendee.Save(ArenaContext.Current.User.Identity.Name);
            }

            result.Successful = "True";
            return(result);
        }
Пример #11
0
        /// <summary>
        /// Creates a new Small Group Occurrence
        /// </summary>
        /// <param name="id">The GroupId.</param>
        /// <param name="occurrence">The occurrence.</param>
        /// <returns></returns>
        internal Services.Contracts.ModifyResult Create(int id, SmallGroupOccurrence occurrence)
        {
            Services.Contracts.ModifyResult result = new Services.Contracts.ModifyResult();
            Group group = new Group(id);

            if (group.GroupID <= 0)
            {
                result.Successful   = "False";
                result.ErrorMessage = "Group not found.";
            }

            DayOfWeek todayDOW   = DateTime.Now.DayOfWeek;
            DayOfWeek meetingDOW = DayOfWeek.Sunday;

            if (occurrence.Start == new DateTime(1900, 1, 1) || occurrence.Start == DateTime.MinValue)
            {
                switch (group.MeetingDay.Value.ToLower())
                {
                case "sunday":
                    meetingDOW = DayOfWeek.Sunday;
                    break;

                case "monday":
                    meetingDOW = DayOfWeek.Monday;
                    break;

                case "tuesday":
                    meetingDOW = DayOfWeek.Tuesday;
                    break;

                case "wednesday":
                    meetingDOW = DayOfWeek.Wednesday;
                    break;

                case "thursday":
                    meetingDOW = DayOfWeek.Thursday;
                    break;

                case "friday":
                    meetingDOW = DayOfWeek.Friday;
                    break;

                case "saturday":
                    meetingDOW = DayOfWeek.Saturday;
                    break;

                default:
                    result.Successful   = "False";
                    result.ErrorMessage = "Meeting Date was not provided and could not be determined from the group";
                    return(result);
                }

                if (meetingDOW <= todayDOW)
                {
                    //if meeting day for this week is the current day or a day in the past assume this week's meeting
                    occurrence.Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, group.MeetingStartTime.Hour, group.MeetingStartTime.Minute, group.MeetingStartTime.Second)
                                       .AddDays(-(todayDOW - meetingDOW));
                }
                else
                {
                    //if meeting day has not occurred yet assume last week's meeting.
                    int daysToSubtract = 7 - meetingDOW - todayDOW;
                    occurrence.Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, group.MeetingStartTime.Hour, group.MeetingStartTime.Minute, group.MeetingStartTime.Second)
                                       .AddDays(-daysToSubtract);
                }

                occurrence.End = new DateTime(occurrence.Start.Year, occurrence.Start.Month, occurrence.Start.Day, group.MeetingEndTime.Hour, group.MeetingEndTime.Minute, group.MeetingEndTime.Second);
            }

            if (group.Occurrences.Where(o => o.StartTime.Date == occurrence.Start.Date).Count() > 0)
            {
                result.Successful   = "False";
                result.ErrorMessage = string.Format("Could not create an occurrence.  An occurrence already exists for {0}", occurrence.Start.Date);
                return(result);
            }

            GroupOccurrence arenaOccurrence = new GroupOccurrence();

            if (String.IsNullOrWhiteSpace(occurrence.Name))
            {
                arenaOccurrence.Name = string.Format("{0} Occurrence", group.Name);
            }
            else
            {
                arenaOccurrence.Name = occurrence.Name;
            }

            arenaOccurrence.GroupID          = group.GroupID;
            arenaOccurrence.OccurrenceTypeID = 230;
            arenaOccurrence.CheckInStart     = new DateTime(1900, 1, 1);
            arenaOccurrence.CheckInEnd       = new DateTime(1900, 1, 1);
            arenaOccurrence.StartTime        = occurrence.Start;
            arenaOccurrence.EndTime          = occurrence.End;
            //arenaOccurrence.Description = "Occurrence";
            arenaOccurrence.MembershipRequired = false;

            arenaOccurrence.Save(ArenaContext.Current.User.Identity.Name);

            foreach (var a in occurrence.Attendees)
            {
                OccurrenceAttendance attendance = new OccurrenceAttendance();
                attendance.OccurrenceID = arenaOccurrence.OccurrenceID;
                attendance.PersonID     = a.ID;
                attendance.Attended     = true;
                attendance.Save(ArenaContext.Current.User.Identity.Name);
            }

            result.Successful = "True";
            return(result);
        }
Пример #12
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            GroupOccurrence occurrence = null;
            int             headCount  = Convert.ToInt32(tbHeadCount.Text);
            string          note       = tbNote.Text;

            if (ViewState["OccurrenceID"] != null)
            {
                occurrence = new GroupOccurrence((int)ViewState["OccurrenceID"]);
                if (occurrence.StartTime.Date != dtDate.SelectedDate)
                {
                    occurrence = null;
                }
            }

            if (occurrence == null)
            {
                occurrence                  = new GroupOccurrence();
                occurrence.GroupID          = group.GroupID;
                occurrence.OccurrenceID     = -1;
                occurrence.OccurrenceTypeID = Convert.ToInt32(OccurrenceTypeSetting);
                occurrence.Name             = OccurrenceNameSetting;
                occurrence.StartTime        = dtDate.SelectedDate;
                occurrence.EndTime          = dtDate.SelectedDate;
                occurrence.HeadCount        = headCount;
                occurrence.Description      = note;
                occurrence.Save(CurrentUser.Identity.Name);
            }

            foreach (ListItem li in cblAttendees.Items)
            {
                OccurrenceAttendance attendance = new OccurrenceAttendance(occurrence.OccurrenceID, Convert.ToInt32(li.Value));
                attendance.OccurrenceID = occurrence.OccurrenceID;
                attendance.PersonID     = Convert.ToInt32(li.Value);
                attendance.Attended     = li.Selected;

                if (attendance.Attended)
                {
                    attendance.Save(CurrentUser.Identity.Name);
                }
                else
                {
                    if (attendance.OccurrenceAttendanceID != -1)
                    {
                        if (attendance.PersonID == -1 || attendance.Notes == string.Empty)
                        {
                            attendance.Delete();
                        }
                        else
                        {
                            attendance.Save(CurrentUser.Identity.Name);
                        }
                    }
                }
            }

            occurrence.HeadCount   = headCount;
            occurrence.Description = note;
            occurrence.Save(CurrentUser.Identity.Name);

            occurrence = null;
            ShowAttendance(occurrence);

            ShowOccurrences();

            if (RedirectPageIDSetting != "")
            {
                string URLGroupID = Request.Params["group"];
                Response.Redirect(string.Format("default.aspx?page={0}&group={1}", RedirectPageIDSetting, URLGroupID));
            }
        }