示例#1
0
        private SalesPersonAndGroup GetChosenSalesPerson(SalesPersonRequest salesPersonRequest)
        {
            SalesPersonAndGroup chosenperson = null;
            Random rand = new Random();
            // Linq will get excuted only when accessed. No need to
            List <SalesPersonAndGroup> anySalesPerson           = SalesPeopleData.SalesPeopleInfo;
            List <SalesPersonAndGroup> personsSpecialisingInCar =
                SalesPeopleData.SalesPeopleInfo.FindAll(x => x.Groups.Any(x => x == salesPersonRequest.CarType));
            List <SalesPersonAndGroup> personsSpecialisingInLangAndCar =
                SalesPeopleData.SalesPeopleInfo.FindAll(x =>
                                                        x.Groups.Any(x => x == salesPersonRequest.Language) &&
                                                        x.Groups.Any(x => x == salesPersonRequest.CarType));


            if (personsSpecialisingInLangAndCar.Count >= 1)
            {
                chosenperson = GetSaleSPersonAtRandom(rand, personsSpecialisingInLangAndCar);
            }
            else if (personsSpecialisingInCar.Count >= 1)
            {
                chosenperson = GetSaleSPersonAtRandom(rand, personsSpecialisingInCar);
            }
            else if (anySalesPerson.Count > 1)
            {
                chosenperson = GetSaleSPersonAtRandom(rand, anySalesPerson);
            }
            else
            {
                throw new Exception("Possibly no sales person DATA INPUT");
            }
            return(chosenperson);
        }
示例#2
0
        public AssignedSalesPerson AssignTheMostSuitableSalesPerson(SalesPersonRequest salesPersonRequest)
        {
            ValidateRequest(salesPersonRequest);
            SalesPersonAndGroup chosenperson = GetChosenSalesPerson(salesPersonRequest);

            // we want to send sepaciality descriptions not just code
            return(ParseToAssignedSalesPerson(chosenperson));;
        }
示例#3
0
        private AssignedSalesPerson ParseToAssignedSalesPerson(SalesPersonAndGroup chosenperson)
        {
            AssignedSalesPerson assignedSalesPerson = new AssignedSalesPerson();

            assignedSalesPerson.SalesPersonName = chosenperson.Name;
            foreach (var g in chosenperson.Groups)
            {
                var f = SalesPersonSpeciality.Groups.FirstOrDefault(x => x.GroupName == g);
                if (f != null)
                {
                    assignedSalesPerson.SpecialityList.Add(f.GroupDescription);                    //
                }
            }

            return(assignedSalesPerson);
        }