/// <summary>
 /// Deprecated Method for adding a new object to the Vlans EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToVlans(Vlan vlan)
 {
     base.AddObject("Vlans", vlan);
 }
        public Vlan CreateVlan(string vlanName, int vlanNumber, IPAddress subnetmask)
        {
            var vlan = db.Vlans.SingleOrDefault(x => x.Number == vlanNumber);

            if (vlan == null)
            {
                vlan = new Vlan
                {
                    Name = vlanName,
                    Number = vlanNumber,
                    IP = CreateIP(subnetmask)
                };

                db.Vlans.AddObject(vlan);
            }

            return vlan;
        }
 /// <summary>
 /// Create a new Vlan object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="number">Initial value of the Number property.</param>
 /// <param name="subnetMaskId">Initial value of the SubnetMaskId property.</param>
 public static Vlan CreateVlan(global::System.Int32 id, global::System.String name, global::System.Int32 number, global::System.Int32 subnetMaskId)
 {
     Vlan vlan = new Vlan();
     vlan.Id = id;
     vlan.Name = name;
     vlan.Number = number;
     vlan.SubnetMaskId = subnetMaskId;
     return vlan;
 }
        public Segment CreateSegment(string name, IPAddress subnetMask, IPAddress gateway, Vlan vlan, Location location)
        {
            var subnetMaskArray = subnetMask.GetAddressBytes();
            var gatewayArray = gateway.GetAddressBytes();

            var segment = db.Segments.SingleOrDefault(x => x.Gateway.Address == gatewayArray && x.SubnetMask.Address == subnetMaskArray);

            if (segment == null)
            {
                segment = new Segment
                {
                    Name = name,
                    SubnetMask = CreateIP(subnetMask),
                    Gateway = CreateIP(gateway),
                    Vlan = vlan,
                    IPGroup = GetIPGroup(gateway)
                };

                db.Segments.AddObject(segment);

                var segmentLocation = new SegmentLocation
                {
                    Segment = segment,
                    Location = location
                };

                db.SegmentLocations.AddObject(segmentLocation);
            }

            return segment;
        }