Beispiel #1
0
        public async Task <string> CalculateDistance(string Latitude, string Longitude)
        {
            try
            {
                var app = App.Current as App;
                Dictionary <string, object> payload = new Dictionary <string, object>();
                payload.Add("access_key", app.SecurityAccessKey);
                payload.Add("phone_number", app.UserPhoneNumber);
                payload.Add("merchant_id", app.Merchantid);
                payload.Add("latitude", Latitude);
                payload.Add("longitude", Longitude);
                DistanceModel robject = await this.Post <DistanceModel>(this.getAuthUrl("getDistance"), payload, null);

                if (robject.status.ToLower() == "success")
                {
                    return(robject.data.distance);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.Message, "ok");

                return(null);
            }
        }
Beispiel #2
0
        public async Task <DistanceData> CalculateDistance(string Latitude, string Longitude, string Pincode)
        {
            try
            {
                var app = Application.Current as App;
                Dictionary <string, object> payload = new Dictionary <string, object>();
                payload.Add("access_key", app.SecurityAccessKey);
                payload.Add("phone_number", app.UserPhoneNumber);
                payload.Add("merchant_id", app.Merchantid);
                payload.Add("latitude", Latitude);
                payload.Add("pin_code", Pincode);
                payload.Add("longitude", Longitude);
                DistanceModel robject = await this.Post <DistanceModel>(this.getAuthUrl("getDistance"), payload, null);

                if (robject != null)
                {
                    return(robject.data);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                try
                {
                    DependencyService.Get <IToastMessage>().LongTime("Error CSD04:Something went wrong. Plese try again. ");
                }
                catch { }
                return(null);
            }
        }
Beispiel #3
0
        public async Task <DistanceData> SubmitProductDetails(Product NewProduct)
        {
            try
            {
                var app = App.Current as App;
                Dictionary <string, object> payload = new Dictionary <string, object>();
                payload.Add("access_key", app.SecurityAccessKey);
                payload.Add("phone_number", app.UserPhoneNumber);
                payload.Add("merchant_id", app.Merchantid);
                DistanceModel robject = await this.Post <DistanceModel>(this.getAuthUrl("getDistance"), payload, null);

                if (robject.status.ToLower() == "success")
                {
                    return(robject.data);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                try
                {
                    DependencyService.Get <IToastMessage>().LongTime("Error CSD04:Something went wrong. Plese try again. ");
                }
                catch { }
                return(null);
            }
        }
        public void DistanceModelExtensionsClass_ToDistanceMethod_ThrowsArgumentNullException_IfParameterIsNull()
        {
            DistanceModel testObject = null;

            _ = testObject.ToDistance();

            Assert.Fail();
        }
        public void DistanceExtensionsClass_ToYamlDistanceModelMethod_ReturnsObjectWithCorrectChainsProperty_IfParameterIsNotNull()
        {
            Distance testParam = GetTestObject();

            DistanceModel testOutput = testParam.ToYamlDistanceModel();

            Assert.AreEqual(testParam.Chainage, testOutput.Chains);
        }
Beispiel #6
0
        public void DistanceModelExtensionsClass_ToDistanceMethod_ThrowsNullReferenceException_IfParameterIsNull()
        {
            DistanceModel testParam = null;

            testParam.ToDistance();

            Assert.Fail();
        }
        public void DistanceModelExtensionsClassToDistanceMethodReturnsDistanceObjectWithCorrectChainageProperty()
        {
            DistanceModel testObject = GetRandomDistanceModel();

            Distance resultObject = testObject.ToDistance();

            Assert.AreEqual(testObject.Chainage, resultObject.Chainage);
        }
Beispiel #8
0
        public void DistanceModelExtensionsClass_ToDistanceMethod_ReturnsDistanceObjectWithCorrectChainageProperty_IfParameterIsNotNull()
        {
            DistanceModel testParam = _rnd.NextDistanceModel();

            Distance testOutput = testParam.ToDistance();

            Assert.AreEqual(testParam.Chains, testOutput.Chainage);
        }
        public async Task <IActionResult> Distance(string from, string to)
        {
            var result = await _mediator.ExecuteAsync(Scenarios.CalculateDistanceBetweenAirports(from, to));

            if (result.IsSuccess)
            {
                return(DistanceModel.FromResult(result.Data).ToObjectResult());
            }
            return(result.ToObjectResult());
        }
Beispiel #10
0
        public async Task <IActionResult> Distance(int id, int startzip, int endzip)
        {
            DistanceModel dis = (await Utilities.GetApiResponse <DistanceModel>($"rest/distance.json/{startzip:D5}/{endzip:D5}", "mile", "https://redline-redline-zipcode.p.rapidapi.com", "rapidapi-key", RedlineApiKey)).FirstOrDefault();

            if (dis != null)
            {
                ViewBag.Distance = dis.Distance;
            }
            return(RedirectToAction("ViewSingle", new { id = id, distance = dis.Distance }));
        }
Beispiel #11
0
        public void LocationModelExtensionsClassToLocationMethodReturnsObjectWithMileagePropertyWithCorrectChainageProperty()
        {
            DistanceModel testDistanceModelObject = GetRandomDistanceModel();
            LocationModel testObject = new LocationModel {
                Mileage = testDistanceModelObject
            };

            Location result = testObject.ToLocation();

            Assert.AreEqual(testDistanceModelObject.Chainage, result.Mileage.Chainage);
        }
        public void DistanceAPIPostTest()
        {
            LogContext db = new LogContext(new DbContextOptionsBuilder <LogContext>()
                                           .UseInMemoryDatabase(databaseName: "BMIPost")
                                           .Options);
            DistanceController MockDistanceAPI = new DistanceController(db);
            DistanceModel      input           = new DistanceModel(1, 0, 2, 0);
            var response = MockDistanceAPI.Post(input) as ObjectResult;

            Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode);
        }
 /// <summary>
 /// Convert this <see cref="DistanceModel"/> instance into a <see cref="Distance"/> object.
 /// </summary>
 /// <param name="model">The data to be loaded.</param>
 /// <returns>The <see cref="Distance"/> object.</returns>
 public static Distance ToDistance(this DistanceModel model)
 {
     if (model is null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     return(new Distance
     {
         Mileage = model.Mileage,
         Chainage = model.Chainage
     });
 }
Beispiel #14
0
        /// <summary>
        /// Convert a <see cref="DistanceModel" /> instance into a <see cref="Distance" /> instance.
        /// </summary>
        /// <param name="model">The <see cref="DistanceModel" /> instance to be converted.</param>
        /// <returns>A <see cref="Distance" /> instance.</returns>
        /// <exception cref="NullReferenceException">Thrown if the <c>this</c> parameter is <c>null</c>.</exception>
        public static Distance ToDistance(this DistanceModel model)
        {
            if (model is null)
            {
                throw new NullReferenceException();
            }

            return(new Distance
            {
                Mileage = model.Miles,
                Chainage = model.Chains,
            });
        }
        public void DistanceModelExtensionsClass_ToDistanceMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            DistanceModel testObject = null;

            try
            {
                _ = testObject.ToDistance();
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("model", ex.ParamName);
            }
        }
Beispiel #16
0
 public HttpResponseMessage Create([FromBody] DistanceModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetAllErrors()));
         }
         logic.CreateDistance(model);
         return(Request.CreateResponse(HttpStatusCode.Created));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.GetUserFriendlyMessage()));
     }
 }
Beispiel #17
0
        // Will return a null if the Google API is unable to find either post code, or the country constraint fails
        public static string BetweenTwoPostCodes(string postcodeA, string postcodeB, string countryCodeWithin, Units units, string apikey)
        {
            //var ll1 = PostCodeToLongLat(postcodeA, countryCodeWithin);
            //if (!ll1.HasValue) return null;
            //var ll2 = PostCodeToLongLat(postcodeB, countryCodeWithin);
            //if (!ll2.HasValue) return null;
            //return ll1.Value.DistanceTo(ll2.Value, units);

            DistanceModel distanceBetweenPostcodes = new DistanceModel();

            distanceBetweenPostcodes = GetDistanceBetweenTwoPostcodes(postcodeA, postcodeB, units, apikey);
            if (distanceBetweenPostcodes != null)
            {
                return(distanceBetweenPostcodes.rows[0].elements[0].distance.text);
            }

            return(string.Empty);
        }
Beispiel #18
0
        public async Task <DistanceModel> LoadDistance(string origin, string destination)
        {
            string url = $"https://maps.googleapis.com/maps/api/distancematrix/json?origins={origin}&destinations={destination}&key={APIHelper.googleapikey}";

            using (HttpResponseMessage response = await APIHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    DistanceModel distance = await response.Content.ReadAsAsync <DistanceModel>();

                    return(distance);
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
Beispiel #19
0
 internal static extern void alDistanceModel(DistanceModel model);
 private static extern void context_setDistanceModel(IntPtr dm, DistanceModel model, ref IntPtr exceptionPointer);
Beispiel #21
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LocationModel()
 {
     Mileage = new DistanceModel();
 }
Beispiel #22
0
 public static extern void DistanceModel(DistanceModel distanceModel);
Beispiel #23
0
 /// <summary>
 /// 保存数据到数据模型
 /// </summary>
 /// <param name="model">写入数据的目的数据模型,该数据模型不能为空引用</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void Save(DistanceModel model)
 {
     throw new System.NotImplementedException();
 }
Beispiel #24
0
        public IActionResult Post([FromBody] DistanceModel input)
        {
            double response = f.Distance(input.x1, input.y1, input.x2, input.y2, db);

            return(Ok(response));
        }
Beispiel #25
0
 internal static extern void alDistanceModel(DistanceModel model);