Ejemplo n.º 1
0
 public HttpResponseMessage PostTeam(Team team)
 {
     Teams.Add(team);
     var routeLink = Url.Link("GetTeamById", new {id = team.Id});
     var response = new HttpResponseMessage(HttpStatusCode.Created);
     response.Headers.Location = new Uri(routeLink);
     return response;
 }
Ejemplo n.º 2
0
        public HttpResponseMessage PutTeam(int id, Team team)
        {
            var currentTeam = Teams.FirstOrDefault(x => x.Id == id);
            if (currentTeam == null) throw new HttpResponseException(HttpStatusCode.NotFound);

            currentTeam.Name = team.Name;

            return new HttpResponseMessage(HttpStatusCode.NoContent);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            var address = "http://localhost:920/";

            using (WebApp.Start<Startup>(address))
            {
                var client = new HttpClient();

                var team = new Team {Id = 3, Name = "Los Angeles Kings"};

                var result = client.PostAsJsonAsync(address + "api/teams", team).Result;
                Console.WriteLine(result.StatusCode);
                Console.WriteLine(result.Headers.Location);

                Console.WriteLine();

                var result2 = client.GetAsync(result.Headers.Location).Result;
                Console.WriteLine(result2.StatusCode);
                Console.WriteLine(result2.Content.ReadAsStringAsync().Result);

                Console.ReadLine();
            }
        }
Ejemplo n.º 4
0
 public HttpResponseMessage PostTeam(Team team)
 {
     Teams.Add(team);
     return new HttpResponseMessage(HttpStatusCode.Created);
 }
Ejemplo n.º 5
-1
        static void Main()
        {
            var address = "http://localhost:920/";

            using (WebApp.Start<Startup>(address))
            {
                var client = new HttpClient();

                var team = new Team {Id = 3, Name = "Los Angeles Kings"};
                var team2 = new Team { Name = "Boston Bruins" };
                var player = new Player {Name = "Tyler Bozak", Team = 1};

                Send(HttpMethod.Get, client, address + "api/teams");
                Send(HttpMethod.Get, client, address + "api/teams/1");
                Send(HttpMethod.Get, client, address + "api/teams/1/players");

                Console.WriteLine(client.PostAsJsonAsync(address+"api/teams", team).Result.StatusCode);
                Console.WriteLine();

                Console.WriteLine(client.PostAsJsonAsync(address+"api/teams/1/players", player).Result.StatusCode);
                Console.WriteLine();

                Console.WriteLine(client.PutAsJsonAsync(address + "api/teams/2", team2).Result.StatusCode);
                Console.WriteLine();

                Send(HttpMethod.Get, client, address + "api/teams");
                Send(HttpMethod.Get, client, address + "api/teams/1/players");
            }

            Console.ReadLine();
        }