public ActionResult CreatePost(MachineLoginCredential machinelogincredential, int?[] MachinesList)
        {
            MachinesManagement machineManagment = new MachinesManagement();

            if (ModelState.IsValid)
            {
                db.MachineLoginCredentials.Add(machinelogincredential);
                db.SaveChanges();

                if (MachinesList != null)
                {
                    machinelogincredential.Machines = new List<Machine>();
                    foreach (int machineID in MachinesList)
                    {
                        var machine = db.Machines.Find(machineID);
                        //ignore modifying the machine if the daemon is running
                        if (machine.StatusEnum != global::Aneka.PAL.Management.Model.DaemonProbeStatus.ServiceStarted)
                        {
                            machineManagment.UpdateMachineStatus((int)machineID, machinelogincredential);
                            machinelogincredential.Machines.Add(machine);
                        }

                    }
                    db.SaveChanges();
                }

                return RedirectToAction("Dashboard", "Home");
            }

            return View("~/Views/Home/Dashboard.cshtml", machinelogincredential);
        }
        /// <summary>
        /// Get the latest Machine Status, and update it in the database
        /// </summary>
        /// <param name="machineID">Machine ID</param>
        /// <param name="login">Machine Login Credential</param>
        /// <returns>Machine Status</returns>
        public DaemonProbeResult UpdateMachineStatus(int machineID, MachineLoginCredential login)
        {
            DaemonProbeResult probeResult = new DaemonProbeResult(DaemonProbeStatus.Unknown,null);
            CloudWebPortal.Areas.Aneka.Models.Machine machine = db.Machines.Find(machineID);
            if (pingMachine(machine.IP))
            {
                global::Aneka.PAL.Management.Model.Machine daemonMachine = ToAnekaPALMachineWithLogin(machine, login);
                probeResult = ProbeMachine(daemonMachine);

                machine.IP = daemonMachine.Address;
                machine.StatusEnum = probeResult.Status;

                db.SaveChanges();
            }
            else
            {
                machine.StatusEnum = DaemonProbeStatus.NetworkNotReachable;
                db.SaveChanges();
            }
            return probeResult;
        }
 /// <summary>
 /// Convert the Machine entity from CloudWebPortal.Areas.Aneka.Models.Machine to Aneka.PAL.Management.Model.Machine by passing the Machine Login Credential
 /// </summary>
 /// <param name="machine">CloudWebPortal.Areas.Aneka.Models.Machine</param>
 /// <param name="login">Machine Login Credential</param>
 /// <returns>Aneka.PAL.Management.Model.Machine</returns>
 public global::Aneka.PAL.Management.Model.Machine ToAnekaPALMachineWithLogin(CloudWebPortal.Areas.Aneka.Models.Machine machine, MachineLoginCredential login)
 {
     global::Aneka.PAL.Management.Model.Machine result = new global::Aneka.PAL.Management.Model.Machine(machine.IP);
     result.DaemonUri = ResolveURL(string.Format("tcp://{0}:{1}/daemon", result.Address, machine.Daemon.Port));
     if (login != null)
         result.UserAccount = new global::Aneka.PAL.Management.Model.UserAccount(login.Username, login.Password);
     result.Platform = machine.Platform.Platform;
     result.HomeDirectory = machine.Daemon.Directory + "\\LocalRepository\\Container";
     return result;
 }
        public ActionResult EditPost(MachineLoginCredential machinelogincredential, int?[] MachinesList)
        {
            MachinesManagement machineManagment = new MachinesManagement();

            if (ModelState.IsValid)
            {

                db.Entry(machinelogincredential).State = EntityState.Modified;
                db.SaveChanges();

                //Machines List
                var machinelogincredential2 = db.MachineLoginCredentials.Include(x => x.Machines).Where(x => x.MachineLoginCredentialId == machinelogincredential.MachineLoginCredentialId).First();

                if (machinelogincredential2.Machines == null)
                    machinelogincredential2.Machines = new List<Machine>();

                foreach (Machine m in db.Machines.ToList())
                    machinelogincredential2.Machines.Remove(m);
                db.SaveChanges();

                if (MachinesList != null)
                {
                    foreach (int machineID in MachinesList)
                    {
                        var machine = db.Machines.Find(machineID);
                        //ignore modifying the machine if the daemon is running
                        if (machine.StatusEnum != global::Aneka.PAL.Management.Model.DaemonProbeStatus.ServiceStarted)
                        {
                            machineManagment.UpdateMachineStatus((int)machineID, machinelogincredential);
                            machinelogincredential.Machines.Add(machine);
                        }
                    }
                    db.SaveChanges();
                }

                return RedirectToAction("Dashboard", "Home");
            }
            return View("~/Views/Home/Dashboard.cshtml",machinelogincredential);
        }