public AdminVM(Controller2Garin controller) : base(controller)
 {
     if (!CheckRights())
     {
         throw new Exception(controller.Localizer2Garin.Localize("common.denied"));
     }
 }
Exemplo n.º 2
0
        public IActionResult ToActionResult(Controller2Garin controller)
        {
            var Logger = controller.LoggerFactory.CreateLogger(this.GetType().FullName);

            if (Page == "404")
            {
                return(controller.NotFound(controller.Localizer2Garin.Localize("common.404")));
            }

            var LoggerMEF = controller.LoggerFactory.CreateLogger(Utils.MEFNameSpace);
            var vm        = new PageVM(controller)
            {
                Input = this
            };

            try
            {
                Logger.LogInformation("Begin '{page}' in lang '{Culture}'", Page, Culture);

                var storage = controller.Storage;
                var sites   = controller.Sites; //storage.GetRepository<ISiteRepository>(false);
                var menus   = controller.Menus; // storage.GetRepository<IMenuRepository>(true);

                //var newitem = new Sites { Name = "Supper Site " + DateTime.Now };
                //sites.Save(newitem);

                Sites site;
                //site = sites[1];

                site = sites[2];
                if (site != null)
                {
                    site.Name = "New name 2 " + DateTime.Now;
                    sites.Save(site);
                    //storage.Save(EnumDB.UserSites);

                    //sites.AfterSave(site, false);
                }
                //vm.Sites = rep.StartQuery().Where(i => i.Id < 30).ToList();
                //using (new BLog(LoggerMEF, "Load sites", GetType().FullName))
                {
                    vm.Sites = sites.StartQuery(0).Where(i => i.Id < 10).OrderByDescending(i => i.Id).ToList();
                }
                GC.Collect();
                Logger.LogInformation("Memory used after full collection:   {0:N0}", GC.GetTotalMemory(true));

                using (new BLog(LoggerMEF, "Load Languages", GetType().FullName))
                {
                    var tmp = controller.Languages.StartQuery(1).Where(i => i.Name.StartsWith("r")).ToList();
                }
            }
            catch (Exception e)
            {
                vm.Error = e;
            }
            return(controller.View(vm));
        }
 public FieldSelect(Controller2Garin controller, FieldBaseAttribute Attribute, string PropertyName) : base(controller, Attribute, PropertyName)
 {
     SelectRepository    = Attribute.SelectRepository;
     SelectValueName     = Attribute.SelectValueName;
     SelectParentName    = Attribute.SelectParentName;
     SelectTitleName     = Attribute.SelectTitleName;
     SelectValuesJson    = Attribute.SelectValuesJson;
     SelectOnlyUnblocked = Attribute.SelectOnlyUnblocked;
     SelectTreePrefix    = Attribute.SelectTreePrefix ?? "&nbsp;&nbsp;&nbsp;&nbsp;";
 }
        public Field(Controller2Garin controller, FieldBaseAttribute Attribute, string propertyName)
        {
            _init(controller, null, null, Attribute.HtmlType, Attribute.IsRequired,
                  Attribute.NeedTranslate, Attribute.IsMultiple, propertyName, Attribute.Priority, Attribute.Default == null ? null : new List <string>()
            {
                Attribute.Default
            },
                  Attribute.Compare, Attribute.Format);

            Title       = LocalizeFieldKey("title", false) ?? PropertyName;
            Placeholder = LocalizeFieldKey("placeholder", false);
        }
        private void _init(Controller2Garin controller, string title, string placeholder, EnumHtmlType htmlType, bool isRequired, bool needTranslate, bool isMultiple,
                           string propertyName, int priority, List <string> Default, EnumFilterCompare compare = EnumFilterCompare.Equals, string format = null)
        {
            Controller    = controller;
            Logger        = controller.LoggerFactory.CreateLogger(GetType().FullName);
            HtmlType      = htmlType;
            PropertyName  = propertyName;
            Priority      = priority;
            IsRequired    = isRequired;
            NeedTranslate = needTranslate;
            IsMultiple    = isMultiple;
            Title         = title;
            Placeholder   = placeholder;
            Compare       = compare;
            Format        = format;

            //this.Default = Default;

            this.Default = ParseValuesFromStrings(Default);
        }
Exemplo n.º 6
0
        public static Form GetForm <FA>(this Type t, Controller2Garin controller) where FA : FieldBaseAttribute
        {
            var fields = new List <IField>();

            foreach (var f in t.GetPropertiesWithAttribute <FA>())
            {
                // вызов конструктора женериков
                // https://docs.microsoft.com/ru-ru/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection

                IField field = null;
                Type[] typeArgs = { f.Key.PropertyType };
                Type   d1, ff;
                switch (f.Value.HtmlType)
                {
                case EnumHtmlType.Image:
                case EnumHtmlType.Images:
                case EnumHtmlType.File:
                case EnumHtmlType.Files:
                    break;

                case EnumHtmlType.Select:
                case EnumHtmlType.Tree:
                    d1    = typeof(FieldSelect <>);
                    ff    = d1.MakeGenericType(typeArgs);
                    field = (IField)Activator.CreateInstance(ff, new object[] { controller, f.Value, f.Key.Name });
                    break;

                default:
                    d1    = typeof(Field <>);
                    ff    = d1.MakeGenericType(typeArgs);
                    field = (IField)Activator.CreateInstance(ff, new object[] { controller, f.Value, f.Key.Name });
                    break;
                }
                if (field != null)
                {
                    fields.Add(field);
                }
            }

            return(new Form(controller, fields));
        }
Exemplo n.º 7
0
 public BaseVM(Controller2Garin controller)
 {
     Controller = controller;
     Breadcrumb = new MenuVM(new List <MenuItem>());
 }
Exemplo n.º 8
0
 public PageVM(Controller2Garin controler) : base(controler)
 {
 }
 public FieldFile(Controller2Garin controller, FieldBaseAttribute Attribute, string PropertyName) : base(controller, Attribute, PropertyName)
 {
 }
 public Field(Controller2Garin controller, string title, string placeholder, EnumHtmlType htmlType, bool isRequired, bool needTranslate, bool isMultiple,
              string propertyName, int priority, List <string> Default, EnumFilterCompare compare = EnumFilterCompare.Equals, string format = null)
 {
     _init(controller, title, placeholder, htmlType, isRequired, needTranslate, isMultiple,
           propertyName, priority, Default, compare, format);
 }
Exemplo n.º 11
0
 public Form(Controller2Garin controller, List <IField> fields)
 {
     Controller = controller;
     Fields     = fields;
 }
Exemplo n.º 12
0
 public Form(Controller2Garin controller)
 {
     Controller = controller;
     Fields     = new List <IField>();
 }