Exemplo n.º 1
0
        public static bool EditMachine(int machineId, string machineName, string ipAddress, string username, string password, bool?pingResponsive, int?plantId, int?connectionType)
        {
            bool retVal = false;

            if (machineId != 0)
            {
                using (VpnManagerEntities entities = new VpnManagerEntities())
                {
                    Machine machine = (from m in entities.Machine where m.Id == machineId select m).FirstOrDefault();

                    if (machine != null)
                    {
                        machine.IdPlant   = plantId.Value;
                        machine.Name      = machineName;
                        machine.IpAddress = ipAddress;
                        machine.Username  = username;
                        machine.Password  = password;
                        machine.IdPreferredConnectionType = connectionType.Value;
                        machine.PingResponseEnabled       = pingResponsive;


                        retVal = entities.SaveChanges() > 0;
                    }
                }
            }


            return(retVal);
        }
Exemplo n.º 2
0
 public static void AddLog(LogConenction obj)
 {
     using (VpnManagerEntities entities = new VpnManagerEntities())
     {
         entities.LogConenction.Add(obj);
         entities.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public static void UpdateLog(LogConenction obj)
 {
     using (VpnManagerEntities entities = new VpnManagerEntities())
     {
         // entities.LogConenction.Add(obj);
         LogConenction _log = (from x in entities.LogConenction where x.Id == obj.Id select x).FirstOrDefault();
         _log.ConncetionSuccesful = obj.ConncetionSuccesful;
         entities.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public static bool AddExtensionObject(int targetId, int table, string name, string value)
        {
            bool retVal = false;

            if (table != null)
            {
                using (VpnManagerEntities entities = new VpnManagerEntities())
                {
                    var checkedTargetId = 0;
                    var targetTable     = string.Empty;

                    switch (table)
                    {
                    case (int)TargetTable.VpnType:
                        checkedTargetId = (from vpn in entities.VpnType where vpn.Id == targetId select vpn.Id).FirstOrDefault();
                        targetTable     = TargetTable.VpnType.ToString();
                        break;

                    case (int)TargetTable.Machine:
                        checkedTargetId = (from machine in entities.Machine where machine.Id == targetId select machine.Id).FirstOrDefault();
                        targetTable     = TargetTable.Machine.ToString();
                        break;

                    case (int)TargetTable.Customer:
                        checkedTargetId = (from customer in entities.Customer where customer.Id == targetId select customer.Id).FirstOrDefault();
                        targetTable     = TargetTable.Customer.ToString();
                        break;

                    case (int)TargetTable.Plant:
                        checkedTargetId = (from plant in entities.Plant where plant.Id == targetId select plant.Id).FirstOrDefault();
                        targetTable     = TargetTable.Plant.ToString();
                        break;
                    }

                    if (checkedTargetId != 0)
                    {
                        ExtensionObjects eObj = new ExtensionObjects();
                        eObj.Name            = name;
                        eObj.Value           = value;
                        eObj.IdTargetElement = targetId;
                        eObj.TargetTableName = targetTable;
                        entities.ExtensionObjects.Add(eObj);
                    }

                    retVal = entities.SaveChanges() > 0;
                }
            }



            return(retVal);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Delete the extension obj from the passe id (Id of the table Extension objects)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DeleteExtensionObject(int id)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                ExtensionObjects eobj = (from extObj in entities.ExtensionObjects where extObj.Id == id select extObj).FirstOrDefault();
                if (eobj != null)
                {
                    entities.ExtensionObjects.Remove(eobj);
                    retVal = entities.SaveChanges() > 0;
                }
            }
            return(retVal);
        }
Exemplo n.º 6
0
        public static bool InsertNewConnectionType(string name)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                ConnectionType conn = new ConnectionType();
                conn.Name = name;

                entities.ConnectionType.Add(conn);
                retVal = entities.SaveChanges() > 0;
            }

            return(retVal);
        }
Exemplo n.º 7
0
        public static bool DeleteMachine(int machineId)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                Machine m = (from machines in entities.Machine where machines.Id == machineId select machines).FirstOrDefault();
                if (m != null)
                {
                    entities.Machine.Remove(m);

                    retVal = entities.SaveChanges() > 0;
                }
            }
            return(retVal);
        }
Exemplo n.º 8
0
        public static bool DeletePlant(int plantId)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                Plant p = (from plants in entities.Plant where plants.Id == plantId select plants).FirstOrDefault();
                if (p != null)
                {
                    entities.Plant.Remove(p);

                    retVal = entities.SaveChanges() > 0;
                }
            }
            return(retVal);
        }
Exemplo n.º 9
0
        public static bool DeleteExtensionObject(int targetId, TargetTable table, string name)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                ExtensionObjects eobj = (from extObj in entities.ExtensionObjects
                                         where extObj.TargetTableName == table.ToString() && extObj.IdTargetElement == targetId && extObj.Name == name
                                         select extObj).FirstOrDefault();
                if (eobj != null)
                {
                    entities.ExtensionObjects.Remove(eobj);
                    retVal = entities.SaveChanges() > 0;
                }
            }
            return(retVal);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Add a new plant from the passed params
        /// </summary>
        /// <param name="name">Name of the plant (CocaCola Femsa)</param>
        /// <param name="connectionType">The id of VPN connection Type</param>
        /// <param name="serverAddress">Ip or public address to connect with</param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool InsertNewPlant(string name, int connectionType, string serverAddress, string username, string password)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                Plant p = new Plant();
                p.Id_Customer      = (int)(from s in entities.Customer where s.Name.Contains(name) select s.Id).FirstOrDefault();
                p.Name             = name;
                p.IdConnectionType = connectionType;
                p.ServerAddress    = serverAddress;
                p.Username         = username;
                p.Password         = password;
                entities.Plant.Add(p);
                retVal = entities.SaveChanges() > 0;
            }

            return(retVal);
        }
Exemplo n.º 11
0
        public static bool EditVpnType(int connectioTypeId, string name)
        {
            bool retVal = false;

            if (connectioTypeId != 0 && !string.IsNullOrEmpty(name))
            {
                using (VpnManagerEntities entities = new VpnManagerEntities())
                {
                    VpnType conn = (from ct in entities.VpnType where ct.Id == connectioTypeId select ct).FirstOrDefault();
                    if (conn != null)
                    {
                        conn.Name = name;

                        retVal = entities.SaveChanges() > 0;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Add a new machine into the machine list to the passed plant and with the specified data
        /// </summary>
        /// <param name="plantId"></param>
        /// <param name="machineName"></param>
        /// <param name="ipAddress"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="pingResponsive"></param>
        /// <param name="connectionType"></param>
        /// <returns></returns>
        public static bool InsertNewMachine(int plantId, string machineName, string ipAddress, string username, string password, bool?pingResponsive, int?connectionType)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                Machine m = new Machine();
                m.IdPlant                   = plantId;
                m.Name                      = machineName;
                m.IpAddress                 = ipAddress;
                m.Username                  = username;
                m.Password                  = password;
                m.PingResponseEnabled       = pingResponsive;
                m.IdPreferredConnectionType = connectionType.Value;

                entities.Machine.Add(m);
                retVal = entities.SaveChanges() > 0;
            }

            return(retVal);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Edit the plant with the passed params
        /// </summary>
        /// <param name="plantId"></param>
        /// <param name="name"></param>
        /// <param name="connectionType"></param>
        /// <param name="serverAddress"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool EditPlant(int plantId, string name, int connectionType, string serverAddress, string username, string password)
        {
            bool retVal = false;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                Plant p = (from plants in entities.Plant where plants.Id == plantId select plants).FirstOrDefault();
                if (p != null)
                {
                    p.Name             = name;
                    p.IdConnectionType = connectionType;
                    p.ServerAddress    = serverAddress;
                    p.Username         = username;
                    p.Password         = password;
                    p.Id_Customer      = (int)(from s in entities.Customer where s.Name.Contains(name) select s.Id).FirstOrDefault();
                    retVal             = entities.SaveChanges() > 0;
                }
            }

            return(retVal);
        }