/// <summary>
 /// Create a new Segment object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="subnetMaskId">Initial value of the SubnetMaskId property.</param>
 /// <param name="gatewayId">Initial value of the GatewayId property.</param>
 /// <param name="vlanId">Initial value of the VlanId property.</param>
 public static Segment CreateSegment(global::System.Int32 id, global::System.String name, global::System.Int32 subnetMaskId, global::System.Int32 gatewayId, global::System.Int32 vlanId)
 {
     Segment segment = new Segment();
     segment.Id = id;
     segment.Name = name;
     segment.SubnetMaskId = subnetMaskId;
     segment.GatewayId = gatewayId;
     segment.VlanId = vlanId;
     return segment;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Segments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSegments(Segment segment)
 {
     base.AddObject("Segments", segment);
 }
        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;
        }