Exemple #1
0
        public ParkingYard Parks(int ID)
        {
            ParkRepo = new ParkRepository();

            return(ParkRepo.GetParkingYard(ID));
        }
Exemple #2
0
        public async Task <JObject> Parks([FromUri] double lat, [FromUri] double lng)
        {
            maps mp = new maps();

            Response Response = new Response();

            Response = await mp.GetNearByPlaces(lat, lng, "parking", 10000);

            JObject Error = new JObject();

            if (Response.Code == 200)

            {
                Error.Add("Code", Response.Code);
                Error.Add("Message", "Success");

                ParkingYard Yard = new ParkingYard();

                JArray jarr = JArray.Parse(Response.Data);

                for (int count = 0; count < jarr.Count; count++)
                {
                    Yard.Image     = jarr[count]["place image"].ToString();
                    Yard.Name      = jarr[count]["name"].ToString();
                    Yard.Place_ID  = jarr[count]["place_id"].ToString();
                    Yard.Reference = jarr[count]["reference"].ToString();

                    ParkingYard.YardLocation YardLocation = new ParkingYard.YardLocation();
                    YardLocation.Name      = jarr[count]["vicinity"].ToString();
                    YardLocation.Latitude  = Convert.ToDouble(jarr[count]["geometry"]["location"]["lat"]);
                    YardLocation.Longitude = Convert.ToDouble(jarr[count]["geometry"]["location"]["lng"]);

                    Yard.Location = YardLocation;

                    ParkRepo = new ParkRepository();

                    if (await ParkRepo.CreateParkingYard(Yard))
                    {
                        Response.Message = "Parking Created Successfully";
                    }

                    else
                    {
                        Response.Message = "Parking Already exists";
                    }

                    JObject Parking = new JObject();

                    ParkingYard py = ParkRepo.GetParkingYard(Yard.Place_ID);

                    JObject Space = new JObject();

                    Space.Add("space id", py.Spaces.Space_ID);
                    Space.Add("space count", py.Spaces.Count);
                    Space.Add("used spaces", py.Spaces.UsedSpaces);

                    JObject Location = new JObject();
                    Location.Add("id", py.Location.id);
                    Location.Add("name", py.Location.Name);

                    Parking.Add("park_id", py.id);
                    Parking.Add("Space", Space);
                    Parking.Add("Location", Location);

                    JObject FinalJarr = (JObject)jarr[count];
                    FinalJarr.Add("Park Data", Parking);

                    jarr[count] = FinalJarr;
                }

                // JArray FinalJSONArray = (JArray)jarr;

                Error.Add("values", jarr);
            }

            else
            {
                Error.Add("Code", Response.Code);
                Error.Add("Message", Response.Message);
                Error.Add("Values", Response.Data);
            }

            return(Error);
        }