Пример #1
0
        public async Task <Limits> GetAsync()
        {
            var limitsKeyValues = await _context.LimitsKeyValuePairs.ToListAsync();

            var limits = Limits.Create();

            foreach (var limit in limitsKeyValues)
            {
                var propertyInfo = typeof(Limits).GetProperty(limit.LimitKey);
                if (propertyInfo == null)
                {
                    throw new LimitNotMappable($"{nameof(Limits)} property {limit.LimitKey} not found, even though it is defined in database.");
                }
                if (propertyInfo.PropertyType == typeof(TimeSpan))
                {
                    propertyInfo.SetValue(limits, new TimeSpan(0, limit.LimitValue, 0));
                }
                else
                {
                    propertyInfo.SetValue(limits, limit.LimitValue);
                }
            }
            return(limits);
        }