Ejemplo n.º 1
0
        public async Task <ActionResult <RideResponse> > Post(RideRequest request)
        {
            _logger.LogDebug("{@Configuration}", _configuration.AsEnumerable().Select(kv => $"{kv.Key} - {kv.Value}").ToList());

            _logger.LogDebug("{@LambdaContext}", Request.HttpContext.Items[AbstractAspNetCoreFunction.LAMBDA_CONTEXT]);
            _logger.LogDebug("{@LambdaRequestObject}", Request.HttpContext.Items[AbstractAspNetCoreFunction.LAMBDA_REQUEST_OBJECT]);
            _logger.LogDebug("{@IdentityDetails}", GetIdentityDetails().ToList());

            var rideId = Guid.NewGuid().ToString();

            var username = User.Identity.Name;

            var unicorn = FindUnicorn(request.PickupLocation);

            await _dbContext.SaveAsync(new Ride
            {
                RideId      = rideId,
                RequestTime = DateTime.UtcNow,
                Unicorn     = unicorn,
                UnicornName = unicorn.Name,
                User        = username
            });

            var response = new RideResponse
            {
                Eta         = "30 seconds",
                RideId      = rideId,
                Rider       = username,
                Unicorn     = unicorn,
                UnicornName = unicorn.Name
            };

            return(CreatedAtAction(nameof(Post), response));
        }
Ejemplo n.º 2
0
        //Lambda entery point - ****maybe i can with the handler serializer get the pickup location in constructor...
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            //returning a bad 'response' if something not went wall
            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.BadRequest
            };

            try
            {
                //inserting a byte array in order to return a random string orderId
                string orderId = toUrlString(new byte[32]);

                //requester user name from cognito user pool
                string userName = request.RequestContext.Authorizer.Claims.GetValueOrDefault("cognito:username");

                //taking the body of the apigateway lambda request
                var deserialize = JObject.Parse(request.Body);
                this.body = JsonConvert.DeserializeObject <PickUpLocation>(deserialize["PickupLocation"].ToString());


                //logging the event we recieved
                LambdaLogger.Log("Received event (" + orderId + "): " + "Latitude: " + body.Latitude + ",Longitude: " + body.Longitude + "...");

                //getting the unicorn nearest to the desired location (for now returning just a random one)
                PickUpLocation pickUpLocation = this.body;
                Unicorn        unicorn        = findUnicorn(pickUpLocation);

                //adding the ride to dynamoDB
                await recordRide(orderId, userName, unicorn);

                //prepering the response of our apigateway
                RideResponse ride = new RideResponse(orderId, unicorn, unicorn.Name, "30 seconds", userName);

                //adding and logging the weather from a weather api service call for the given lat and lon
                ride.Weather = await GetWeatherForecast(pickUpLocation.Latitude, pickUpLocation.Longitude);

                response = new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Body       = JsonConvert.SerializeObject(ride),
                    Headers    = new Dictionary <string, string> {
                        { "Access-Control-Allow-Origin", "*" }
                    }
                };
            }
            catch (Exception e)
            {
                context.Logger.LogLine("Error in inserting a new item to the database and/or returning a valid value");
                context.Logger.LogLine(e.Message);
                context.Logger.LogLine(e.StackTrace);
            }

            return(response);
        }
Ejemplo n.º 3
0
        public IHttpActionResult Get(string username)
        {
            if (!Repository.Instance.UserExists(username))
            {
                return(NotFound());
            }

            var user = Repository.Instance.TaxiServiceRepository.Users.FirstOrDefault(x => x.Username == username);
            IEnumerable <RideResponse> rides;

            switch (user.Role)
            {
            case UserRole.Customer:
            {
                var ridesAllData = Repository.Instance.TaxiServiceRepository.GetAllRides().Where(x => x.CustomerId == user.Id).ToList();
                rides = ridesAllData.Select(x => RideResponse.Convert(x));
            }
            break;

            case UserRole.Driver:
            {
                var ridesAllData = Repository.Instance.TaxiServiceRepository.GetAllRides().Where(x => x.DriverId == user.Id).ToList();
                rides = ridesAllData.Select(x => RideResponse.Convert(x));
            }
            break;

            case UserRole.Dispatcher:
            {
                var ridesAllData = Repository.Instance.TaxiServiceRepository.GetAllRides().Where(x => x.DispatcherId == user.Id).ToList();
                rides = ridesAllData.Select(x => RideResponse.Convert(x));
            }
            break;

            default:
                rides = null;
                break;
            }

            return(Ok(rides));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns basic ride data in compliance with GDPR
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RideResponse Get(int id)
        {
            var ride = Repository.Instance.TaxiServiceRepository.GetAllRides().FirstOrDefault(x => x.Id == id);

            return(RideResponse.Convert(ride));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Collection of rides converted to return just basic user information in compliance with GDPR
 /// </summary>
 /// <returns></returns>
 public IEnumerable <RideResponse> Get()
 {
     return(Repository.Instance.TaxiServiceRepository.GetAllRides().ToList().Select(x => RideResponse.Convert(x)));
 }
Ejemplo n.º 6
0
        public ActionResult GetAnyActive()
        {
            if (LoggedInUserId == null)
            {
                return(BadRequest("Invalid user id"));
            }

            var ride = RideService.Get(r =>
                                       (r.PassengerId == LoggedInUserId || r.DriverId == LoggedInUserId) &&
                                       (r.RideStatus == RideStatus.Requested || r.RideStatus == RideStatus.Accepted || r.RideStatus == RideStatus.PickedUp)
                                       );

            if (ride == null)
            {
                return(NoContent());
            }

            var rideResponse = new RideResponse
            {
                Id          = ride.RideId,
                PassengerId = ride.PassengerId,
                DriverId    = ride.DriverId,
                RideStatus  = ride.RideStatus,
                FromAddress = new AddressDto
                {
                    FormattedAddress = ride.FromAddress.FormattedAddress,
                    Latitude         = ride.FromAddress.Latitude,
                    Longitude        = ride.FromAddress.Longitude
                },
                ToAddress = new AddressDto
                {
                    FormattedAddress = ride.ToAddress.FormattedAddress,
                    Latitude         = ride.ToAddress.Latitude,
                    Longitude        = ride.ToAddress.Longitude
                },
                CurrentAddress = new AddressDto
                {
                    FormattedAddress = ride.CurrentAddress
                },
                Requested       = ride.Requested,
                Cancelled       = ride.Cancelled,
                Accepted        = ride.Accepted,
                Rejected        = ride.Rejected,
                PositionUpdated = ride.PositionUpdated,
                PickedUp        = ride.PickedUp,
                DroppedOff      = ride.DroppedOff
            };

            if (ride.CurrentLatitude != null)
            {
                if (ride.CurrentLatitude.HasValue)
                {
                    rideResponse.CurrentAddress.Latitude = ride.CurrentLatitude.Value;
                }
                if (ride.CurrentLongitude.HasValue)
                {
                    rideResponse.CurrentAddress.Longitude = ride.CurrentLongitude.Value;
                }
            }

            return(Ok(rideResponse));
        }
Ejemplo n.º 7
0
        private void AddJobtoLimoAnyWhere()
        {
            JobWrapper jobWrapper = new JobWrapper();
            string     apiId      = ConfigurationSettings.AppSettings["apiId"];  //Your Api ID
            string     apiKey     = ConfigurationSettings.AppSettings["apiKey"]; //Your Api Key
            //LimoEntities limmoEntity = new LimoEntities();
            //Company company = limmoEntity.Companies.Where(xx=>xx.CompanyID == jobWrapper.JobDetailsObject.CompanyID ).ToList().FirstOrDefault();
            var apiService = new ApiService();

            //LimoEntities limoEntity = new LimoEntities();
            //Company company =
            //limoEntity.Companies.Where(obj => obj.CompanyID == jobWrapper.JobDetailsObject.CompanyID).
            //    FirstOrDefault();
            //string zipCode = string.Empty;
            //if (company != null)
            //    zipCode = company.ZipCode;
            //AffiliateResponse affiliateResponse =
            //    apiService.GetAffiliates(apiId, apiKey).Affiliates.Where(obj => obj.Zip == zipCode).FirstOrDefault();
            //AffliateID = affiliateResponse != null ? affiliateResponse.Id : 0;

            VehicleTypeResponse cehicleTypeResponse = apiService.GetVehicleTypes(apiId, apiKey);
            string vehicleType = cehicleTypeResponse.VehicleTypes != null &&
                                 cehicleTypeResponse.VehicleTypes.Length > 0
                                     ? cehicleTypeResponse.VehicleTypes[0].VehTypeCode
                                     : string.Empty;

            //apiService.mylimobiz.book.ApiService laApi = new com.mylimobiz.book.ApiService();
            string[] fromAddress = txtSource.Text.Trim().Split(',');
            string   fromStreet = "", fromCity = "", fromState = "", fromZIPCode = "";

            if (fromAddress.Length > 0)
            {
                if (fromAddress.Length >= 3)
                {
                    fromStreet = fromAddress[0];
                    fromCity   = fromAddress[1];
                    string[] temp = fromAddress[2].Trim().Split(' ');
                    fromState = temp[0];
                    if (temp.Length == 2)
                    {
                        fromZIPCode = temp[1];
                    }
                }
                else if (fromAddress.Length == 2)
                {
                    fromCity = fromAddress[0];
                    string[] temp = fromAddress[1].Trim().Split(' ');
                    fromState = temp[0];
                    if (temp.Length == 2)
                    {
                        fromZIPCode = temp[1];
                    }
                }
            }
            string[] toAddress = txtDistenation.Text.Trim().Split(',');
            string   toStreet = "", toCity = "", toState = "", toZIPCode = "";

            if (toAddress.Length > 0)
            {
                if (toAddress.Length >= 3)
                {
                    toStreet = toAddress[0];
                    toCity   = toAddress[1];
                    string[] temp = toAddress[2].Trim().Split(' ');
                    toState = temp[0];
                    if (temp.Length == 2)
                    {
                        toZIPCode = temp[1];
                    }
                }
                else if (toAddress.Length == 2)
                {
                    toCity = toAddress[0];
                    string[] temp = toAddress[1].Trim().Split(' ');
                    toState = temp[0];
                    if (temp.Length == 2)
                    {
                        toZIPCode = temp[1];
                    }
                }
            }
            double carSeatInsidePickupFee = 0;

            double price = 0;

            double.TryParse(txtTotalPrice.Text, out price);
            //if (jobWrapper.JobDetailsObject.IsInsidePickup)
            //    carSeatInsidePickupFee += 15;
            //if (jobWrapper.JobDetailsObject.IsCarSeatAdd)
            //    carSeatInsidePickupFee += 30;
            //carSeatInsidePickupFee += jobWrapper.JobDetailsObject.JobProcessingFees;
            Ride ride = new Ride()
            {
                RideSource  = "Limoallover",
                RideType    = "RES",
                ServiceType = JobWrapper.ServiceTypeObject.PTP.ToString(),
                // done
                VehicleType = vehicleType,
                //"SEDAN",//jobWrapper.JobDetailsObject.JobCarType.ToString(),
                PickUpDate = DateTime.Parse(txtDatepicker.Text),
                PickUpTime = ddlHour.SelectedValue + ddlMinutes.SelectedItem.Text,

                NumberOfPax = int.Parse(ddlNOPassenger.SelectedItem.Text),
                //done
                PassengerFirstName = txtFirstName.Text,
                //done
                PassengerLastName = txtLastName.Text,
                //done
                PassengerEmail = txtPassEmail.Text,
                // done
                PassengerPhone = txtPassMobile.Text,
                // done
                BillingContact = txtFirstName.Text + " " + txtLastName.Text,
                //done
                Currency = "USD",
                //done
                //RideNumber = DateTime.Now.Ticks.ToString(),
                SpecialChildSeat = "No",                 //jobWrapper.JobDetailsObject.IsCarSeatAdd ? "Toddler" : "No",
                // done

                RatesMapping = new RatesMapping()
                {
                    BaseRate =
                        new RateFixed()
                    {
                        Rate = price
                    },
                    PerHourRate = new RateMultiply()
                    {
                        RatePerUnit = 0
                    },
                    PerMileRate =
                        new RateMultiply()
                    {
                        RatePerUnit = 0, Units = 0, Total = 0
                    },
                    PerPassengerRate =
                        new RateMultiply()
                    {
                        RatePerUnit = 0, Units = 0, Total = 0
                    },
                    ExtraStops = new RateFixed()
                    {
                        Rate = 0
                    },
                    Discount2 = new RateFixed()
                    {
                        Rate = 0
                    },
                    FuelSurcharge = new RatePercentage()
                    {
                        PercentageAmount = 0
                    },
                    Gratuity = new RatePercentage()
                    {
                        PercentageAmount = 0
                    },
                    Misc1 = new RateMisc()
                    {
                        Rate = 0, RateName = "Tolls"
                    },
                    Misc2 = new RateMisc()
                    {
                        Rate = 0, RateName = "Parking"
                    },
                    Misc3 = new RateMisc()
                    {
                        Rate     = 0,
                        RateName = "Taxes"
                    },
                    Misc4 =
                        new RateMisc()
                    {
                        Rate     = carSeatInsidePickupFee,
                        RateName =
                            "ProcessingFees / CarSeat / InsidePickupFee"
                    },
                    OvertimeWaitTime = new RateFixed()
                    {
                        Rate = 0
                    },
                    STCSurcharge = new RatePercentage()
                    {
                        PercentageAmount = 0
                    },
                    Total = price
                },
                RideRouteBlock = new RoutingItem[]
                {
                    new RoutingItem()
                    {
                        RIType       = "PU",
                        LocationType = "ADDR",
                        RIAddr1      = fromStreet,
                        RICity       = fromCity,
                        RIState      = fromState,
                        RIZip        = fromZIPCode
                    },
                    new RoutingItem()
                    {
                        RIType       = "DO",
                        LocationType = "ADDR",
                        RIAddr1      = toStreet,
                        RICity       = toCity,
                        RIState      = toState,
                        RIZip        = toZIPCode
                    }
                },
                //credit card
                //CreditCardNumber = txtCardNumber.Text,
                //CCExpDate = ddlExpirationMonth.SelectedValue + "/" + ddlExpirationYear.SelectedValue,
                //CCName = txtFirstName.Text + " " + txtLastName.Text,
                //CCState = ddlState.SelectedValue,
                //CCBillingAddr = txtAdddress.Text,
                //CCZip = txtZipCode.Text //,
                //CCNotes = txtCardVerifNumber.Text
            };
            RideResponse response = apiService.ImportReservation(apiId, apiKey, ride);
        }