RemoveVariableUsage() public méthode

Detaches the data attribute and the data structure that were linked by the variable and then deletes the variable from the database.
If the variable is referenced by any DataValue the method fails to delete the variable. Also, all the parameters associated to the variable will be deleted.
public RemoveVariableUsage ( Variable usage ) : void
usage BExIS.Dlm.Entities.DataStructure.Variable The variable object to be deleted.
Résultat void
 public ActionResult deleteDataStructure(long Id, string cssId = "")
 {
     MessageModel DataStructureDeleteValidation = MessageModel.validateDataStructureDelete(Id);
     if (DataStructureDeleteValidation.hasMessage)
     {
         return PartialView("_messageWindow", DataStructureDeleteValidation);
     }
     else
     {
         DataStructureManager dataStructureManager = new DataStructureManager();
         if (dataStructureManager.StructuredDataStructureRepo.Get(Id) != null)
         {
             StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);
             DataStructureIO.deleteTemplate(dataStructure.Id);
             foreach (Variable v in dataStructure.Variables)
             {
                 dataStructureManager.RemoveVariableUsage(v);
             }
             dataStructureManager.DeleteStructuredDataStructure(dataStructure);
             LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
         }
         else
         {
             UnStructuredDataStructure dataStructure = dataStructureManager.UnStructuredDataStructureRepo.Get(Id);
             dataStructureManager.DeleteUnStructuredDataStructure(dataStructure);
             LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
         }
         return PartialView("_message", new MessageModel()
         {
             Message = "DataStructure" + Id + "deleted",
             hasMessage = false,
             CssId = "deleted"
         });
     }
 }
        public ActionResult storeVariables(long Id, storeVariableStruct[] variables)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();
            StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);
            MessageModel returnObject = new MessageModel();
            MessageModel messageModel = MessageModel.validateDataStructureInUse(dataStructure.Id, dataStructure);
            if (messageModel.hasMessage)
            {
                foreach (Variable v in dataStructure.Variables)
                {
                    if (variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                    {
                        v.Description = variables.Where(svs => svs.Id == v.Id).FirstOrDefault().Description;
                        dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                    }
                }
                return PartialView("_messageWindow", messageModel);
            }

            if (variables != null && variables.Count() > 0)
            {
                Variable variable = new Variable();
                List<long> order = new List<long>();

                foreach (Variable v in dataStructure.Variables)
                {
                    if (!variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        dataStructureManager.RemoveVariableUsage(v);
                }

                foreach (storeVariableStruct svs in variables.Where(svs => svs.Id == 0).ToList())
                {
                    if (svs.Lable == null)
                        svs.Lable = "";
                    if (svs.Description == null)
                        svs.Description = "";

                    DataAttribute dataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                    if (dataAttribute != null)
                    {
                        variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), new UnitManager().Repo.Get(svs.UnitId));
                        svs.Id = variable.Id;
                    }
                    else
                    {
                        returnObject = new MessageModel()
                        {
                            hasMessage = true,
                            Message = "Not all Variables are stored.",
                            CssId = "0"
                        };
                    }
                }
                dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);

                variables = variables.Where(v => v.Id != 0).ToArray();

                foreach (storeVariableStruct svs in variables.Where(svs => svs.Id != 0).ToList())
                {
                    if (svs.Lable == null)
                        svs.Lable = "";
                    if (svs.Description == null)
                        svs.Description = "";

                    variable = dataStructure.Variables.Where(v => v.Id == svs.Id).FirstOrDefault();
                    if (variable != null)
                    {
                        variable.Label = svs.Lable.Trim();
                        variable.Description = svs.Description.Trim();
                        variable.Unit = new UnitManager().Repo.Get(svs.UnitId);
                        variable.DataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                        variable.IsValueOptional = svs.isOptional;
                    }
                }

                dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList());
            }
            else
            {
                foreach (Variable v in dataStructure.Variables)
                {
                    dataStructureManager.RemoveVariableUsage(v);
                }
            }
            LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored.");
            return Json(returnObject, JsonRequestBehavior.AllowGet);
        }