Ejemplo n.º 1
0
        public ActionResult deleteDataStructure(long Id, string cssId = "")
        {
            MessageModel DataStructureDeleteValidation = MessageModel.validateDataStructureDelete(Id);

            if (DataStructureDeleteValidation.hasMessage)
            {
                return(PartialView("_messageWindow", DataStructureDeleteValidation));
            }
            else
            {
                DataStructureManager dataStructureManager = null;
                MissingValueManager  missingValueManager  = null;

                try
                {
                    dataStructureManager = new DataStructureManager();
                    missingValueManager  = new MissingValueManager();
                    var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>();
                    StructuredDataStructure structuredDataStructure = structureRepo.Get(Id);

                    if (structuredDataStructure != null) // Javad: This one retrieves the entity withough using it, and then the next line agian fetches the same!
                    {
                        DataStructureIO.deleteTemplate(structuredDataStructure.Id);
                        foreach (Variable v in structuredDataStructure.Variables)
                        {
                            List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(v.Id)).ToList();
                            foreach (MissingValue mv in missingValues)
                            {
                                missingValueManager.Delete(mv);
                            }
                            dataStructureManager.RemoveVariableUsage(v);
                        }
                        dataStructureManager.DeleteStructuredDataStructure(structuredDataStructure);
                        LoggerFactory.LogData(structuredDataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
                    }
                    else
                    {
                        var unStructureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <UnStructuredDataStructure>();
                        UnStructuredDataStructure unStructuredDataStructure = unStructureRepo.Get(Id);
                        dataStructureManager.DeleteUnStructuredDataStructure(unStructuredDataStructure);
                        LoggerFactory.LogData(unStructuredDataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
                    }
                    return(PartialView("_message", new MessageModel()
                    {
                        Message = "DataStructure" + Id + "deleted",
                        hasMessage = false,
                        CssId = "deleted"
                    }));
                }
                finally
                {
                    dataStructureManager.Dispose();
                    missingValueManager.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public void PurgeAllDataStructures()
        {
            var manager = new DataStructureManager();

            try
            {
                var sts = manager.StructuredDataStructureRepo.Query().ToList();
                sts.ForEach(p => manager.DeleteStructuredDataStructure(p));
                //manager.DeleteStructuredDataStructure(sts); // Does not delete all the entities of the list!!!! Javad, 29.08.2018

                var unsts = manager.UnStructuredDataStructureRepo.Query().ToList();
                unsts.ForEach(p => manager.DeleteUnStructuredDataStructure(p));
                //manager.DeleteUnStructuredDataStructure(unsts);
            }
            finally
            {
                manager.Dispose();
            }
        }