/// <summary>
 /// Create a new Server object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="serverTypeId">Initial value of the ServerTypeId property.</param>
 /// <param name="locationId">Initial value of the LocationId property.</param>
 public static Server CreateServer(global::System.Int32 id, global::System.Int32 serverTypeId, global::System.Int32 locationId)
 {
     Server server = new Server();
     server.Id = id;
     server.ServerTypeId = serverTypeId;
     server.LocationId = locationId;
     return server;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Servers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToServers(Server server)
 {
     base.AddObject("Servers", server);
 }
        public Request CreateRequest(string businessService, string applicationName, int[] applicationTypeId,
            string netBIOSName, string dnsName, int locationId, int serverTypeId, int? bladeChassisId,
            string bladeSwitchLocation, bool? bladeTeaming, int operatingSystemId, string notes, int? oldRequestId)
        {
            BladeChassis bladeChassis = null;

            if (serverTypeId == (int)ServerTypes.Blades)
            {
                bladeChassis = CreateBladeChassis(bladeSwitchLocation, bladeTeaming.Value);
            }

            var server = new Server
            {
                ServerTypeId = serverTypeId,
                LocationId = locationId,
                BladeChassi = bladeChassis
            };

            var vir = new Virtualization
            {
                OperatingSystemId = operatingSystemId,
                NetBIOSName = netBIOSName,
                DNSName = dnsName,
                Server = server
            };

            var oldRequest = oldRequestId.HasValue ? GetRequestById(oldRequestId.Value) : null;
            var user = GetCurrentUser();
            var owner = (oldRequest != null) ? oldRequest.Owner : user;

            var request = new Request
            {
                Owner = owner,
                User = user,
                BusinessService = businessService,
                ApplicationName = applicationName,
                Virtualization = vir,
                SubmissionDate = System.DateTime.Now,
                OldRequestId = oldRequestId,
                Notes = notes
            };

            if(oldRequest != null)
            {
                request.OriginalRequest = oldRequest.OriginalRequest;
            }
            else
            {
                //request.OriginalRequest = request;
            }

            if (oldRequest != null && user.Id != owner.Id)
            {
                var inheritedPorts = oldRequest.RequestPorts.Where(x => x.Port.UserId != user.Id);

                foreach (var port in inheritedPorts)
                {
                    var requestPort = new RequestPort
                    {
                        Request = request,
                        Port = port.Port
                    };

                    db.RequestPorts.AddObject(requestPort);
                }
            }

            for (int i = 0; i < applicationTypeId.Length; i++)
            {
                var appType = new RequestApplicationType
                {
                    ApplicationTypeId = applicationTypeId[i],
                    Request = request
                };
            }

            db.Requests.AddObject(request);

            return request;
        }