public ActionResult DeleteConfirmed(int id)
        {
            PickUpLocation pickUpLocation = (PickUpLocation)db.PickUpLocations.Find(id);

            db.PickUpLocations.Remove(pickUpLocation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public Vehicle NewVehicle()
        {
            Location pickUpLocation = new Location(PickUpLocation.Split(',')[1], PickUpLocation.Split(',')[0]);

            double.TryParse(Price, out double vehiclePrice);

            return(new Vehicle(pickUpLocation, Information, vehiclePrice));
        }
Exemplo n.º 3
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);
        }
        // GET: PickUpLocations/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PickUpLocation pickUpLocation = (PickUpLocation)db.PickUpLocations.Find(id);

            if (pickUpLocation == null)
            {
                return(HttpNotFound());
            }
            return(View(pickUpLocation));
        }
        public ActionResult Edit([Bind(Include = "PickUpLocationID,PickUpNickName,PickUpBuilding,PickUpStreet,PickUpCity,PickUpProvinceCode,PickUpPostalCode")] PickUpLocationViewModel pickUpLocationViewModel)
        {
            if (ModelState.IsValid)
            {
                PickUpLocation pickUpLocation = new PickUpLocation(pickUpLocationViewModel.PickUpLocationID,
                                                                   pickUpLocationViewModel.PickUpNickName, pickUpLocationViewModel.PickUpBuilding, pickUpLocationViewModel.PickUpStreet,
                                                                   pickUpLocationViewModel.PickUpCity, pickUpLocationViewModel.PickUpProvinceCode, pickUpLocationViewModel.PickUpPostalCode);

                pickUpLocation.PickUpProvinceCode = GetProvince(pickUpLocation.PickUpCity);
                db.Entry(pickUpLocation).State    = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(pickUpLocationViewModel));
        }
        public ActionResult ArrangePickup(PickupViewModel pickupViewModel, bool next = false)
        {
            if (!next)  // Submit Pickuplocation
            {
                PickUpLocation pickupLocation = db.PickUpLocations.Find(pickupViewModel.PickUpLocationID);
                ViewBag.PickUpBuilding   = pickupLocation.PickUpBuilding;
                ViewBag.PickUpStreet     = pickupLocation.PickUpStreet;
                ViewBag.PickUpCity       = pickupLocation.PickUpCity;
                ViewBag.PickUpPostalCode = pickupLocation.PickUpPostalCode;

                pickupViewModel.PickUpLocations = PopulatePickUpLocationsDropDownList().ToList();
                if (pickupViewModel.PickUpLocations.Count > 0)
                {
                    ViewBag.ShowPickupLocation = 1;
                }
                else
                {
                    ViewBag.ShowPickupLocation = 0;
                }
                pickupViewModel.Cities = PopulateDestinationsDropDownList().ToList();

                return(View(pickupViewModel));
            }


            if (Session["newPickupView"] != null)
            {
                Session.Remove("newPickupView");
            }
            SaveToSessionState("newPickupView", pickupViewModel);
            if (Session["newPickup"] != null)
            {
                Session.Remove("newPickup");
            }
            SaveToSessionState("newPickup", pickupViewModel.Pickup);

            if (pickupViewModel.Pickup.Type == "Prearranged")
            {
                return(RedirectToAction("ArrangePrearrangedPickup"));
            }
            else if (pickupViewModel.Pickup.Type == "Immediate")
            {
                return(RedirectToAction("ConfirmPickup"));
            }

            return(RedirectToAction("Index", "Home"));
        }
        // GET: PickUpLocations/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PickUpLocation pickUpLocation = (PickUpLocation)db.PickUpLocations.Find(id);

            if (pickUpLocation == null)
            {
                return(HttpNotFound());
            }
            PickUpLocationViewModel pickUpLocationViewModel = new PickUpLocationViewModel(pickUpLocation.PickUpLocationID,
                                                                                          pickUpLocation.PickUpNickName, pickUpLocation.PickUpBuilding, pickUpLocation.PickUpStreet,
                                                                                          pickUpLocation.PickUpCity, pickUpLocation.PickUpProvinceCode, pickUpLocation.PickUpPostalCode);

            pickUpLocationViewModel.PickUpCities = PopulateDestinationsDropDownList().ToList();
            return(View(pickUpLocationViewModel));
        }
Exemplo n.º 8
0
 public void ChoosePickUpLocation()
 {
     PickUpLocation.Click();
     PickUpLocation.SendKeys(LOCATION);
     PickUpLocation.SendKeys(Keys.Enter);
 }
Exemplo n.º 9
0
 //returning a random unicorn for now
 public Unicorn findUnicorn(PickUpLocation pickupLocation)
 {
     LambdaLogger.Log("Finding unicorn for ," + pickupLocation.Latitude + ", " + pickupLocation.Longitude);
     //returning a random horse from the fleet, in real life we need a better logic of course.
     return(fleet[new Random().Next(3)]);
 }
Exemplo n.º 10
0
        protected override void Seed(LocationsDBContext context)
        {
            var coordinates = new List <GPSLocation>
            {
                new GPSLocation(20, 54),
                new GPSLocation(23, 54),
                new GPSLocation(25, 54),
                new GPSLocation(27, 54),
                new GPSLocation(35, 54),
                new GPSLocation(42, 54),
                new GPSLocation(46, 60),
                new GPSLocation(48, 65),
                new GPSLocation(50, 65),
                new GPSLocation(58, 65),
                new GPSLocation(2, 30),
                new GPSLocation(4, 34),
                new GPSLocation(6, 34),
                new GPSLocation(12, 80),
                new GPSLocation(18, 80),
                new GPSLocation(25, 80),
                new GPSLocation(25, 84),
                new GPSLocation(25, 90),
                new GPSLocation(25, 99),
            };

            if (!context.GPSLocation.Any())
            {
                context.GPSLocation.AddRange(coordinates);
            }

            var containerTypeOrange = ContainerTypeBuilder.Create()
                                      .ColouredOrange()
                                      .WithDescription(ContainerTypeDescription.Orange.ToString())
                                      .Build();

            var containerTypeYellow = ContainerTypeBuilder.Create()
                                      .ColouredYellow()
                                      .WithDescription(ContainerTypeDescription.Yellow.ToString())
                                      .Build();

            var containerTypeBrown = ContainerTypeBuilder.Create()
                                     .ColouredBrown()
                                     .WithDescription(ContainerTypeDescription.Brown.ToString())
                                     .Build();

            var containerTypeGreen = ContainerTypeBuilder.Create()
                                     .ColouredGreen()
                                     .WithDescription(ContainerTypeDescription.Green.ToString())
                                     .Build();

            var containerTypeBlue = ContainerTypeBuilder.Create()
                                    .ColouredBlue()
                                    .WithDescription(ContainerTypeDescription.Blue.ToString())
                                    .Build();

            var containerType = new List <ContainerType>
            {
                containerTypeOrange,
                containerTypeYellow,
                containerTypeBrown,
                containerTypeBlue,
                containerTypeGreen,
            };

            if (!context.ContainerType.Any())
            {
                context.ContainerType.AddRange(containerType);
            }

            var pickuplocations = new List <PickUpLocation>
            {
                PickUpLocation.Create(coordinates[0], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[0], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[0], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[1], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[1], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), false),
                PickUpLocation.Create(coordinates[1], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), true),
                PickUpLocation.Create(coordinates[2], containerType.SingleOrDefault(ct => ct.Id == containerTypeGreen.Id), true),
                PickUpLocation.Create(coordinates[2], containerType.SingleOrDefault(ct => ct.Id == containerTypeBlue.Id), false),
                PickUpLocation.Create(coordinates[3], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[3], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[3], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), true),
                PickUpLocation.Create(coordinates[4], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), false),
                PickUpLocation.Create(coordinates[4], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[4], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[5], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[6], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[6], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[6], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[7], containerType.SingleOrDefault(ct => ct.Id == containerTypeGreen.Id), false),
                PickUpLocation.Create(coordinates[7], containerType.SingleOrDefault(ct => ct.Id == containerTypeBlue.Id), false),
                PickUpLocation.Create(coordinates[8], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[9], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[9], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[9], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[10], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[10], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), false),
                PickUpLocation.Create(coordinates[10], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[11], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), false),
                PickUpLocation.Create(coordinates[11], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[11], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), true),
                PickUpLocation.Create(coordinates[12], containerType.SingleOrDefault(ct => ct.Id == containerTypeGreen.Id), true),
                PickUpLocation.Create(coordinates[12], containerType.SingleOrDefault(ct => ct.Id == containerTypeBlue.Id), true),
                PickUpLocation.Create(coordinates[13], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[14], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[14], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[14], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), true),
                PickUpLocation.Create(coordinates[15], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[15], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), false),
                PickUpLocation.Create(coordinates[15], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[16], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), true),
                PickUpLocation.Create(coordinates[16], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), true),
                PickUpLocation.Create(coordinates[16], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), true),
                PickUpLocation.Create(coordinates[17], containerType.SingleOrDefault(ct => ct.Id == containerTypeOrange.Id), false),
                PickUpLocation.Create(coordinates[17], containerType.SingleOrDefault(ct => ct.Id == containerTypeYellow.Id), false),
                PickUpLocation.Create(coordinates[17], containerType.SingleOrDefault(ct => ct.Id == containerTypeBrown.Id), false),
                PickUpLocation.Create(coordinates[18], containerType.SingleOrDefault(ct => ct.Id == containerTypeGreen.Id), true),
                PickUpLocation.Create(coordinates[18], containerType.SingleOrDefault(ct => ct.Id == containerTypeBlue.Id), true),
            };

            if (!context.PickUpLocation.Any())
            {
                context.PickUpLocation.AddRange(pickuplocations);
            }

            context.SaveChanges();
        }