public async Task <ActionResult> EditAttribute(int pid, int aid, string optionType, IFormCollection fc) { var success = false; var message = string.Empty; var _id = -1; try { if (aid < 1) { var prop = repo.GetGeneratedProperty().Where(x => x.ID == pid).FirstOrDefault(); var att = new GeneratedAttribute { Type = optionType }; var model = ApiHelper.CreateInstance(ApiHelper.GetType(optionType)); await TryUpdateModelAsync(model, model.GetType(), ""); var value = JsonConvert.SerializeObject(model); att.Value = value; prop.Attributes.Add(att); repo.SaveChanges(); _id = att.ID; } else { var att = repo.GetGeneratedAttribute().Where(x => x.ID == aid).FirstOrDefault(); var model = ApiHelper.CreateInstance(ApiHelper.GetType(optionType)); await TryUpdateModelAsync(model, model.GetType(), ""); var value = JsonConvert.SerializeObject(model); att.Value = value; repo.SaveChanges(); _id = att.ID; } } catch (Exception ex) { message = ex.Message; } return(Json(new { success = true, message = message, id = _id })); }
public ActionResult EditAttribute(int id, int pid, string optionType) { var attribute = new GeneratedAttribute(); if (id > -1) { attribute = repo.GetGeneratedAttribute().FirstOrDefault(x => x.ID == id); } ViewBag.pid = pid; ViewBag.aid = id; ViewBag.type = optionType; var modelType = Type.GetType(optionType); I_GeneratedOption model; if (string.IsNullOrEmpty(attribute.Value)) { model = ApiHelper.CreateInstance(modelType) as I_GeneratedOption; } else { model = JsonConvert.DeserializeObject(attribute.Value, modelType) as I_GeneratedOption; } return(View(model)); }
private Property Make() { ValidateMake(); log.Debug("Building property " + name); Property prop = new Property(); prop.Name = name; prop.NodeName = name; prop.Value = value; prop.IsLazy = lazy; prop.Cascade = cascade; prop.PropertyAccessorName = propertyAccessorName; GeneratedAttribute ann = property != null?AttributeHelper.GetFirst <GeneratedAttribute>(property) : null; GenerationTime?generated = ann != null ? ann.Value : null; if (generated != null) { if (!GenerationTime.Never.Equals(generated)) { if (AttributeHelper.IsAttributePresent <VersionAttribute>(property) && GenerationTime.Insert.Equals(generated)) { throw new AnnotationException("[Generated(Insert)] on a [Version] property not allowed, use ALWAYS: " + StringHelper.Qualify(holder.Path, name)); } insertable = false; if (GenerationTime.Always.Equals(generated)) { updatable = false; } prop.Generation = GenerationTimeConverter.Convert(generated.Value); } } //TODO: Natural Id port. //NaturalIdAttribute naturalId = property != null ? AttributeHelper.GetFirst<NaturalIdAttribute>(property) : null; //if (naturalId != null) //{ // if (!naturalId.IsMutable) // { // updatable = false; // } // prop.setNaturalIdentifier(true); //} prop.IsInsertable = insertable; prop.IsUpdateable = updatable; var lockAnn = property != null?AttributeHelper.GetFirst <OptimisticLockAttribute>(property) : null; if (lockAnn != null) { prop.IsOptimisticLocked = !lockAnn.IsExcluded; //TODO this should go to the core as a mapping validation checking if (lockAnn.IsExcluded && (AttributeHelper.IsAttributePresent <VersionAttribute>(property) || AttributeHelper.IsAttributePresent <IdAttribute>(property) || AttributeHelper.IsAttributePresent <EmbeddedIdAttribute>(property))) { throw new AnnotationException( "[OptimisticLock].IsExclude==true incompatible with [Id], [EmbeddedId] and [Version]: " + StringHelper.Qualify(holder.Path, name)); } } log.Info("Cascading " + name + " with " + cascade); return(prop); }
/// <summary> /// It is strongly recommended to call this functions before calling any other function in this class. /// </summary> public GeneratedAttribute Value(string boxIdentity, BoxModuleI boxModule, ColumnInfo columnInfo, AttributeDomainEnum domainType, double from, double to, long countOfCategories) { lock (this) { Dictionary<string, IComparable> cacheSetting = new Dictionary<string, IComparable>(); cacheSetting.Add(Database.DatabaseBoxInfo.typeIdentifier + Database.DatabaseBoxInfo.OdbcConnectionStringPropertyName, columnInfo.dataMatrix.database.odbcConnectionString); cacheSetting.Add(DataMatrix.DataMatrixBoxInfo.typeIdentifier + DataMatrix.DataMatrixBoxInfo.DataMatrixNamePropertyName, columnInfo.dataMatrix.dataMatrixName); cacheSetting.Add(DataMatrix.DataMatrixBoxInfo.typeIdentifier + DataMatrix.DataMatrixBoxInfo.RecordCountPropertyName, columnInfo.dataMatrix.recordsCount); cacheSetting.Add(Column.ColumnBoxInfo.typeIdentifier + Column.ColumnBoxInfo.ColumnSelectExpressionPropertyName, columnInfo.columnSelectExpression); cacheSetting.Add("DomainType", domainType); cacheSetting.Add("From", from); cacheSetting.Add("To", to); cacheSetting.Add("CountOfCategories", countOfCategories); if (IsObsolete(columnInfo.dataMatrix.database.lastReloadInfo, cacheSetting)) { try { value = EquidistantAlgorithm.Generate( domainType, from, to, countOfCategories, columnInfo, boxIdentity); } catch (Ferda.Modules.BadParamsError ex) { value = new GeneratedAttribute(); if (ex.restrictionType == restrictionTypeEnum.DbColumnDataType) { boxModule.OutputMessage( Ferda.ModulesManager.MsgType.Info, "UnsupportedColumnDatatype", "NumericDatatypesSupportedOnly"); } else throw Ferda.Modules.Exceptions.BoxRuntimeError(ex, boxModule.StringIceIdentity, null); } } if (value == null) value = new GeneratedAttribute(); return value; } }
public void DeleteGeneratedAttribute(GeneratedAttribute ga) { throw new NotImplementedException(); //repo.GeneratedAttribute.Remove(ga); }
public void AddGeneratedAttribute(GeneratedAttribute ga) { throw new NotImplementedException(); //repo.GeneratedAttribute.Add(ga); }
/// <summary> /// Generates the attribute. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="dataMatrixName">Name of the data matrix.</param> /// <param name="columnSelectExpression">The column select expression.</param> /// <param name="boxIdentity">The box identity.</param> /// <returns>Generated attribute.</returns> public static GeneratedAttribute Generate( string connectionString, string dataMatrixName, string columnSelectExpression, string boxIdentity) { DataTable dataTable = Ferda.Modules.Helpers.Data.Column.GetDistincts(connectionString, dataMatrixName, columnSelectExpression, boxIdentity); CategoriesStruct categoriesStructValue = new CategoriesStruct(); List<SelectString> categoriesNames = new List<SelectString>(); categoriesStructValue.enums = new EnumCategorySeq(); string rowValue; string categoryName; SelectString item; bool getNames = (dataTable.Rows.Count <= AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray); string includeNullCategoryNameValue = null; foreach (DataRow dataRow in dataTable.Rows) { rowValue = dataRow.ItemArray[0].ToString(); if (String.IsNullOrEmpty(rowValue)) { categoryName = Ferda.Modules.Helpers.Common.Constants.DbNullCategoryName; includeNullCategoryNameValue = categoryName; } else { categoryName = rowValue; } categoriesStructValue.enums.Add(categoryName, new string[1] { rowValue }); if (getNames) { item = new SelectString(); item.label = categoryName; item.name = categoryName; categoriesNames.Add(item); } } GeneratedAttribute output = new GeneratedAttribute( categoriesStructValue, includeNullCategoryNameValue, categoriesStructValue.enums.Count, categoriesNames.ToArray()); return output; }