Exemple #1
0
 bool belongsToCategory(ChampionshipCategory category, Customer customer, bool isStrict)
 {
     if (isStrict)
     {
         if (category.Category == ChampionshipWinningCategories.Seniorzy)
         {
             return(customer.Birthday.Value.GetAge() >= 14);
         }
         else if (category.Category == ChampionshipWinningCategories.JuniorzyMlodsi)
         {
             return(customer.Birthday.Value.GetAge() >= 14 &&
                    DateTime.Today.Year <= customer.Birthday.Value.AddYears(18).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Juniorzy)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(19).Year&&
                    DateTime.Today.Year <= customer.Birthday.Value.AddYears(23).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani1)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(40).Year&&
                    DateTime.Today.Year <= customer.Birthday.Value.AddYears(49).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani2)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(50).Year&&
                    DateTime.Today.Year <= customer.Birthday.Value.AddYears(59).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani3)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(60).Year&&
                    DateTime.Today.Year <= customer.Birthday.Value.AddYears(69).Year);
         }
         return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(70).Year);
     }
     else
     {
         if (category.Category == ChampionshipWinningCategories.Seniorzy)
         {
             return(customer.Birthday.Value.GetAge() >= 14);
         }
         else if (category.Category == ChampionshipWinningCategories.JuniorzyMlodsi)
         {
             return(customer.Birthday.Value.GetAge() >= 14);
         }
         else if (category.Category == ChampionshipWinningCategories.Juniorzy)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(19).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani1)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(40).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani2)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(50).Year);
         }
         else if (category.Category == ChampionshipWinningCategories.Weterani3)
         {
             return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(60).Year);
         }
         return(DateTime.Today.Year >= customer.Birthday.Value.AddYears(70).Year);
     }
 }
Exemple #2
0
        private IList <ChampionshipCustomer> filterCustomersForCategory(Championship championshipDb, ChampionshipCategory category, IList <ChampionshipCustomer> customers)
        {
            customers = customers.Where(x => x.Type != ChampionshipCustomerType.Disqualified && (!category.IsOfficial || x.Type == ChampionshipCustomerType.Normal) && belongsToCategory(category, x.Customer, category.IsAgeStrict)).ToList();

            if (!category.IsAgeStrict)
            {
                //dla kategorii nie strict musimy sprawdzić czy jesli jest user który niby podpada do tej kategorii ale tylko przez loose to czy istnieje jakas inna kategoria do której pasuje jako strict i jesli tak jest to wywalamy usera z tej kategorii loose.
                //czyli mamy dwie kategorie Weterani1 (40-49) loose i Weterani3 (60-69). Mamy też trzech userów (wiek 41, 51 i 61 lat). W tym przypadku user 41 podpada do Weterani1 (jako strict),
                //user 51 także wpada do weterani1 (jako loose) ale user 61 wpada do weterani3 (jako strict). I wlasnie to wpadnięcie usera 61 do weterani3 a nie do weterani1 jest tutaj sprawdzane
                for (int index = customers.Count - 1; index >= 0; index--)
                {
                    ChampionshipCustomer championshipCustomer = customers[index];
                    var strictCategory = findStrictAgeCategoryForCustomer(championshipCustomer.Customer, championshipDb.Categories);
                    if (strictCategory != null && strictCategory != category)
                    {
                        customers.RemoveAt(index);
                    }
                }
            }
            return(customers);
        }