public ActionResult editAttribute(DataAttributeModel Model) { ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Manage Data Attributes", this.Session.GetTenant()); DataContainerManager dataAttributeManager = new DataContainerManager(); IList<DataAttribute> DataAttributeList = dataAttributeManager.DataAttributeRepo.Get(); long tempUnitId = Convert.ToInt64(Model.Unit.Id); long tempDataTypeId = Convert.ToInt64(Model.DataType.Id); Model.Id = Model.Id; Model.ShortName = cutSpaces(Model.ShortName); Model.Name = cutSpaces(Model.Name); Model.Description = cutSpaces(Model.Description); //if (Model.DomainConstraints.Count > 0) //{ // if (Model.DomainConstraints. != null && Model.DomainItems.Count > 0) // { // Model.DomainConstraints.FirstOrDefault().DomainItems = clearEmptyItems(Model.DomainItems); // } //} if (Model.Name == "" | Model.Name == null) { Session["nameMsg"] = "invalid Name"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } else { bool nameNotExist = DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).Count().Equals(0); if (Model.Id == 0) { if (nameNotExist) { UnitManager UM = new UnitManager(); Unit unit = new Unit(); DataTypeManager DTM = new DataTypeManager(); DataType dataType = new DataType(); DataContainerManager DAM = new DataContainerManager(); DataAttribute temp = new DataAttribute(); if(UM.Repo.Get(tempUnitId)!= null) unit = UM.Repo.Get(tempUnitId); else unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); if (DTM.Repo.Get(tempDataTypeId) != null) dataType = DTM.Repo.Get(tempDataTypeId); else dataType = DTM.Repo.Get().ToList().FirstOrDefault(); temp = DAM.CreateDataAttribute(Model.ShortName, Model.Name, Model.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min !=null || Model.RangeConstraints.FirstOrDefault().Max !=null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0 )) temp = storeConstraint(Model.RangeConstraints.First(), temp); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) temp = storeConstraint(Model.PatternConstraints.First(), temp); if (Model.DomainConstraints.Count > 0) { foreach (DomainConstraintModel d in Model.DomainConstraints) { temp = storeConstraint(d, temp); } } #endregion temp = DAM.UpdateDataAttribute(temp); } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } else { if (nameNotExist || DataAttributeList.Where(p => p.Name.Equals(Model.Name)).ToList().First().Id == Model.Id) { DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First(); if (!attributeInUse(dataAttribute)) { DataContainerManager DAM = new DataContainerManager(); dataAttribute.Name = cutSpaces(Model.Name); dataAttribute.ShortName = Model.ShortName; dataAttribute.Description = Model.Description; UnitManager UM = new UnitManager(); if (UM.Repo.Get(tempUnitId) != null) dataAttribute.Unit = UM.Repo.Get(tempUnitId); else dataAttribute.Unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); DataTypeManager DTM = new DataTypeManager(); if (DTM.Repo.Get(tempDataTypeId) != null) dataAttribute.DataType = DTM.Repo.Get(tempDataTypeId); else dataAttribute.DataType = DTM.Repo.Get().ToList().FirstOrDefault(); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0)) dataAttribute = storeConstraint(Model.RangeConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.RangeConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) dataAttribute = storeConstraint(Model.PatternConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.PatternConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.DomainConstraints.FirstOrDefault().Terms)) dataAttribute = storeConstraint(Model.DomainConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.DomainConstraints.First().Id, dataAttribute); #endregion DAM.UpdateDataAttribute(dataAttribute); } } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } } Session["Window"] = false; return RedirectToAction("AttributeManager"); }
public ActionResult deletConstraint(long Id, long attributeId) { if (Id != 0 && attributeId != 0) { DataContainerManager dam = new DataContainerManager(); DataAttribute dataattribute = dam.DataAttributeRepo.Get(attributeId); Constraint constraint = dam.DataAttributeRepo.Get(attributeId).Constraints.Where(c => c.Id == Id).FirstOrDefault(); foreach (Constraint c in dataattribute.Constraints.ToList()) { if (c.Id == constraint.Id) { dataattribute.Constraints.Remove(c); break; } } dataattribute = dam.UpdateDataAttribute(dataattribute); //if (constraint is RangeConstraint) // dam.RemoveConstraint((RangeConstraint)constraint); } return RedirectToAction("openAttributeWindow", new { Id = attributeId, showConstraints = true }); }
public MessageModel storeAtttribute(long Id, string Name, long unitId, long dataTypeId, string Description = "", string cssId = "", bool inUse = false) { Name = Server.UrlDecode(Name); Description = Server.UrlDecode(Description); MessageModel DataStructureValidation = MessageModel.validateAttributeInUse(Id); if (DataStructureValidation.hasMessage && inUse == false) { return DataStructureValidation; } else { DataStructureValidation = MessageModel.validateAttributeName(Id, Name, cssId); if (DataStructureValidation.hasMessage) { return DataStructureValidation; } else { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute dataAttribute; if (Id == 0) { Unit unit = new UnitManager().Repo.Get(unitId); DataType dataType = new DataTypeManager().Repo.Get(dataTypeId); dataAttribute = dataAttributeManager.CreateDataAttribute(Name, Name, Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); return new MessageModel() { Message = dataAttribute.Id.ToString(), hasMessage = false, CssId = "refresh" }; } else { dataAttribute = dataAttributeManager.DataAttributeRepo.Get(Id); dataAttribute.Name = Name; dataAttribute.Description = Description; dataAttribute = dataAttributeManager.UpdateDataAttribute(dataAttribute); return new MessageModel() { Message = Id.ToString(), hasMessage = false, CssId = "refresh" }; } } } }