コード例 #1
0
        /// <summary>
        /// Updates the location of the car and takes care of the status as well as returns appropriate requests
        /// </summary>
        /// <param name="lon"></param>
        /// <param name="lat"></param>
        /// <param name="accessToken"></param>
        /// <param name="absent"></param>
        /// <param name="free"></param>
        /// <param name="onAddress"></param>
        /// <returns></returns>
        public JsonResult Pull(double lon, double lat, string accessToken, bool absent = false, bool free = false,
                               bool onAddress = false)
        {
            if (HttpContext.Request.RequestType == "POST")
            {
                var newAccessToken = _accessTokenService.GenerateAccessToken(accessToken);

                if (newAccessToken == null)
                {
                    return(Json(new { status = "INVALID ACCESSTOKEN" }));
                }

                var userId = _accessTokenService.GetUserId(newAccessToken);

                var driver = _driverService.GetDriverByUserId(userId);
                var car    = _carService.GetCarByDriver(driver);
                _carService.UpdateCarInfo(car, new Models.Models.Location {
                    Latitude = lat, Longitude = lon
                }, absent, free);

                if (onAddress)
                {
                    if (_carService.CarOnAddress(car))
                    {
                        return
                            (Json(
                                 new
                        {
                            status = "OK",
                            onAddress = true,
                            carStatus = car.CarStatus,
                            accessToken = newAccessToken
                        }));
                    }
                }

                if (_carService.CarOnAddressCheck(car))
                {
                    return
                        (Json(
                             new
                    {
                        status = "OK",
                        onAddress = true,
                        carStatus = car.CarStatus,
                        accessToken = newAccessToken
                    }));
                }

                var requestObj = _requestService.AppropriateRequest(car);
                if (requestObj != null)
                {
                    return
                        (Json(
                             new
                    {
                        status = "OK",
                        accessToken = newAccessToken,
                        carStatus = car.CarStatus,
                        request = requestObj
                    }));
                }

                return(Json(new { status = "OK", carStatus = car.CarStatus, accessToken = newAccessToken }));
            }
            return(Json(new { }));
        }