
<%@ Page Language="C#" %>
<%@ Import Namespace="eDocument.Server.Administrator" %>
<%@ Import Namespace="eDocument.Server.Administrator.eDocument.Server.Services" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
	protected void Page_Load(object sender, EventArgs e)
	{
			if (!Authorizor.IsAuthorized())
				Response.Redirect("~/Forbidden.aspx");
		}

	protected void btnCreate_Click(object sender, EventArgs e)
	{

			if (!Authorizor.IsAuthorized())
				Response.Redirect("~/Forbidden.aspx");

					
		var ds = new eDocumentDataSet {EnforceConstraints = false};

		var device = ds.Device.NewDeviceRow();
		device.DeviceId = Guid.NewGuid();
		device.Name = txtName.Text;
		device.Description = txtDescription.Text;
		device.Capabilities = txtCapabilities.Text;
		ds.Device.AddDeviceRow(device);

		var service = ServiceFactory.GetService();
		service.Update(ds);
		
		Response.Redirect("List.aspx");
	}
</script>


<html xmlns="http://www.w3.org/1999/xhtml">
	<head runat="server">
		<title>Title</title>
		<LINK rel="stylesheet" type="text/css" href="../css/FrameWork.css">
		<LINK rel="stylesheet" type="text/css" href="../css/Main.css">
	</head>
	<body>
		<form runat="server">
				<h1>Opprett enhet</h1>

			<table cellSpacing="2" cellPadding="5">
				<tr>
					<td><asp:label id="Label1" runat="server">Navn *</asp:label></td>
					<td><asp:textbox id="txtName" runat="server" MaxLength="300" Width="272px"></asp:textbox></td>
					<td><asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" Display="Dynamic" ControlToValidate="txtName"
							ErrorMessage="Du må angi et navn."></asp:requiredfieldvalidator></td>
				</tr>
				<tr>
					<td><asp:label id="Label2" runat="server">Beskrivelse</asp:label></td>
					<td><asp:textbox id="txtDescription" runat="server" MaxLength="300" Width="272px"></asp:textbox></td>
				</tr>
            <tr>
                <td valign="top">
                    <asp:Label ID="Label32" runat="server">Capabilities</asp:Label></td>
                <td>
                    <asp:TextBox ID="txtCapabilities" runat="server" Width="500px" Height="80px" TextMode="MultiLine"></asp:TextBox></td>
                <td>
                </td>
                <td>
                </td>
            </tr>
				<tr>
					<td align="right" colSpan="3"><asp:button id="btnCreate" runat="server" Text="Opprett" onclick="btnCreate_Click"></asp:button></td>
					<td></td>
				</tr>
			</table>
		</form>
	</body>
</html>
