public static int Insert(int siteId, FieldInfo fieldInfo) { fieldInfo.Taxis = GetMaxTaxis(fieldInfo.FormId) + 1; var sqlString = $@"INSERT INTO {TableName} ( {nameof(FieldInfo.FormId)}, {nameof(FieldInfo.Taxis)}, {nameof(FieldInfo.Title)}, {nameof(FieldInfo.Description)}, {nameof(FieldInfo.PlaceHolder)}, {nameof(FieldInfo.FieldType)}, {nameof(FieldInfo.Validate)}, {nameof(FieldInfo.Settings)} ) VALUES ( @{nameof(FieldInfo.FormId)}, @{nameof(FieldInfo.Taxis)}, @{nameof(FieldInfo.Title)}, @{nameof(FieldInfo.Description)}, @{nameof(FieldInfo.PlaceHolder)}, @{nameof(FieldInfo.FieldType)}, @{nameof(FieldInfo.Validate)}, @{nameof(FieldInfo.Settings)} )"; var parameters = new [] { Context.DatabaseApi.GetParameter(nameof(FieldInfo.FormId), fieldInfo.FormId), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Taxis), fieldInfo.Taxis), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Title), fieldInfo.Title), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Description), fieldInfo.Description), Context.DatabaseApi.GetParameter(nameof(FieldInfo.PlaceHolder), fieldInfo.PlaceHolder), Context.DatabaseApi.GetParameter(nameof(FieldInfo.FieldType), fieldInfo.FieldType), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Validate), fieldInfo.Validate), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Settings), fieldInfo.Settings) }; var id = Context.DatabaseApi.ExecuteNonQueryAndReturnId(TableName, nameof(FieldInfo.Id), Context.ConnectionString, sqlString, parameters); FieldItemDao.InsertItems(fieldInfo.FormId, id, fieldInfo.Items); var formInfo = FormManager.GetFormInfo(siteId, fieldInfo.FormId); var list = FormUtils.StringCollectionToStringList(formInfo.Additional.ListAttributeNames); list.Add(fieldInfo.Title); formInfo.Additional.ListAttributeNames = FormUtils.ObjectCollectionToString(list); FormDao.Update(formInfo); FieldManager.ClearCache(); return(id); }
public static void Update(FieldInfo info, bool updateItems) { var sqlString = $@"UPDATE {TableName} SET {nameof(FieldInfo.FormId)} = @{nameof(FieldInfo.FormId)}, {nameof(FieldInfo.Taxis)} = @{nameof(FieldInfo.Taxis)}, {nameof(FieldInfo.Title)} = @{nameof(FieldInfo.Title)}, {nameof(FieldInfo.Description)} = @{nameof(FieldInfo.Description)}, {nameof(FieldInfo.PlaceHolder)} = @{nameof(FieldInfo.PlaceHolder)}, {nameof(FieldInfo.FieldType)} = @{nameof(FieldInfo.FieldType)}, {nameof(FieldInfo.Validate)} = @{nameof(FieldInfo.Validate)}, {nameof(FieldInfo.Settings)} = @{nameof(FieldInfo.Settings)} WHERE {nameof(FieldInfo.Id)} = @{nameof(FieldInfo.Id)}"; var updateParms = new [] { Context.DatabaseApi.GetParameter(nameof(FieldInfo.FormId), info.FormId), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Taxis), info.Taxis), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Title), info.Title), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Description), info.Description), Context.DatabaseApi.GetParameter(nameof(FieldInfo.PlaceHolder), info.PlaceHolder), Context.DatabaseApi.GetParameter(nameof(FieldInfo.FieldType), info.FieldType), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Validate), info.Validate), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Settings), info.Additional.ToString()), Context.DatabaseApi.GetParameter(nameof(FieldInfo.Id), info.Id) }; Context.DatabaseApi.ExecuteNonQuery(Context.ConnectionString, sqlString, updateParms); if (updateItems) { FieldItemDao.DeleteByFieldId(info.Id); FieldItemDao.InsertItems(info.FormId, info.Id, info.Items); } FieldManager.ClearCache(); }