Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Last active December 19, 2015 12:09
Show Gist options
  • Select an option

  • Save TechplexEngineer/5952436 to your computer and use it in GitHub Desktop.

Select an option

Save TechplexEngineer/5952436 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace PcnWeb.Models
{
public partial class Device
{
public Device()
{
this.Ports = new List<Port>();
}
[Key]
public int deviceRecId { get; set; }
public int deviceLocRecId { get; set; }
public int processAreaRecId { get; set; }
public int systemRecId { get; set; }
public int deviceDescRecId { get; set; }
public int deviceIPTypeRecId { get; set; }
public int speedRecId { get; set; }
public int ipAddressRecId { get; set; }
[Required, StringLength(64)]
[Unique]
public string Name { get; set; }
[StringLength(256)]
public string Comment { get; set; }
public virtual IPAddress IPAddress { get; set; }
public virtual MasterBus MasterBus { get; set; }
public virtual ICollection<Port> Ports { get; set; }
public virtual DeviceDesc DeviceDesc { get; set; }
public virtual DeviceIPType DeviceIPType { get; set; }
public virtual DeviceLoc DeviceLoc { get; set; }
public virtual ProcessArea ProcessArea { get; set; }
public virtual NetworkSpeed NetworkSpeed { get; set; }
public virtual ProcessSystem ProcessSystem { get; set; }
}
}
@model PcnWeb.Models.Device
@{
ViewBag.Title = "Create a Device";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Device</legend>
<div class="editor-label">
@Html.LabelFor(model => model.deviceLocRecId, "DeviceLoc")
</div>
<div class="editor-field">
@Html.DropDownList("deviceLocRecId", String.Empty)
@Html.ValidationMessageFor(model => model.deviceLocRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.processAreaRecId, "ProcessArea")
</div>
<div class="editor-field">
@Html.DropDownList("processAreaRecId", String.Empty)
@Html.ValidationMessageFor(model => model.processAreaRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.systemRecId, "ProcessSystem")
</div>
<div class="editor-field">
@Html.DropDownList("systemRecId", String.Empty)
@Html.ValidationMessageFor(model => model.systemRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.deviceDescRecId, "DeviceDesc")
</div>
<div class="editor-field">
@Html.DropDownList("deviceDescRecId", String.Empty)
@Html.ValidationMessageFor(model => model.deviceDescRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.deviceIPTypeRecId, "DeviceIPType")
</div>
<div class="editor-field">
@Html.DropDownList("deviceIPTypeRecId", String.Empty)
@Html.ValidationMessageFor(model => model.deviceIPTypeRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.speedRecId, "NetworkSpeed")
</div>
<div class="editor-field">
@Html.DropDownList("speedRecId", String.Empty)
@Html.ValidationMessageFor(model => model.speedRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ipAddressRecId, "IPAddress")
</div>
<div class="editor-field">
@Html.DropDownList("ipAddressRecId", String.Empty)
@Html.ValidationMessageFor(model => model.ipAddressRecId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name, "Name")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Comment, "Comment")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment)
@Html.ValidationMessageFor(model => model.Comment)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace PcnWeb.Models
{
public class IP_Address
{
public IP_Address()
{
this.UPSs = new List<UPS>();
}
public virtual ICollection<UPS> UPSs { get; set; }
public virtual ICollection<NetworkSwitch> NetworkSwitches { get; set; }
public virtual ICollection<Device> Devices { get; set; }
[Key]
public int ipAddressRecId { get; set; }
[Required]
[NotMapped]
[RegularExpression(@"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|DHCP", ErrorMessage = "IP Address must be in the form of four octets 0-255: 255.255.255.255 or DHCP")]
public string IP_Address
{
get
{
if (ipOctet1 == null | ipOctet2 == null | ipOctet3 == null | ipOctet4 == null)
return "DHCP";
return ipOctet1 + "." + ipOctet2 + "." + ipOctet3 + "." + ipOctet4;
}
set
{
if (value == "DHCP")
{
ipOctet1 = null;
ipOctet2 = null;
ipOctet3 = null;
ipOctet4 = null;
return;
}
//@todo Parseing could throw a number of errors: ArgumentNullException, FormatException, Exception
byte[] temp = System.Net.IPAddress.Parse(value).GetAddressBytes();
ipOctet1 = temp[0];
ipOctet2 = temp[1];
ipOctet3 = temp[2];
ipOctet4 = temp[3];
}
}
[NotMapped] //@todo check if this is needed. Don't want an extra database entry.
public long ipTotal
{
get
{
if (ipOctet1 == null || ipOctet2 == null || ipOctet3 == null || ipOctet4 == null)
return 0;
//(first octet * 2^24) + (second octet * 2^16) + (third octet * 2^8) + (fourth octet)
return ((long)ipOctet1 * 16777216) + ((long)ipOctet2 * 65536) + ((long)ipOctet3 * 256) + (long)ipOctet4;
}
}
public Nullable<int> ipOctet1 { get; set; }
public Nullable<int> ipOctet2 { get; set; }
public Nullable<int> ipOctet3 { get; set; }
public Nullable<int> ipOctet4 { get; set; }
[Required]
[NotMapped]
[RegularExpression(@"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|DHCP", ErrorMessage = "Subnet Mask must be in the form of four octets 0-255: 255.255.255.255 or DHCP")]
public string Subnet_Mask
{
get
{
if (smOctet1 == null || smOctet2 == null || smOctet3 == null || smOctet4 == null)
return "DHCP";
return smOctet1 + "." + smOctet2 + "." + smOctet3 + "." + smOctet4;
}
set
{
if (value == "DHCP")
{
smOctet1 = null;
smOctet2 = null;
smOctet3 = null;
smOctet4 = null;
return;
}
//@todo Parseing could throw a number of errors: ArgumentNullException, FormatException, Exception
byte[] temp = System.Net.IPAddress.Parse(value).GetAddressBytes();
smOctet1 = temp[0];
smOctet2 = temp[1];
smOctet3 = temp[2];
smOctet4 = temp[3];
}
}
[NotMapped] //@todo check if this is needed. Don't want an extra database entry.
public long smTotal
{
get
{
if (smOctet1 == null || smOctet2 == null || smOctet3 == null || smOctet4 == null)
return 0;
//(first octet * 2^24) + (second octet * 2^16) + (third octet * 2^8) + (fourth octet)
return ((long)smOctet1 * 16777216) + ((long)smOctet2 * 65536) + ((long)smOctet3 * 256) + (long)smOctet4;
}
}
public Nullable<int> smOctet1 { get; set; }
public Nullable<int> smOctet2 { get; set; }
public Nullable<int> smOctet3 { get; set; }
public Nullable<int> smOctet4 { get; set; }
}
}
@model PcnWeb.Models.IPAddress
@{
ViewBag.Title = "Create a IPAddress";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>IPAddress</legend>
<div class="editor-label">
@Html.LabelFor(model => model.IP_Address, "IP Address")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IP_Address)
@Html.ValidationMessageFor(model => model.IP_Address)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Subnet_Mask, "Subnet Mask")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Subnet_Mask)
@Html.ValidationMessageFor(model => model.Subnet_Mask)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment