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(); } } }
public bool _checkMissingValueName(long variableId, MissingValueStruct missingValue) { MissingValueManager missingValueManager = null; try { missingValueManager = new MissingValueManager(); List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(variableId)).ToList(); foreach (MissingValue mv in missingValues) { if (mv.DisplayName == missingValue.DisplayName && mv.Id != missingValue.Id) { return(false); } } return(true); } finally { missingValueManager.Dispose(); } }
public ActionResult _getMissingValueElement(long missinValueId = 0) { MissingValueStruct missingValueStruct = new MissingValueStruct(); if (missinValueId > 0) { MissingValueManager missingValueManager = null; try { missingValueManager = new MissingValueManager(); MissingValue missingValue = missingValueManager.Repo.Get(missinValueId); if (missingValue == null) { return(null); } else { missingValueStruct = new MissingValueStruct() { Id = missingValue.Id, DisplayName = missingValue.DisplayName, Description = missingValue.Description, Placeholder = missingValue.Placeholder }; } } catch { return(null); } finally { missingValueManager.Dispose(); } } return(PartialView("_missingValueElement", missingValueStruct)); }
public ActionResult storeVariables(long Id, storeVariableStruct[] variables) { DataStructureManager dataStructureManager = null; DataContainerManager dataContainerManager = null; MissingValueManager missingValueManager = null; UnitManager um = null; try { dataStructureManager = new DataStructureManager(); missingValueManager = new MissingValueManager(); dataContainerManager = new DataContainerManager(); um = new UnitManager(); var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>(); StructuredDataStructure dataStructure = structureRepo.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.Any()) { 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)) { 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); } } 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 = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); if (dataAttribute != null) { variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), um.Repo.Get(svs.UnitId)); svs.Id = variable.Id; foreach (MissingValueStruct mvs in svs.MissingValues) { if (mvs.Id == 0) { if (String.IsNullOrEmpty(mvs.Placeholder)) { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable); } else { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder); } } } } else { returnObject = new MessageModel() { hasMessage = true, Message = "Not all Variables are stored.", CssId = "0" }; } } //dataStructure = structureRepo.Get(Id); // Javad: why it is needed? variables = variables.Where(v => v.Id != 0).ToArray(); MissingValue missingValue = new MissingValue(); 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 = um.Repo.Get(svs.UnitId); variable.DataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); variable.IsValueOptional = svs.isOptional; List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(svs.Id)).ToList(); foreach (MissingValue mv in missingValues) { if (!svs.MissingValues.Select(mvs => mvs.Id).Contains(mv.Id)) { missingValueManager.Delete(mv); } } foreach (MissingValueStruct mvs in svs.MissingValues) { if (mvs.Id == 0) { if (String.IsNullOrEmpty(mvs.Placeholder)) { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable); } else { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder); } } else if (mvs.Id > 0) { missingValue = missingValues.Where(mv => mv.Id.Equals(mvs.Id)).FirstOrDefault(); if (missingValue != null) { missingValue.DisplayName = mvs.DisplayName; missingValue.Description = mvs.Description; missingValue.Placeholder = mvs.Placeholder; missingValueManager.Update(missingValue); } } } } } dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure); DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList()); } else { foreach (Variable v in dataStructure.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); } } LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored."); return(Json(returnObject, JsonRequestBehavior.AllowGet)); } finally { dataStructureManager.Dispose(); dataContainerManager.Dispose(); um.Dispose(); missingValueManager.Dispose(); } }
public VariablePreviewStruct fill(Variable variable, bool getConstraints) { MissingValueManager missingValueManager = null; try { missingValueManager = new MissingValueManager(); List <MissingValue> temp = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(variable.Id)).ToList(); variable.Unit = variable.Unit ?? new Unit(); variable.Unit.Dimension = variable.Unit.Dimension ?? new Dimension(); variable.DataAttribute = variable.DataAttribute ?? new DataAttribute(); variable.DataAttribute.DataType = variable.DataAttribute.DataType ?? new DataType(); this.Id = variable.Id; this.Name = variable.Label; this.Description = variable.Description; this.isOptional = variable.IsValueOptional; this.Unit.Id = variable.Unit.Id; this.Unit.Name = variable.Unit.Name; this.Unit.Description = variable.Unit.Abbreviation; this.convertibleUnits = getUnitListByDimenstionAndDataType(variable.Unit.Dimension.Id, variable.DataAttribute.DataType.Id); this.DataType = variable.DataAttribute.DataType.Name; DataTypeDisplayPattern displayPattern = DataTypeDisplayPattern.Materialize(variable.DataAttribute.DataType.Extra); if (displayPattern != null) { this.DisplayPattern = displayPattern.StringPattern; } TypeCode typeCode = TypeCode.String; foreach (TypeCode tc in Enum.GetValues(typeof(DataTypeCode))) { if (tc.ToString() == variable.DataAttribute.DataType.SystemType) { typeCode = tc; break; } } if (missingValueManager.getPlaceholder(typeCode, this.Id) != null && temp.Any()) { foreach (MissingValue mv in temp) { this.MissingValues.Add(new MissingValueStruct() { Id = mv.Id, DisplayName = mv.DisplayName, Description = mv.Description, Placeholder = mv.Placeholder }); } } else if (missingValueManager.getPlaceholder(typeCode, this.Id) == null) { this.MissingValues = null; } if (getConstraints) { if (variable.DataAttribute.Constraints != null) { foreach (Constraint c in variable.DataAttribute.Constraints) { c.Materialize(); this.Constraints.Add(c.Id, c.FormalDescription); } } } this.Attribute = Attribute.fill(variable.DataAttribute, false); return(this); } finally { missingValueManager.Dispose(); } }