コード例 #1
0
        private void UpdateVolunteerPositions(VolunteerProfile volunteer)
        {
            // clear out all current preferences for this volunteer
            List <PositionVolunteer> oldPositions = _context.PositionVolunteers
                                                    .Where(p => p.Volunteer == volunteer).ToList();

            _context.PositionVolunteers.RemoveRange(oldPositions);

            // load new position selection into volunteerprofile
            volunteer.Positions = new List <PositionVolunteer>();

            // iterate through all positions (via model property that contains every selectable position)
            foreach (Position position in Positions)
            {
                // prepare an entity to be added to the volunteer's list of positions
                PositionVolunteer posVol = new PositionVolunteer()
                {
                    Volunteer = volunteer,
                    Position  = position,
                };

                // for each position, check to see if it was selected as a preferred position or an assigned position
                var preferred = Request.Form["preferred-" + position.Name];
                var assigned  = Request.Form["assigned-" + position.Name];

                bool selectedAsPreferredPosition = preferred.Count > 0 && assigned.Count == 0;
                bool selectedAsAssignedPosition  = preferred.Count == 0 && assigned.Count > 0;
                bool selectedAsBoth = preferred.Count > 0 && assigned.Count > 0;

                if (selectedAsPreferredPosition)
                {
                    posVol.Association = PositionVolunteer.AssociationType.Preferred;
                    volunteer.Positions.Add(posVol);
                }
                else if (selectedAsAssignedPosition)
                {
                    posVol.Association = PositionVolunteer.AssociationType.Assigned;
                    volunteer.Positions.Add(posVol);
                }
                else if (selectedAsBoth)
                {
                    posVol.Association = PositionVolunteer.AssociationType.PreferredAndAssigned;
                    volunteer.Positions.Add(posVol);
                }
            }
        }
コード例 #2
0
        private void FillPreferredPositions(VolunteerProfile volunteer)
        {
            // clear out all current preferences for this volunteer
            List <PositionVolunteer> oldPositions = _context.PositionVolunteers
                                                    .Where(p => p.Volunteer == volunteer).ToList();

            _context.PositionVolunteers.RemoveRange(oldPositions);
            volunteer.Positions = new List <PositionVolunteer>();
            foreach (Position position in Positions)
            {
                var preferred = Request.Form["preferred-" + position.Name];
                var assigned  = Request.Form["assigned-" + position.Name];

                PositionVolunteer posVol = new PositionVolunteer()
                {
                    Volunteer = volunteer,
                    Position  = position,
                };

                // this means it was preferred, StringValues are weird
                if (preferred.Count > 0 && assigned.Count == 0)
                {
                    posVol.Association = PositionVolunteer.AssociationType.Preferred;
                    volunteer.Positions.Add(posVol);
                }
                // this means it was assigned
                else if (preferred.Count == 0 && assigned.Count > 0)
                {
                    posVol.Association = PositionVolunteer.AssociationType.Assigned;
                    volunteer.Positions.Add(posVol);
                }
                // this means it was both
                else if (preferred.Count > 0 && assigned.Count > 0)
                {
                    posVol.Association = PositionVolunteer.AssociationType.PreferredAndAssigned;
                    volunteer.Positions.Add(posVol);
                }
            }
        }
コード例 #3
0
        private List <PositionVolunteer> AssignPreferredPositions(VolunteerProfile volunteer)
        {
            List <PositionVolunteer> volunteerPositions = new List <PositionVolunteer>();

            foreach (Position position in Positions)
            {
                var positionWasSelected = Request.Form[position.Name];

                // this means it was selected, StringValues are weird
                if (positionWasSelected.Count > 0)
                {
                    PositionVolunteer posVol = new PositionVolunteer()
                    {
                        Volunteer   = volunteer,
                        Position    = position,
                        Association = PositionVolunteer.AssociationType.Preferred
                    };
                    volunteerPositions.Add(posVol);
                }
            }

            return(volunteerPositions);
        }