示例#1
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);
        }
        /// <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;
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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));
            }
        }