@page "/Contacts/Add"

@using Gremlin_BlazorServer.Data.EntityClasses;
@using Gremlin_BlazorServer.Services;

@inject ContactService contactService
@inject NavigationManager navigationManager

<h2>Add Contact</h2>
<hr />

<form>
    <div class="row">
        <div class="col-md-8">
            <div class="form-group">
                <label for="ContactId" class="control-label">ContactId</label>
                <input form="ContactId" class="form-control" @bind="@contact.ContactId" />
            </div>
            <div class="form-group">
                <label for="AccountId" class="control-label">AccountId</label>
                <input form="AccountId" class="form-control" @bind="@contact.AccountId" />
            </div>
            <div class="form-group">
                <label for="LastName" class="control-label">LastName</label>
                <input form="LastName" class="form-control" @bind="@contact.LastName" />
            </div>
            <div class="form-group">
                <label for="FirstName" class="control-label">FirstName</label>
                <input form="FirstName" class="form-control" @bind="@contact.FirstName" />
            </div>
            <div class="form-group">
                <label for="Gender" class="control-label">Gender</label>
                <input form="Gender" class="form-control" @bind="@contact.Gender" />
            </div>
            <div class="form-group">
                <label for="EMail" class="control-label">EMail</label>
                <input form="EMail" class="form-control" @bind="@contact.EMail" />
            </div>
            <div class="form-group">
                <label for="SAPContactNumber" class="control-label">SAPContactNumber</label>
                <input form="SAPContactNumber" class="form-control" @bind="@contact.SAPContactNumber" />
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-4">
            <div class="form-group">
                <input type="button" class="btn btn-primary" @onclick="@CreateContact" value="Save"/>
                <input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel"/>
            </div>
        </div>
    </div>
</form>

@code {
    Contact contact = new Contact();

    protected async void CreateContact()
    {
        contact.DataModificationByUser = "Gremlin_BlazorServer";
        //contact.DataStatus = "Active";

        if (await contactService.InsertContactAsync(contact))
        {
            navigationManager.NavigateTo("Contacts/Index");
        }
    }

    void Cancel() => navigationManager.NavigateTo("Contacts/Index");
}