Beispiel #1
0
        private async Task <double> CalPrice(PriceRequest req)
        {
            var airport = await sql.GetAirports(req.Code[0]);

            var a1 = airport.ElementAt(0);

            airport = await sql.GetAirports(req.Code[1]);

            var a2 = airport.ElementAt(0);;

            GeoCoordinate firstPoint =
                new GeoCoordinate(a1.latitude, a1.longitude);

            GeoCoordinate secondPoint =
                new GeoCoordinate(a2.latitude, a2.longitude);

            var distance = firstPoint.GetDistanceTo(secondPoint);
            var fare     = 0.0;

            distance = distance / 1000.0;

            switch (req.Travellers)
            {
            case "Child":
                fare = 0.25 * distance * (1.0 - 0.33);
                break;

            case "Senior":
                fare = 0.25 * distance * (1.0 - 0.25);
                break;

            case "Infant":
                fare = 0.25 * distance * (1.0 - 0.90);
                break;

            case "Adult":
                fare = 0.25 * distance;
                break;
            }

            return(Math.Round(fare, 2));
        }
Beispiel #2
0
 public async Task <double> GetPrice(int db, [FromBody] PriceRequest req)
 {
     System.Diagnostics.Trace.TraceInformation(JsonConvert.SerializeObject(req));
     return(await CalPrice(req));
 }