@model IEnumerable<SuperShop.Web.Data.Entities.OrderDetailTemp>
@{
    ViewData["Title"] = "Create";
}

<h2>Create</h2>


<p>
    <a asp-action="AddProduct" class="btn btn-success">Add Product</a>
    <a asp-action="ConfirmOrder" class="btn btn-primary" id="btnConfirm">Confirm Order</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Product.Name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Price)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Quantity)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Value)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Product.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Price)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Quantity)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Value)
                </td>
                <td id="@item.Id">
                    <a asp-action="Increase" asp-route-id="@item.Id" class="btn btn-warning"><i class="fa fa-plus"></i></a>
                    <a asp-action="Decrease" asp-route-id="@item.Id" class="btn btn-info"><i class="fa fa-minus"></i></a>
                    <a asp-action="DeleteItem" asp-route-id="@item.Id" class="btn btn-danger" id="btnDeleteItem">Delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>
<div id="confirmDialog" class="modal fade">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Confirm Order</h4>
                <button type="button" class="close" data-dismiss="modal"><i class="fa fa-window-close"></i></button>
            </div>
            <div class="modal-body">
                <p>Do you want to confirm the order ?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="btnYesConfirm">Yes</button>
                <button type="button" class="btn btn-success" id="btnNoConfirm">No</button>
            </div>
        </div>
    </div>
</div>

<div id="deleteDialog" class="modal fade">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Delete</h4>
                <button type="button" class="close" data-dismiss="modal"><i class="fa fa-window-close"></i></button>
            </div>
            <div class="modal-body">
                <p>Do you want to delete product from order ?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="btnYesDelete">Yes</button>
                <button type="button" class="btn btn-success" id="btnNoDelete">No</button>
            </div>
        </div>
    </div>
</div>
@section Scripts{
    <script type="text/javascript">
        $(document).ready(function(){
            var id = 0;
            $("#btnConfirm").click(function() {
                $("#confirmDialog").modal("show");
                return false;
            });
            $("#btnNoConfirm").click(function() {
                $("#confirmDialog").modal("hide");
                return false;
            });
            $("#btnYesConfirm").click(function() {
                window.location.href = "/Orders/ConfirmOrder";
            });
            $("a[id*=btnDeleteItem]").click(function() {
                debugger;
                id=$(this).parent()[0].id;
                $("#deleteDialog").modal("show");
                return false;
            });
            $("#btnNoDelete").click(function() {
                $("#deleteDialog").modal("hide");
                return false;
            });
            $("#btnYesDelete").click(function() {
                window.location.href = "/Orders/DeleteItem/" + id;
            });
        });
    </script>
    }

