Exemplo n.º 1
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.º 2
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.º 3
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);
        }