public ApplicationSettings GetApplicationSettings()
        {
            return(cachingService.GetOrSet("AppSettings", () =>
            {
                var dict = settingsRepository.GetDictionary();

                var settings = dict.ToEntity <ApplicationSettings>(new Dictionary <string, Func <object, object> >()
                {
                    { "EnabledLanguages", (input) => ((string)input).Split(',') }
                });

                return settings;
            }));
        }
        public Contracts.Settings.Entities.Settings Get()
        {
            return(cachingService.GetOrSet(CACHE_KEY, () =>
            {
                using (var ctx = dbContextFactory.Create())
                    using (var db = new Database(ctx.Database.Connection.ConnectionString).Get)
                    {
                        var result = db.Query("SELECT * FROM [dbo].[Settings]");
                        var dictionary = result.ToDictionary(x => (string)x.Name, x => x.Value);

                        return ToEntity <Contracts.Settings.Entities.Settings>(dictionary);
                    }
            }));
        }
Example #3
0
        public Application Get(string identifier)
        {
            return(cachingService.GetOrSet($"{CACHE_KEY}_{identifier}", () =>
            {
                using (var ctx = dbContextFactory.Create())
                    using (var db = new Database(ctx.Database.Connection.ConnectionString).Get)
                    {
                        var results = db.QueryMultiple(@"
SELECT CONVERT(VARCHAR(50), ID) AS Identifier, Name AS DisplayName, CustomData, EnableCreate, EnableUpdate, EnableDelete FROM [dbo].[Applications]
WHERE ID = @identifier

SELECT * FROM [dbo].[Fields]
WHERE IDApplication = @identifier
", new { identifier });

                        var application = results.ReadFirstOrDefault <Application>();

                        if (application == null)
                        {
                            return null;
                        }

                        var fieldResult = results.Read <FieldResult>();

                        application.Identifier = application.Identifier.ToLower();

                        var searchVisibilities = new int[] { 0, 1 };
                        var gridVisibilities = new int[] { 0, 2, 6 };
                        var propertyVisibilities = new int[] { 0, 4 };

                        var searchFields = new List <SearchField>();
                        var gridFields = new List <GridField>();
                        var propertyFields = new List <PropertyField>();
                        var lookupPropertyFields = new List <LookupPropertyField>();
                        var hiddenFields = new List <Field>();

                        foreach (var field in fieldResult)
                        {
                            if (searchVisibilities.Contains(field.VisibilityType) && field.NotVisibleFilter != true)
                            {
                                searchFields.Add(field.ToSearchField());
                            }

                            if (gridVisibilities.Contains(field.VisibilityType) && field.NotVisibleList != true)
                            {
                                gridFields.Add(field.ToGridField());
                            }

                            if (propertyVisibilities.Contains(field.VisibilityType) && field.NotVisibleViewer != true)
                            {
                                if (field.Type == 10)
                                {
                                    var lookupField = field.ToLookupPropertyField();
                                    lookupPropertyFields.Add(lookupField);
                                    propertyFields.Add(lookupField);
                                }
                                else
                                {
                                    propertyFields.Add(field.ToPropertyField());
                                }
                            }

                            if (field.NotVisibleFilter == true && field.NotVisibleList == true && field.NotVisibleViewer == true)
                            {
                                hiddenFields.Add(field.ToField <Field>());
                            }
                        }

                        application.SearchFields = searchFields;
                        application.GridFields = gridFields;
                        application.PropertyFields = propertyFields;
                        application.LookupPropertyFields = lookupPropertyFields;
                        application.HiddenFields = hiddenFields;

                        var validationRules = validationProvider
                                              .GetRules(identifier)
                                              .GroupBy(x => x.FieldIdentifier);

                        foreach (var propertyField in application.PropertyFields)
                        {
                            var propertyRules = validationRules.FirstOrDefault(x => x.Key == propertyField.Identifier);

                            if (propertyRules == null)
                            {
                                continue;
                            }

                            propertyField.ValidationRules = propertyRules.ToList();
                        }

                        return application;
                    }
            }));
        }
Example #4
0
        public IEnumerable <ValidationRule> GetRules(string applicationIdentifier)
        {
            return(cachingService.GetOrSet($"{CACHE_KEY_GETRULES}_{applicationIdentifier}", () =>
            {
                using (var ctx = dbContextFactory.Create())
                    using (var db = new Database(ctx.Database.Connection.ConnectionString).Get)
                    {
                        var results = db.Query <FieldResult>(@"
SELECT ID, UniqueName, Name, ValidationRulesJson FROM [dbo].[Fields]
WHERE IDApplication = @applicationIdentifier
", new { applicationIdentifier });

                        var list = new List <ValidationRule>();

                        foreach (var item in results)
                        {
                            string fieldIdentifier = item.UniqueName ?? item.ID.ToString().ToLower();

                            if (string.IsNullOrEmpty(item.ValidationRulesJson))
                            {
                                continue;
                            }

                            if (item.ValidationRules.IsAlpha)
                            {
                                list.Add(new ValidationRule
                                {
                                    FieldIdentifier = fieldIdentifier,
                                    Method = "IsAlpha",
                                    InvalidMessage = $"{item.Name} must be alphanumeric"
                                });
                            }

                            if (item.ValidationRules.IsAlphanumeric)
                            {
                                list.Add(new ValidationRule
                                {
                                    FieldIdentifier = fieldIdentifier,
                                    Method = "IsAlphanumeric",
                                    InvalidMessage = $"{item.Name} must be alphanumeric"
                                });
                            }

                            if (item.ValidationRules.IsRequired)
                            {
                                list.Add(new ValidationRule
                                {
                                    FieldIdentifier = fieldIdentifier,
                                    Method = "IsRequired",
                                    InvalidMessage = $"{item.Name} is required"
                                });
                            }

                            if (item.ValidationRules.MinLength.HasValue)
                            {
                                list.Add(new ValidationRule
                                {
                                    FieldIdentifier = fieldIdentifier,
                                    Method = "MinLength",
                                    InvalidMessage = $"{item.Name} must be at least ${item.ValidationRules.MinLength} characters long.",
                                    Arguments = new object[] { item.ValidationRules.MinLength.Value }
                                });
                            }

                            if (item.ValidationRules.MaxLength.HasValue)
                            {
                                list.Add(new ValidationRule
                                {
                                    FieldIdentifier = fieldIdentifier,
                                    Method = "MaxLength",
                                    InvalidMessage = $"{item.Name} must be at most ${item.ValidationRules.MaxLength} characters long.",
                                    Arguments = new object[] { item.ValidationRules.MaxLength.Value }
                                });
                            }
                        }

                        return list;
                    }
            }));
        }