public void SendNewRequestMail(Request request)
        {
            var subject = string.Format("{0} ({1}) Created by {2} {3}", request.ApplicationName, request.BusinessService, request.User.FirstName, request.User.LastName);
            var body = LoadMailTemplate("NewRequestMail", new {
                User = request.User,
                Url = string.Format("{0}/request/{1}", domainName, request.Id)
            });

            var to = GetUsersMailAddress(repo.GetUsersInRole("SecurityMails"));
            var cc = GetUsersMailAddress(repo.GetUsersInRole("CommunicationMails"));

            SendMail(to, cc, subject, body);
        }
        public void SendRequestApprovedMail(Request request)
        {
            var action = repo.GetLastSecurityAction(request);

            var subject = string.Format("{0} ({1}) Approved by {2} {3}", request.ApplicationName, request.BusinessService, action.User.FirstName, action.User.LastName);
            var body = LoadMailTemplate("ApprovedRequestMail", new {
                User = action.User,
                Url = string.Format("{0}/request/{1}", domainName, request.Id),
                Vlan = action.Vlan
            });

            var to = GetUsersMailAddress(new User[] { request.User });
            var cc = GetUsersMailAddress(repo.GetUsersInRole("SecurityMails")).Union(
                GetUsersMailAddress(repo.GetUsersInRole("CommunicationMails"))).Union(
                GetUsersMailAddress(new User[] { request.Owner }));

            SendMail(to, cc, subject, body);
        }
        public RequestFormViewModel(Request request, User user, IEnumerable<ApplicationType> applicationTypes, IEnumerable<Location> locations, 
            IEnumerable<ServerType> serverTypes, IEnumerable<PortType> portTypes, IEnumerable<IPRequestForm.Models.OperatingSystem> operatingSystems, 
            RequestFormViews requestFormView)
        {
            this.RequestFormView = requestFormView;
            this.OperatingSystems = operatingSystems;
            this.PortTypes = portTypes;
            this.ServerTypes = serverTypes;
            this.Locations = locations;
            this.ApplicationTypes = applicationTypes;

            RequestFormView = requestFormView;

            RequestUser = request.User;

            this.RequestOwner = request.Owner;

            RequestId = request.Id;

            Date = request.SubmissionDate;
            BusinessService = request.BusinessService;
            ApplicationName = request.ApplicationName;

            RequestApplicationTypes = request.RequestApplicationTypes.Select(i => i.ApplicationType);

            NetBIOSName = request.Virtualization.NetBIOSName;
            DNSName = request.Virtualization.DNSName;

            Notes = request.Notes;

            Deleted = request.Deleted;
            DeletedDate = request.DeleteDate;

            ServerLocation = request.Virtualization.Server.Location;
            ServerType = request.Virtualization.Server.ServerType;

            ServerTypeName = (ServerTypes)request.Virtualization.Server.ServerType.Id;

            if (ServerTypeName == IPRequestForm.ViewModels.ServerTypes.Blades)
            {
                RackChassisPort = request.Virtualization.Server.BladeChassi.RackChassisPort;
                NICTeaming = request.Virtualization.Server.BladeChassi.NICTeaming;
            }

            this.OperatingSystem = request.Virtualization.OperatingSystem;

            //ShowPolicies = (!Roles.IsUserInRole("Users") || request.UserId == user.Id);

            ShowPolicies = true;

            var reqs = request.RequestPorts.AsQueryable();

            if (user.Id != request.OwnerId & !Roles.IsUserInRole("Security") & !Roles.IsUserInRole("Communication"))
            {
                reqs = reqs.Where(x => x.Port.UserId == user.Id);
            }

            Policies = reqs.Select(i => new Policy
            {
                Id = i.Port.Id,
                IPAddress = CommonFunctions.IPDotted(i.Port.IP.Address),
                SubnetMaskBits = i.Port.SubnetMaskId != null ? (int?)BitConverter.ToUInt32(i.Port.SubnetMask.Address.Reverse().ToArray(), 0).BitsSetCountNaive() : null,
                PortType = i.Port.PortType,
                StartPortNumber = i.Port.StartPortNumber,
                EndPortNumber = i.Port.EndPortNumber,
                PortDirection = (PortDirections)i.Port.PortDirection.Id,
                StartDate = i.Port.StartDate,
                EndDate = i.Port.EndDate
            });
        }
 public RequestFormViewModel(Request request, User user, RequestFormViews requestFormView)
     : this(request, user, null, null, null, null, null, requestFormView)
 {
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Requests EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRequests(Request request)
 {
     base.AddObject("Requests", request);
 }
 /// <summary>
 /// Create a new Request object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="applicationName">Initial value of the ApplicationName property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="deleted">Initial value of the Deleted property.</param>
 /// <param name="submissionDate">Initial value of the SubmissionDate property.</param>
 /// <param name="virtualizationId">Initial value of the VirtualizationId property.</param>
 /// <param name="ownerId">Initial value of the OwnerId property.</param>
 public static Request CreateRequest(global::System.Int32 id, global::System.String applicationName, global::System.Int32 userId, global::System.Boolean deleted, global::System.DateTime submissionDate, global::System.Int32 virtualizationId, global::System.Int32 ownerId)
 {
     Request request = new Request();
     request.Id = id;
     request.ApplicationName = applicationName;
     request.UserId = userId;
     request.Deleted = deleted;
     request.SubmissionDate = submissionDate;
     request.VirtualizationId = virtualizationId;
     request.OwnerId = ownerId;
     return request;
 }
        public RequestViewModel(User user, Request request, IEnumerable<Vlan> vlans, IEnumerable<Switch> switches, 
            IEnumerable<SwitchModule> switchModules, IEnumerable<SwitchPort> switchPorts, RequestFilters requestFilter)
        {
            RequestFilter = requestFilter;
            User = user;
            Switches = switches;
            SwitchModules = switchModules;
            SwitchPorts = switchPorts;

            var repo = new RequestRepository();

            OlderRequest = repo.GetOlderRequest(request);

            NewerRequest = repo.GetNewerRequest(request);

            Request = new RequestFormViewModel(request, user, RequestFormViews.View);

            var lastApprovedAction = repo.GetLastApprovedSecurityAction(request);

            if (lastApprovedAction != null)
            {
                Vlan = lastApprovedAction.Vlan;
            }

            // Get the last security action of this request version.
            if (request.SecurityActions.Count > 0)
            {
                LastSecurityAction = request.SecurityActions.OrderByDescending(x => x.Id).First();
            }

            // Get the last communication action of this request version.
            if (request.CommunicationActions.Count > 0)
            {
                LastCommunicationAction = request.CommunicationActions.OrderByDescending(x => x.Id).First();

                Notes = LastCommunicationAction.Notes;
            }

            var lastCompletedAction = repo.GetLastCompletedCommunicationAction(request);

            if (lastCompletedAction != null)
            {
                IPAddress = CommonFunctions.IPDotted(lastCompletedAction.ServerIP.IP.Address);

                if (lastCompletedAction.Completed == true)
                {
                    if (Request.ServerType.Id == (int)ServerTypes.Standalone)
                    {
                        SwitchIPAddress = CommonFunctions.IPDotted(lastCompletedAction.ServerIP.SwitchPort.SwitchModule.Switch.IP.Address);
                        SwitchName = lastCompletedAction.ServerIP.SwitchPort.SwitchModule.Switch.Name;
                        SwitchNumber = lastCompletedAction.ServerIP.SwitchPort.SwitchModule.Switch.StackableNumber;

                        SwitchModuleNumber = lastCompletedAction.ServerIP.SwitchPort.SwitchModule.Number;
                        SwitchPortNumber = lastCompletedAction.ServerIP.SwitchPort.Port;
                    }
                }
            }

            Vlans = vlans;

            Logs = new List<Log>();

            var reqs = repo.GetRequestUpdates(request.OriginalRequest).ToList();

            Logs.AddRange(reqs.Select(x => new Log
            {
                User = x.User,
                Date = x.SubmissionDate,
                Notes = x.Notes,
                LogAction = (x.Id == x.OriginalId) ? LogActions.RequestCreated : LogActions.RequestUpdated
            }));

            Logs.AddRange(reqs.SelectMany(x => x.SecurityActions.Select(action => new Log
            {
                User = action.User,
                Date = action.Date,
                Notes = action.Notes,
                LogAction = action.Approved == true ? LogActions.SecurityApproved :
                            (action.Approved == false ? LogActions.SecurityRejected :
                            (action.Assigned ? LogActions.SecurityAssigned :
                            LogActions.SecurityReleased))
            })));

            Logs.AddRange(reqs.SelectMany(x => x.CommunicationActions.Select(action => new Log
            {
                User = action.User,
                Date = action.Date,
                Notes = action.Notes,
                LogAction = action.Completed == true ? LogActions.CommunicationCompleted :
                            (action.Completed == false ? LogActions.CommunicationProcessing :
                            (action.Assigned ? LogActions.CommunicationAssigned :
                            LogActions.CommunicationReleased))
            })));

            Logs = Logs.OrderByDescending(x => x.Date).ToList();
        }
 public RequestViewModel(User user, Request request)
     : this(user, request, null, null, null, null, RequestFilters.All)
 {
 }