private EventConfigurationViewModel GetModel()
        {
            int userId = UserHelper.GetUserByIdentityName(User.Identity.Name).Id;

            var configs = EventConfigurationHelper.GetUserEventConfigurations(userId);

            var model = new EventConfigurationViewModel()
            {
                Configurations = new List <EventConfigRow>(),
                Properties     = DataConfigurationHelper.GetUserDataProperties(userId),
                CurrentConfig  = GetEmptyCurrentConfig(userId),
                Response       = string.Empty
            };

            foreach (var config in configs)
            {
                model.Configurations.Add(new EventConfigRow
                {
                    Id     = config.Id,
                    Rule   = EventConfigurationHelper.FormatEventToString(config),
                    Period = config.Period
                });
            }

            return(model);
        }
        private CurrentConfig GetCurrentConfig(EventConfiguration config, int userId)
        {
            var operators = new List <string>()
            {
                "=", "<", ">"
            };
            var functions = new List <string>()
            {
                "SUM", "AVG", "COUNT"
            };
            var properties = DataConfigurationHelper.GetUserDataProperties(userId);

            return(new CurrentConfig
            {
                Id = config.Id.ToString(),
                PropertyId = config.PropertyId,
                PropertyList =
                    properties.Select(x => new SelectListItem
                {
                    Text = x.Name,
                    Value = x.Id.ToString(),
                    Selected = x.Id == config.PropertyId
                }),
                PropertyOperator = config.PropertyOperator,
                PropertyOperatorList =
                    operators.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == config.PropertyOperator
                }),
                PropertyValue = config.PropertyValue,
                Operator = config.Operator,
                OperatorList =
                    operators.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == config.Operator
                }),
                ResultValue = config.ResultValue.ToString(),
                Function = config.Function,
                FunctionList =
                    functions.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == config.Function
                }),
                Period = config.Period.ToString(),
                Template = config.Template,
                TemplateProperties = EventConfigurationHelper.ConvertTemplatePropertiesFromIdsToNames(config.TemplateProperties)
            });
        }
        private CurrentConfig GetEmptyCurrentConfig(int userId)
        {
            var operators = new List <string>()
            {
                "=", "<", ">"
            };
            var functions = new List <string>()
            {
                "SUM", "AVG", "COUNT"
            };
            var properties = DataConfigurationHelper.GetUserDataProperties(userId);

            return(new CurrentConfig
            {
                Id = string.Empty,
                PropertyList =
                    properties.Select(x => new SelectListItem
                {
                    Text = x.Name,
                    Value = x.Id.ToString(),
                    Selected = x.Id == properties.First().Id
                }),
                PropertyOperatorList =
                    operators.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == operators.First()
                }),
                PropertyValue = string.Empty,
                OperatorList =
                    operators.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == operators.First()
                }),
                ResultValue = string.Empty,
                FunctionList =
                    functions.Select(x => new SelectListItem
                {
                    Text = x,
                    Value = x,
                    Selected = x == functions.First()
                }),
                Period = string.Empty,
                Template = string.Empty,
                TemplateProperties = string.Empty
            });
        }