<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SorsolásWebApp._Default" %>
  
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

     <link href="Content/bootstrap.css" rel="stylesheet" />
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <script src="Scripts/bootstrap.min.js"></script>     
    <script src="Scripts/jquery-1.10.2.js"></script>

     <div class="container">
         <div class="jumbotron">
            <h1>Sorsolás  API elérése</h1>
        </div>
        <div class="form-group">
            <label for="nevsor">Névsor:</label>
            <textarea readonly class="form-control"  rows="5" id="nevsor"></textarea>
        </div>
        
            <input type="button" value="Sorsolj" class="form-control btn btn-primary btn-lg" onclick="sorsolj();" />
            <div class="form-group">
                <label for="kiválasztott">Kisorsolt:</label>
                <p id="kivalasztott" class="form-control" />
            </div>
        </div>


        <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
        <script>
            //var uri = ide írjuk az  api címét;
            var uri = "http://localhost:49885/api/sorsolas";
            $(document).ready(function () {
                $.getJSON(uri)
                    .done(function (data) {
                        $.each(data, function (i, item) {
                            var nev = item + ","
                            $('#nevsor').text($('#nevsor').text() + nev);
                        }); //End of foreach Loop   
                    })
                    .fail(function (jqXHR, textStatus, err) {
                        $('#kivalasztott').text('Hiba: ' + err);
                    })
            })
            function sorsolj() {
                var id = 0;               
                $.getJSON(uri + '/' + id)
                    .done(function (data) {
                        $('#kivalasztott').text(data);
                    })
                    .fail(function (jqXHR, textStatus, err) {
                        $('#kivalasztott').text('Hiba: ' + err);
                    });
            }
        </script>

</asp:Content>
