Esempio n. 1
0
        public async Task <ActionResult <PlaceConverter> > PostPlaceConverter(PlaceConverter placeConverter)
        {
            _context.PlaceConverter.Add(placeConverter);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPlaceConverter", new { id = placeConverter.PlaceConverterId }, placeConverter));
        }
Esempio n. 2
0
        public IHttpActionResult GetPlace([FromUri] string placeId)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            if (!Guid.TryParse(placeId, out var modelPlaceId))
            {
                return(this.BadRequest());
            }

            Models.Place.Place modelPlace = null;

            try
            {
                modelPlace = this.repository.Get(modelPlaceId);
            }
            catch (Models.Place.PlaceNotFoundException)
            {
                return(this.NotFound());
            }

            return(this.Ok(PlaceConverter.Convert(modelPlace)));
        }
Esempio n. 3
0
        public async Task <IActionResult> PutPlaceConverter(int id, PlaceConverter placeConverter)
        {
            if (id != placeConverter.PlaceConverterId)
            {
                return(BadRequest());
            }

            _context.Entry(placeConverter).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaceConverterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void GivenAnEmployeAtThe(string name, string placeName)
        {
            Employe employe = GetEmployeFromSmallRedTeam(name);

            var place = PlaceConverter.Convert(placeName);

            employe.MoveTo(place);

            Assert.AreEqual(place, employe.CurrentPlace);
        }
Esempio n. 5
0
        public IHttpActionResult PatchPlace([FromUri] string placeId, [FromBody] PlacePatchInfo patchInfo)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            if (!Guid.TryParse(placeId, out var placeIdGuid))
            {
                return(this.BadRequest());
            }

            string            sessionId = "";
            CookieHeaderValue cookie    = Request.Headers.GetCookies("SessionId").FirstOrDefault();

            if (cookie != null)
            {
                sessionId = cookie["SessionId"].Value;
            }

            if (!authenticator.TryGetSession(sessionId, out var sessionState))
            {
                return(this.Unauthorized());
            }

            try
            {
                var place = this.repository.Get(placeIdGuid);
                if (sessionState.UserId != place.OwnerId)
                {
                    return(this.Unauthorized());
                }
            }
            catch (Exception)
            {
                return(this.Unauthorized());
            }

            var placePatchInfo = PlacePatchInfoConverter.Convert(placeIdGuid, patchInfo);

            Models.Place.Place modelPlace = null;

            try
            {
                modelPlace = this.repository.Patch(placePatchInfo);
            }
            catch (Models.Place.PlaceNotFoundException)
            {
                this.NotFound();
            }

            return(Ok(PlaceConverter.Convert(modelPlace)));
        }
        public IHttpActionResult PatchPlace([FromUri] string placeId, [FromBody] PlacePatchInfo patchInfo)
        {
            string sessionId = patchInfo.SessionId;

            if (!authenticator.TryGetSession(sessionId, out var sessionState))
            {
                return(this.Unauthorized());
            }

            if (!Guid.TryParse(placeId, out var placeIdGuid))
            {
                return(this.BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }
            if (patchInfo == null)
            {
                return(this.BadRequest("Body must be not null"));
            }

            try
            {
                var place = this.repository.Get(placeIdGuid);
                if (sessionState.UserId != place.OwnerId)
                {
                    return(this.Unauthorized());
                }
            }
            catch (Exception)
            {
                return(this.Unauthorized());
            }

            var placePatchInfo = PlacePatchInfoConverter.Convert(placeIdGuid, patchInfo);

            Models.Place.Place modelPlace = null;

            try
            {
                modelPlace = this.repository.Patch(placePatchInfo);
            }
            catch (Models.Place.PlaceNotFoundException)
            {
                this.NotFound();
            }

            return(Ok(PlaceConverter.Convert(modelPlace)));
        }
Esempio n. 7
0
File: Map.cs Progetto: skim817/api
        public static List <PlaceConverter> GetPlacesFromGeoCodenType(String GeoCode, String Type)
        {
            String  APIKEY         = "AIzaSyDxnLbITe46r20XEo51dgFm8yHeHL4nzT0";
            String  LinkforPlaces  = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + GeoCode + "&rankby=distance&type=" + Type + "&key=" + APIKEY;
            String  PlacesInfoJSON = new WebClient().DownloadString(LinkforPlaces);
            dynamic jsonObj        = JsonConvert.DeserializeObject <dynamic>(PlacesInfoJSON);

            List <PlaceConverter> PlacesFinal = new List <PlaceConverter>();

            for (int i = 0; i < 20; i++)
            {
                String name       = jsonObj["results"][i]["name"];
                String placeidnum = jsonObj["results"][i]["place_id"];

                String  LinkforMap      = "https://maps.googleapis.com/maps/api/place/details/json?placeid=" + placeidnum + "&key=" + APIKEY;
                String  PlacesInfoJSON2 = new WebClient().DownloadString(LinkforMap);
                dynamic jsonObj2        = JsonConvert.DeserializeObject <dynamic>(PlacesInfoJSON2);

                int rank = 100;

                if (jsonObj2["result"]["rating"] != null)
                {
                    rank = jsonObj2["result"]["rating"];
                }

                String photo = "https://shenandoahcountyva.us/bos/wp-content/uploads/sites/4/2018/01/picture-not-available-clipart-12.jpg";

                if (jsonObj2["result"]["photos"] != null)
                {
                    photo = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=" + jsonObj2["result"]["photos"][0]["photo_reference"] + "&key=" + APIKEY;
                }

                PlaceConverter Place = new PlaceConverter
                {
                    PlaceTitle  = name,
                    Photo       = photo,
                    PlaceRank   = rank,
                    IsFavourite = false,
                    PlaceId     = placeidnum
                };

                PlacesFinal.Add(Place);
            }


            return(PlacesFinal);
        }
Esempio n. 8
0
        public async Task <ActionResult <Main> > PostMain([FromBody] INPUT data)
        {
            Main   main;
            String geolcation;
            String type;

            try
            {
                // Constructing the video object from our helper function
                geolcation = data.GeoCode;
                type       = data.TypeOfPlace;
                main       = Map.GetPlaces(geolcation, type);
            }
            catch
            {
                return(BadRequest("Invalid"));
            }

            _context.Main.Add(main);
            await _context.SaveChangesAsync();

            int ide = main.MainId;

            placeConverterContext     a   = new placeConverterContext();
            PlaceConvertersController pcc = new PlaceConvertersController(a);

            Task addplace = Task.Run(async() =>
            {
                List <PlaceConverter> placearray = new List <PlaceConverter>();
                placearray = Map.GetPlacesFromGeoCodenType(geolcation, type);

                for (int i = 0; i < placearray.Count; i++)
                {
                    PlaceConverter pl = placearray.ElementAt(i);
                    pl.MainId         = ide;

                    await pcc.PostPlaceConverter(pl);
                }
            });



            return(CreatedAtAction("GetMain", new { id = main.MainId }, main));
        }
Esempio n. 9
0
        public async Task GetRunsUser(string game, string username)
        {
            var requester = new RequestHandler();
            var message   = await ReplyAsync("Gathering Data...");

            try
            {
                var user    = requester.GetUser(username).data;
                var runs    = requester.GetRunsPerUserPerGame(user.id, game);
                var builder = Builders.BaseBuilder(user.names["international"],
                                                   "Runs done in game " + runs[0].game.data.names["international"], Color.Blue, null,
                                                   runs[0].game.data.assets["icon"].uri);
                string runText = "";
                foreach (var run in runs)
                {
                    if (run.level?.data == null)
                    {
                        runText +=
                            $"**{run.category.data.name} {PlaceConverter.Ordinal(run.place)} place:** {ConvertToTime(run.run.times.primary)}\n";
                    }
                    else
                    {
                        runText +=
                            $"**(IL) {run.level.data.name} {PlaceConverter.Ordinal(run.place)} place:** {ConvertToTime(run.run.times.primary)}\n";
                    }
                }
                builder.AddInlineField("Runs", runText);
                await message.DeleteAsync();
                await ReplyAsync("", embed : builder.Build());
            }
            catch
            {
                await message.DeleteAsync();
                await ReplyAsync("User or Game not found");
            }
        }
Esempio n. 10
0
        public async Task GetUserData([Remainder] string name)
        {
            var message = await ReplyAsync("Gathering data...");

            try
            {
                var user    = new RequestHandler().GetUser(name).data;
                var builder = Builders.BaseBuilder(user.names["international"], "", Color.Blue, null, null);
                builder.AddInlineField("Information",
                                       $"**Name:** {user.names["international"]}\n" +
                                       $"**Country:** {user.location.country.names["international"]}");
                string links = "";
                if (user.twitch != null)
                {
                    links += user.twitch.uri + "\n";
                }
                if (user.twitter != null)
                {
                    links += user.twitter.uri + "\n";
                }
                if (user.hitbox != null)
                {
                    links += user.hitbox + "\n";
                }
                if (user.speedrunslive != null)
                {
                    links += user.speedrunslive.uri + "\n";
                }
                if (user.youtube != null)
                {
                    links += user.youtube.uri + "\n";
                }
                if (!string.IsNullOrEmpty(links))
                {
                    builder.AddInlineField("Links", links);
                }
                builder.WithUrl(user.weblink);
                var    wrRuns       = new RequestHandler().GetWorldRecordsPerUser(user.id).OrderBy(x => x.game.data.names["international"]).ToList();
                string worldrecords = "";
                for (int i = 0; i < wrRuns.Count; i++)
                {
                    if (wrRuns[i].level?.data == null)
                    {
                        worldrecords +=
                            $"**{wrRuns[i].game.data.names["international"]} {wrRuns[i].category.data.name}: **{ConvertToTime(wrRuns[i].run.times.primary)}\n";
                    }
                    else
                    {
                        worldrecords +=
                            $"**{wrRuns[i].game.data.names["international"]} (IL) {wrRuns[i].level.data.name}: **{ConvertToTime(wrRuns[i].run.times.primary)}\n";
                    }
                }
                if (!string.IsNullOrEmpty(worldrecords))
                {
                    builder.AddInlineField("World Records", worldrecords);
                }
                var    recentRuns = new RequestHandler().GetLatestRunsPerUser(user.id);
                string runs       = "";
                for (int i = 0; i < 10; i++)
                {
                    if (recentRuns[i].level?.data == null)
                    {
                        runs +=
                            $"**{recentRuns[i].game.data.names["international"]} {recentRuns[i].category.data.name} {PlaceConverter.Ordinal(recentRuns[i].place)} place:** " +
                            $"{/*recentRuns[i].run.times.primary.Replace("PT", "").Replace("H", ":").Replace("M", ":").Replace("S", "")*/ ConvertToTime(recentRuns[i].run.times.primary)}\n";
                    }
                    else
                    {
                        runs +=
                            $"**{recentRuns[i].game.data.names["international"]} (IL) {recentRuns[i].level.data.name} {PlaceConverter.Ordinal(recentRuns[i].place)} place:** {ConvertToTime(recentRuns[i].run.times.primary)}\n";
                    }
                }
                if (!string.IsNullOrEmpty(runs))
                {
                    builder.AddInlineField("Recent PBs", runs);
                }
                await message.DeleteAsync();
                await ReplyAsync("", embed : builder.Build());
            }
            catch
            {
                await message.DeleteAsync();
                await ReplyAsync("User not found");
            }
        }