protected override AbstractDataGrid GetImportTemplate()
        {
            // Get the properties of the DTO for Save, excluding Id or EntityState
            var type  = typeof(MeasurementUnitForSave);
            var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            // The result that will be returned
            var result = new AbstractDataGrid(props.Length, 1);

            // Add the header
            var header = result[result.AddRow()];
            int i      = 0;

            foreach (var prop in props)
            {
                var display = _metadataProvider.GetMetadataForProperty(type, prop.Name)?.DisplayName ?? prop.Name;
                if (display != Constants.Hidden)
                {
                    header[i++] = AbstractDataCell.Cell(display);
                }
            }

            return(result);
        }
Example #2
0
        protected override AbstractDataGrid GetImportTemplate()
        {
            // Get the properties of the DTO for Save, excluding Id or EntityState
            var custodyType  = typeof(CustodyForSave);
            var agentType    = typeof(AgentForSave);
            var custodyProps = custodyType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var agentProps   = agentType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var props        = custodyProps.Union(agentProps);

            if (ViewId() == ORGANIZATION)
            {
                // For organizations, some properties are left blank
                var exemptProperties = new string[] { nameof(Agent.Title), nameof(Agent.Title2), nameof(Agent.Gender) };
                props.Where(p => !exemptProperties.Contains(p.Name));
            }

            var propsArray = props.ToArray();

            // The result that will be returned
            var result = new AbstractDataGrid(propsArray.Length, 1);

            // Add the header
            var header = result[result.AddRow()];
            int i      = 0;

            foreach (var prop in props)
            {
                var display = _metadataProvider.GetMetadataForProperty(agentType, prop.Name)?.DisplayName ?? prop.Name;
                if (display != Constants.Hidden)
                {
                    header[i++] = AbstractDataCell.Cell(display);
                }
            }

            return(result);
        }
Example #3
0
        protected override AbstractDataGrid DtosToAbstractGrid(GetResponse <Agent> response, ExportArguments args)
        {
            // Get all the properties without Id and EntityState
            var type             = typeof(Agent);
            var custodySaveProps = typeof(CustodyForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var agentSaveProps   = typeof(AgentForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            var readProps = typeof(Agent).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var saveProps = custodySaveProps.Union(agentSaveProps);

            var props = saveProps.Union(readProps);

            if (ViewId() == ORGANIZATION)
            {
                // For organizations, some properties are left blank
                var exemptProperties = new string[] { nameof(Agent.Title), nameof(Agent.Title2), nameof(Agent.Gender) };
                props.Where(p => !exemptProperties.Contains(p.Name));
            }

            var propsArray = props.ToArray();

            // The result that will be returned
            var result = new AbstractDataGrid(propsArray.Length, response.Data.Count() + 1);

            // Add the header
            List <PropertyInfo> addedProps = new List <PropertyInfo>(propsArray.Length);

            {
                var header = result[result.AddRow()];
                int i      = 0;
                foreach (var prop in propsArray)
                {
                    var display = _metadataProvider.GetMetadataForProperty(type, prop.Name)?.DisplayName ?? prop.Name;
                    if (display != Constants.Hidden)
                    {
                        header[i] = AbstractDataCell.Cell(display);

                        // Add the proper styling
                        if (prop.PropertyType.IsDateOrTime())
                        {
                            var att        = prop.GetCustomAttribute <DataTypeAttribute>();
                            var isDateOnly = att != null && att.DataType == DataType.Date;
                            header[i].NumberFormat = ExportDateTimeFormat(dateOnly: isDateOnly);
                        }

                        addedProps.Add(prop);
                        i++;
                    }
                }
            }


            // Add the rows
            foreach (var entity in response.Data)
            {
                var row = result[result.AddRow()];
                int i   = 0;
                foreach (var prop in addedProps)
                {
                    var content = prop.GetValue(entity);

                    // Special handling for choice lists
                    var choiceListAttr = prop.GetCustomAttribute <ChoiceListAttribute>();
                    if (choiceListAttr != null)
                    {
                        var choiceIndex = Array.FindIndex(choiceListAttr.Choices, e => e.Equals(content));
                        if (choiceIndex != -1)
                        {
                            string displayName = choiceListAttr.DisplayNames[choiceIndex];
                            content = _localizer[displayName];
                        }
                    }

                    // Special handling for DateTimeOffset
                    if (prop.PropertyType.IsDateTimeOffset() && content != null)
                    {
                        content = ToExportDateTime((DateTimeOffset)content);
                    }

                    row[i] = AbstractDataCell.Cell(content);
                    i++;
                }
            }

            return(result);
        }
Example #4
0
        protected override AbstractDataGrid DtosToAbstractGrid(GetResponse <MeasurementUnit> response, ExportArguments args)
        {
            // Get all the properties without Id and EntityState
            var type      = typeof(MeasurementUnit);
            var readProps = typeof(MeasurementUnit).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var saveProps = typeof(MeasurementUnitForSave).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            var props     = saveProps.Union(readProps).ToArray();

            // The result that will be returned
            var result = new AbstractDataGrid(props.Length, response.Data.Count() + 1);

            // Add the header
            List <PropertyInfo> addedProps = new List <PropertyInfo>(props.Length);

            {
                var header = result[result.AddRow()];
                int i      = 0;
                foreach (var prop in props)
                {
                    var display = _metadataProvider.GetMetadataForProperty(type, prop.Name)?.DisplayName ?? prop.Name;
                    if (display != Constants.Hidden)
                    {
                        header[i] = AbstractDataCell.Cell(display);

                        // Add the proper styling for DateTime and DateTimeOffset
                        if (prop.PropertyType.IsDateOrTime())
                        {
                            var att        = prop.GetCustomAttribute <DataTypeAttribute>();
                            var isDateOnly = att != null && att.DataType == DataType.Date;
                            header[i].NumberFormat = ExportDateTimeFormat(dateOnly: isDateOnly);
                        }

                        addedProps.Add(prop);
                        i++;
                    }
                }
            }

            // Add the rows
            foreach (var entity in response.Data)
            {
                var metadata = entity.EntityMetadata;
                var row      = result[result.AddRow()];
                int i        = 0;
                foreach (var prop in addedProps)
                {
                    metadata.TryGetValue(prop.Name, out FieldMetadata meta);
                    if (meta == FieldMetadata.Loaded)
                    {
                        var content = prop.GetValue(entity);

                        // Special handling for choice lists
                        var choiceListAttr = prop.GetCustomAttribute <ChoiceListAttribute>();
                        if (choiceListAttr != null)
                        {
                            var choiceIndex = Array.FindIndex(choiceListAttr.Choices, e => e.Equals(content));
                            if (choiceIndex != -1)
                            {
                                string displayName = choiceListAttr.DisplayNames[choiceIndex];
                                content = _localizer[displayName];
                            }
                        }

                        // Special handling for DateTimeOffset
                        if (prop.PropertyType.IsDateTimeOffset() && content != null)
                        {
                            content = ToExportDateTime((DateTimeOffset)content);
                        }

                        row[i] = AbstractDataCell.Cell(content);
                    }
                    else if (meta == FieldMetadata.Restricted)
                    {
                        row[i] = AbstractDataCell.Cell(Constants.Restricted);
                    }
                    else
                    {
                        row[i] = AbstractDataCell.Cell("-");
                    }

                    i++;
                }
            }

            return(result);
        }