/// <summary> /// Gets the table definition. /// </summary> /// <param name="parameters">The query parameters.</param> /// <returns></returns> /// <exception cref="ALexException">Used for displaying a message to the user.</exception> protected IQueryable <TableDefinition> GetTableDefinitions(IBuilderParameters parameters) { var result = from td in this.Context.QueryBuilderDbContext.TableDefinitions where td.ItemName == parameters.ItemName && td.IsEnabled select td; switch (parameters.QueryType) { case EQueryType.DetailListView: result = result.Where(e => e.TableDefinitionUi.ShowInDetails); break; case EQueryType.EditView: result = result.Where(e => e.TableDefinitionUi.ShowInEdit); break; case EQueryType.GridView: result = result.Where(e => e.TableDefinitionUi.ShowInGrid); break; default: throw new ALexException("The query type is not set. You must specify the query type.", 102); } return(result); }
private IQueryable <FieldGroup> GetGroups(IBuilderParameters parameters) { var fields = base.GetFieldDefinitions(parameters); var groups = from gr in base.Context.QueryBuilderDbContext.FieldGroups where (from f in fields select f.FieldDefinitionUi.FieldGroupDetail.FieldGroupId) .Distinct() .Contains(gr.FieldGroupId) select gr; return(groups); }
/// <summary> /// Gets the fields assigned to the request. /// </summary> /// <param name="parameters">The query parameters.</param> /// <returns>A queryable collection.</returns> /// <exception cref="ALexException">Used for displaying a message to the user.</exception> protected IQueryable <FieldDefinition> GetFieldDefinitions(IBuilderParameters parameters) { if (parameters.QueryType == EQueryType.Undefined) { throw new ALexException("The query type is not set. You must specify the query type.", 100) { } } ; var tableDef = this.GetTableDefinitions(parameters); var fields = from td in tableDef from fd in td.FieldDefinitions where fd.IsEnabled select fd; switch (parameters.QueryType) { case EQueryType.DetailListView: fields = fields.Where(e => e.FieldDefinitionUi.ShowInDetails); break; case EQueryType.EditView: fields = fields.Where(e => e.FieldDefinitionUi.ShowInEdit); break; case EQueryType.GridView: fields = fields.Where(e => e.FieldDefinitionUi.ShowInGrid); break; default: throw new ALexException("The query type is not set. You must specify the query type.", 101); } return(fields); }
/// <summary> /// Gets the table edit detail definition configuration based in the parameters. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns></returns> /// <exception cref="ALexException">Used for displaying a message to the user.</exception> /// <exception cref="QueryBuilderException">Thrown with a code number.</exception> public virtual async Task <GeneralResult <EditConfigViewModel> > GetEditConfigAsync(IBuilderParameters parameters) { GeneralResult <EditConfigViewModel> result; try { var fieldGroups = this.GetGroups(parameters); var groups = from gr in fieldGroups select new EditGroupViewModel() { DisplayName = gr.DisplayName, GroupType = gr.GroupType, GroupWidth = gr.GroupWidth, ItemName = gr.ItemName, GroupDetails = (from grd in gr.FieldGroupDetails select new EditGroupDetailViewModel() { DisplayName = grd.DisplayName, ItemName = grd.ItemName, GroupType = grd.GroupType, DisplayOrder = grd.DisplayOrder, GroupWidth = grd.GroupWidth, Fields = (from f in grd.FieldDefinitionUis select new EditFieldConfigViewModel() { ItemName = f.FieldDefinition.ItemName, AllowEditInDetail = f.AllowEditInDetail, DisplayFormat = f.DisplayFormat, DisplayOrder = f.DisplayOrder, DisplayType = f.DisplayType, IsHidden = f.IsHidden, IsKey = f.FieldDefinition.IsKey, IsReadOnly = f.IsReadOnly, DisplayName = f.DisplayName, EditWidth = f.EditWidth, IsRequired = f.IsRequired, MaxLength = f.MaxLength, MinLength = f.MinLength, Regex = f.Regex, FieldType = f.FieldDefinition.FieldType, SourceList = (from s in f.FieldDefinition.FieldListSources select s.RequiredFieldDefinition.ItemName).ToList() }).ToList() }).ToList() }; var fieldDefinitions = base.GetFieldDefinitions(parameters); var validations = from val in base.Context.QueryBuilderDbContext.TableFieldValidations where val.ValidateOnClient && val.ExecutionSource.ExecutionType == Entities.EExecutionType.JavaScript && (from f in fieldDefinitions select f.FieldDefinitionId).Contains(val.ChangeFieldDefinitionId) select val; var dataValidations = from val in validations group val by val.ExecutionSourceId into val select new DataValidation() { ExecuteOnClientSide = val.Max(e => e.ValidateOnClient), ExecutionResultType = val.Max(e => e.ExecutionResultType), Statement = val.Max(e => e.ExecutionSource.ExecutionText), Fields = (from v in validations select v.ChangeFieldDefinition.ItemName).ToList() }; var table = await(from t in base.GetTableDefinitions(parameters) select new EditConfigViewModel() { AllowExport = t.TableDefinitionUi.AllowExport, DetailFormat = t.TableDefinitionUi.DetailFormat, DisplayName = t.TableDefinitionUi.DisplayName, ItemName = t.ItemName, } ).FirstOrDefaultAsync(); table.Validations = await dataValidations.ToListAsync(); table.Groups = await groups.ToListAsync(); result = new GeneralResult <EditConfigViewModel>() { Result = table }; } catch (ALexException ex) { result = base.GetResultFromException <GeneralResult <EditConfigViewModel> >(ex, 2001); } return(result); }
/// <summary> /// Gets the table definition configuration based in the parameters. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns></returns> /// <exception cref="ALexException">Used for displaying a message to the user.</exception> /// <exception cref="QueryBuilderException">Thrown with a code number.</exception> public async virtual Task <GeneralResult <GridConfigViewModel> > GetGridConfigAsync(IBuilderParameters parameters) { GeneralResult <GridConfigViewModel> result; try { var fieldGroups = this.GetGroups(parameters); var groups = from fg in fieldGroups from det in fg.FieldGroupDetails select new GridGroupViewModel() { DisplayName = fg.DisplayName, ItemName = fg.ItemName, Fields = (from f in det.FieldDefinitionUis select new GridFieldConfigViewModel() { ItemName = f.FieldDefinition.ItemName, AllowFilter = f.AllowFilter, AllowSort = f.AllowSort, GridWidth = f.GridWidth, DisplayFormat = f.DisplayFormat, DisplayOrder = f.DisplayOrder, DisplayType = f.DisplayType, IsHidden = f.IsHidden, IsKey = f.FieldDefinition.IsKey, IsReadOnly = f.IsReadOnly, DisplayName = f.DisplayName, }).ToList() }; var table = await(from t in base.GetTableDefinitions(parameters) select new GridConfigViewModel() { AllowExport = t.TableDefinitionUi.AllowExport, DisplayName = t.TableDefinitionUi.DisplayName, ItemName = t.ItemName, } ).FirstOrDefaultAsync(); table.Groups = await groups.ToListAsync(); result = new GeneralResult <GridConfigViewModel>() { Result = table }; } catch (ALexException ex) { result = base.GetResultFromException <GeneralResult <GridConfigViewModel> >(ex, 2003); } return(result); }
/// <summary> /// Gets the table list detail definition configuration based in the parameters. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns></returns> /// <exception cref="ALexException">Used for displaying a message to the user.</exception> /// <exception cref="QueryBuilderException">Thrown with a code number.</exception> public virtual async Task <GeneralResult <DetailListConfigViewModel> > GetDetailListConfigAsync(IBuilderParameters parameters) { GeneralResult <DetailListConfigViewModel> result; try { var r = await(from td in base.GetTableDefinitions(parameters) select new DetailListConfigViewModel() { DetailFormat = td.TableDefinitionUi.DetailFormat, DisplayName = td.TableDefinitionUi.DisplayName, ItemName = td.ItemName, }).FirstOrDefaultAsync(); r.Groups = await(from f in base.GetFieldDefinitions(parameters) select new FieldConfigViewModel() { DisplayFormat = f.FieldDefinitionUi.DisplayFormat, ItemName = f.ItemName }).ToListAsync(); result = new GeneralResult <DetailListConfigViewModel>() { Result = r }; } catch (ALexException ex) { result = base.GetResultFromException <GeneralResult <DetailListConfigViewModel> >(ex, 2002); } return(result); }
/// <summary> /// Builds the main query. /// </summary> /// <param name="parameters">Parameters to be used in the query building.</param> /// <param name="aditionalStatemnts">Additional statements for adding to the queries.</param> /// <param name="fieldDefinitions">A collection of <see cref="FieldDefinition"/>.</param> /// <returns></returns> private async Task <(StringBuilder QueryString, StringBuilder CounterString)> BuildMainQueryAsync(IEnumerable <FieldDefinition> fieldDefinitions, IBuilderParameters parameters, IEnumerable <string> aditionalStatemnts) { (StringBuilder QueryString, StringBuilder CounterString)result; var queryBuilder = new StringBuilder(); var counterBuilder = new StringBuilder(); await Task.Run(() => { var selectFields = fieldDefinitions.Where(e => e.FieldType != EFieldType.MultiselectCheckbox && e.FieldType != EFieldType.MultiselectList && e.FieldType != EFieldType.TableReference); // The table query is the same for both queries. string alias = "T1"; queryBuilder.Append("From(").Append(fieldDefinitions.First().TableDefinition.TableName).Append(" AS ").Append(alias).AppendLine(")"); counterBuilder.Append(queryBuilder); // Select statement for query builder. queryBuilder.Append("Select(").Append(string.Join(",", selectFields.Select(e => alias + "." + e.ItemName))).Append(")"); // Counter statement for counter. counterBuilder.Append("Select(COUNT(1) AS TotalCount)").AppendLine(); // If there are aditional filters (or statements) they are added to the queries. if (aditionalStatemnts != null) { foreach (string filter in aditionalStatemnts) { queryBuilder.AppendLine(filter); counterBuilder.AppendLine(filter); } } // Adds the table alias to the dictionary in order to use with the query. if (parameters.AdditionalParameters == null) { parameters.AdditionalParameters = new Dictionary <string, object>(); } if (!parameters.AdditionalParameters.ContainsKey("FirstAlias")) { parameters.AdditionalParameters.Add("FirstAlias", alias); } if (parameters.QueryType == EQueryType.EditView) { // Only one record since it is the detail view. queryBuilder.Append("Limit(1)").AppendLine(); } }); result = (QueryString : queryBuilder, CounterString : counterBuilder); return(result); }