Example #1
0
        public async Task <object> Measure(Measure measure)
        {
            var email = string.Empty;

            if (HttpContext.User.Identity is ClaimsIdentity identity)
            {
                email = identity.FindFirst(ClaimTypes.Name).Value;
            }

            object result;

            if (!ModelState.IsValid)
            {
                return(new { Error = ModelState.Errors() });;
            }
            result = await distanceMeasureDataProvider.
                     MeasureDistance(measure.Location1, measure.Location2);

            await historyDataProvider.InsertHistory(new RequestHistory()
            {
                Date   = DateTime.Now.ToShortDateString(),
                Mesure = new ViewModel.MeasureViewModel()
                {
                    Location1 = measure.Location1.Lat + "," + measure.Location1.Long,
                    Location2 = measure.Location2.Lat + "," + measure.Location2.Long,
                },
                Result = result.ToString(),
                User   = new User()
            });

            return(result);
        }
        public async Task <object> Measure(Measure measure)
        {
            object result;

            if (!ModelState.IsValid)
            {
                return(new { Error = ModelState.Errors() });;
            }
            result = await distanceMeasureDataProvider.
                     MeasureDistance(measure.Location1, measure.Location2);

            await historyDataProvider.InsertHistory(new RequestHistory()
            {
                Date   = DateTime.Now.ToShortDateString(),
                Mesure = new Measure()
                {
                    Location1 = measure.Location1,
                    Location2 = measure.Location2
                },
                Result = result.ToString(),
                User   = new User()
            });

            return(result);
        }
Example #3
0
        public async Task <object> Measure(Measure measure)
        {
            var userName = string.Empty;

            if (HttpContext.User.Identity is ClaimsIdentity identity)
            {
                userName = identity.FindFirst(ClaimTypes.Name).Value;
            }

            object result;

            if (!ModelState.IsValid)
            {
                return(new { Error = ModelState.Errors() });;
            }
            result = await distanceMeasureDataProvider.
                     MeasureDistance(measure.Location1, measure.Location2);

            await historyDataProvider.InsertHistory
                (new RequestHistory()
            {
                Date      = DateTime.Now.ToShortDateString(),
                Locations = "{" + measure.Location1.Lat + "," + measure.Location1.Long + "} To {" +
                            measure.Location2.Lat + "," + measure.Location2.Long + "}",
                Result = result.ToString(),
                User   = await userDataProvider.GetUserIfExist(userName)
            });

            return(result);
        }
        public async Task <object> Measure(Measure measure)
        {
            #region get UserName via token
            var userName = string.Empty;
            if (HttpContext.User.Identity is ClaimsIdentity identity)
            {
                userName = identity.FindFirst(ClaimTypes.Name).Value;
            }
            #endregion


            if (!ModelState.IsValid)
            {
                return(new { Error = ModelState.Errors() });;
            }

            //store distance measuring in dynamic result (maybe have error in measuring function)
            dynamic result = await distanceMeasureDataProvider.
                             MeasureDistance
                             (
                measure.Location1, measure.Location2
                             );

            //if calcule measur have error dont continue and return error
            if (result.Code != StatusCodes.Status200OK)
            {
                return(result);
            }

            //insert measurin history to database
            await historyDataProvider.InsertHistory
                (new RequestHistory()
            {
                Date      = DateTime.Now.ToShortDateString(),
                Locations = "{" + measure.Location1.Lat + "," + measure.Location1.Long + "} To {" +
                            measure.Location2.Lat + "," + measure.Location2.Long + "}",
                Result = result.Distance + "",
                User   = await userDataProvider.GetUserIfExist(userName)  //get user object for insert to Measure History
            });

            return(result);
        }