Beispiel #1
0
        public void updateNanny(BE.Nanny nanny)
        {
            string str      = "";
            double distance = 0;
            Thread thread   = new Thread(() => distance = GoogleApiFunc.CalcDistance(nanny.address,
                                                                                     nanniesList().First(x => x.id == nanny.id).address,
                                                                                     TravelType.Walking));

            thread.Start();
            thread.Join();

            if (distance > 1000)
            {
                str += "update succseed but you have to update all the mother about your new address";
            }


            try
            {
                dal.updateNanny(nanny);
                if (str != "")
                {
                    throw new Exception(str);
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        public List <BE.Nanny> bestNannies(BE.Mother mother)
        {
            List <BE.Nanny> nannies = new List <BE.Nanny>();

            if (listOfMatchingNannies(mother).Count > 5)
            {
                nannies = listOfMatchingNannies(mother);
            }
            else
            {
                nannies = bestDefaultsNannies(mother);
            }

            double[] distances = new double[nannies.Count];
            int      i         = 0;
            Thread   thread;

            ///<object contains nanny with her distance to mother/>
            foreach (var nanny in nannies)
            {
                double distance = 0;
                thread = new Thread(() => distance = GoogleApiFunc.CalcDistance(nanny.address, mother.address, TravelType.Walking));
                thread.Start();
                thread.Join();
                distances[i++] = distance;
            }
            i = 0;
            var nanniesDistance = from nanny in nannies
                                  select new
            {
                thisNanny = nanny,
                distance  = distances[i++]
            };
            var nanniesdistance = nanniesDistance.ToList();

            nannies = new List <BE.Nanny>();

            nanniesdistance.Sort((x, y) => x.distance.CompareTo(y.distance));

            foreach (var item in nanniesdistance)
            {
                nannies.Add(item.thisNanny);
            }

            return(nannies);
        }
Beispiel #3
0
        public IEnumerable <IGrouping <double, BE.Contract> > contractsByDistance(bool sorting = false)
        {
            List <BE.Contract> contracts = contractsList();

            if (sorting)
            {
                contracts.Sort((x, y) =>
                               GoogleApiFunc
                               .CalcDistance(dal.getMotherById(x.motherId).address, dal.GetNannyById(x.nannyId).address,
                                             TravelType.Walking).CompareTo(GoogleApiFunc.CalcDistance(
                                                                               dal.getMotherById(y.motherId).address, dal.GetNannyById(y.nannyId).address,
                                                                               TravelType.Walking)));
            }

            IEnumerable <IGrouping <double, BE.Contract> > query = from contract in contracts
                                                                   group contract by GoogleApiFunc.CalcDistance(dal.getMotherById(contract.motherId).address,
                                                                                                                dal.GetNannyById(contract.nannyId).address, TravelType.Walking) % 5;

            return(query);
        }
Beispiel #4
0
 public double distance(string source, string dest)
 {
     return(GoogleApiFunc.CalcDistance(source, dest, TravelType.Walking));
 }