public ParticipantIndexViewModel GenreateParticipantIndexViewModel(List <Participant> participants)
        {
            ParticipantIndexViewModel vm = new ParticipantIndexViewModel();

            foreach (var participant in participants)
            {
                var EventName = _context
                                .Events
                                .Where(e => e.Id == participant.EventCategory.Event.Id)
                                .Select(e => e.EventName)
                                .FirstOrDefault();

                vm.Participants.Add(new ParticipantViewModel(participant.FirstName, participant.LastName, participant.EventCategory.Category, EventName, participant.Gender, participant.paid, participant.Id));
            }

            return(vm);
        }
        public ActionResult Index(ParticipantIndexViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", vm.AddParticipant));
            }
            else
            {
                if (!CheckIfParticipantCanParticipateInCategory(vm))
                {
                    return(RedirectToAction("Index", vm.AddParticipant));
                }
            }
            var userId     = User.Identity.GetUserId();
            var categoryId = _unitOfWork.Category.GetCategoryIdByName(vm.AddParticipant.AgeGroup);

            // add participant to event and save if successful

            if (_unitOfWork.Participants.AddParticipant(userId, categoryId, vm.AddParticipant))
            {
                _unitOfWork.Complete();
            }
            return(RedirectToAction("Index"));
        }
        // method to check if user's age qualifies with age group in which they want to participate in
        public bool CheckIfParticipantCanParticipateInCategory(ParticipantIndexViewModel vm)
        {
            var today = DateTime.UtcNow;
            var age   = today.Year - vm.AddParticipant.DOB.Year;

            if (today < vm.AddParticipant.DOB.AddYears(age))
            {
                age--;
            }

            if (vm.AddParticipant.Gender == Models.Gender.Female)
            {
                switch (vm.AddParticipant.AgeGroup)
                {
                case Models.AgeGroup.BabyMiss:
                    if (age < 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.PeeWeeMiss:
                    if (age < 2 && age >= 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.TinyMiss:
                    if (age <= 3 && age >= 2)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.LittleMiss:
                    if (age <= 5 && age >= 4)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.PetiteMiss:
                    if (age <= 8 && age >= 6)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.YouthMiss:
                    if (age <= 12 && age >= 9)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.TeenMiss:
                    if (age <= 15 && age >= 13)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                default:
                    return(false);
                }
            }
            else
            {
                switch (vm.AddParticipant.AgeGroup)
                {
                case Models.AgeGroup.BabyMr:
                    if (age < 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.PeeWeeMr:
                    if (age < 2 && age >= 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.TinyMr:
                    if (age <= 3 && age >= 2)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case Models.AgeGroup.LittleMr:
                    if (age <= 5 && age >= 4)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                default:
                    return(false);
                }
            }
        }