示例#1
0
        public virtual ActionResult Edit(int id)
        {
            var entity = Repository.GetByPrimaryKey(id);

            if (entity == null)
            {
                return(ToIndex());
            }
            WebContext.Model = entity;

            var list = GetIndexEntities().ToList();

            if (Settings.ListSettings.Levels)
            {
                list = PlainTree.GetTree(list);
            }
            var prev = list.TakeWhile(e => e.Id != id).LastOrDefault();

            WebContext.PrevId = prev == null ? null : (int?)prev.Id;
            var next = list.SkipWhile(e => e.Id != id).Skip(1).Take(1).FirstOrDefault();

            WebContext.NextId = next == null ? null : (int?)next.Id;

            PrepareEntity(entity);
            return(View(EditViewName, entity));
        }
示例#2
0
        public virtual ActionResult Index(int?page, string order, string desc)
        {
            var indexList = GetIndexEntities().ToList();

            indexList = InitFiltersAndFilterList(indexList);
            indexList = OrderList(indexList, order, desc);
            var itemsCount = indexList.Count;

            indexList = BrakeIntoPagesList(page, itemsCount, indexList);
            if (Settings.ListSettings.Levels)
            {
                indexList = PlainTree.GetTree(indexList);
            }
            var filterParameters = new FilterParameters
            {
                ItemsCount = itemsCount,
                Page       = page,
                PageSize   = Settings.ListSettings.PageSize
            };

            return(View(IndexViewName, GetIndexViewModel(indexList, filterParameters)));
        }
示例#3
0
        public override void Execute()
        {
            WriteLiteral("\r\n");


            #line 10 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"


            /*  описание свойств:
             *
             *
             *          string Data - имя ключа, по которому можно получить список элементов для селекта
             *          string OptionTitle - текст
             *          string OptionValue - ключ
             *          List<OptionSettings> Options - предпределённые элементы
             *          bool Levels - использует ли вложенность
             *          bool Multiple - доступен ли множественный выбор
             *
             *          string TypeName - тип, с помощью которого можно получить данные
             *          string PropertyName - свойство, возвращающее список доступных элементов (работает только при указанном типе)
             *          string MethodName - метод, возвращающий список доступных элементов (работает только при указанном типе)
             *
             * если по данным ничего не установлено, берутся значения из бд по типу
             *
             *
             *  принцип работы
             *     берём текущее значение из модели
             *     если оно не указано, смотрим, есть ли такое значение в предопределённых (PreValue должно быть выставлено в true), если да, то устанавливаем именно его
             *
             *      получаем данные: сначала просматривается свойство Data, если оно пустое, то тип, в котором свойство или метод, через которые и получаем данные
             *
             *
             */


            var fieldSettings = (SelectSettings)WebContext.FieldSettings;

            var model = TypeHelpers.GetPropertyValue(WebContext.Model, fieldSettings.Name, null); // текущее значение свойства

            var modelString = model != null?model.ToString() : "";

            if (fieldSettings.PreValue && string.IsNullOrEmpty(modelString))
            {
                modelString = Session[string.Format("prevalue_{0}_{1}", fieldSettings.Name, ViewBag.EditViewModel.FormData.GetType().Name)];
            }

            IEnumerable <object> data = null;

            if (!string.IsNullOrEmpty(fieldSettings.Data))
            {
                data = (IEnumerable <object>)WebContext.ViewData[fieldSettings.Data];
            }
            else if (!string.IsNullOrEmpty(fieldSettings.TypeName))
            {
                if (!string.IsNullOrEmpty(fieldSettings.PropertyName))
                {
                    data = (IEnumerable <object>)TypeHelpers.GetPropertyValue(fieldSettings.TypeName, fieldSettings.PropertyName);
                }
                else if (!string.IsNullOrEmpty(fieldSettings.MethodName))
                {
                    data = (IEnumerable <object>)TypeHelpers.ExecuteMethod(fieldSettings.TypeName, fieldSettings.MethodName);
                }
            }
            else if (!string.IsNullOrEmpty(fieldSettings.Reference))
            {
                var db = ((OziController)ViewContext.Controller).DataModelContext;
                if (db != null)
                {
                    var t = TypeHelpers.GetPropertyType(WebContext.ModelType, fieldSettings.GetFullPropertyName());
                    var d = TypeHelpers.GetEntitySet(db, t).Cast <IEntity>();

                    if (typeof(ISortableEntity).IsAssignableFrom(t))
                    {
                        d = d.OrderBy(entity => ((ISortableEntity)entity).Sort);
                    }

                    if (fieldSettings.Levels)
                    {
                        d = PlainTree.GetTree(d.Cast <IPlainTreeItem>().Where(p => WebContext.Model == null || (p.GetType() != WebContext.Model.GetType() || (p.ParentId != WebContext.Model.Id || p.ParentId == null) && p.Id != WebContext.Model.Id)));
                    }
                    data = d.ToList();
                }
            }


            #line default
            #line hidden
            WriteLiteral("\r\n\r\n");


            #line 88 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
            if (!fieldSettings.Editable)
            {
            #line default
            #line hidden
                WriteLiteral("    <select");

                WriteAttribute("name", Tuple.Create(" name=\"", 3455), Tuple.Create("\"", 3500)

            #line 91 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 3462), Tuple.Create <System.Object, System.Int32>(ViewData.TemplateInfo.HtmlFieldPrefix

            #line default
            #line hidden
                                                                                                                 , 3462), false)
                               );

                WriteLiteral(" class=\"ozi-select\"");

                WriteLiteral(" \r\n        ");


            #line 92 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                if (fieldSettings.Multiple)
                {
            #line default
            #line hidden
                    WriteLiteral("            ");

                    WriteLiteral("multiple=\"multiple\" style=\"width: 400px;\"");

                    WriteLiteral("\r\n");


            #line 95 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    if (fieldSettings.Height != 0)
                    {
            #line default
            #line hidden
                        WriteLiteral("                ");

                        WriteLiteral("size=\"");


            #line 97 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        Write(fieldSettings.Height);


            #line default
            #line hidden
                        WriteLiteral("\"");

                        WriteLiteral("\r\n");


            #line 98 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    }
                }


            #line default
            #line hidden
                WriteLiteral("        ");


            #line 100 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                if (fieldSettings.Disabled)
                {
            #line default
            #line hidden
                    WriteLiteral(" ");

                    WriteLiteral("disabled=\"disabled\"");

                    WriteLiteral(" ");


            #line 101 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("        ");


            #line 102 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                if (fieldSettings.Readonly)
                {
            #line default
            #line hidden
                    WriteLiteral(" ");

                    WriteLiteral("readonly=\"readonly\"");


            #line 103 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                }

            #line default
            #line hidden
                WriteLiteral(">\r\n        \r\n");


            #line 105 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"


            #line default
            #line hidden

            #line 105 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                foreach (OptionSettings option in fieldSettings.Options)
                {
            #line default
            #line hidden
                    WriteLiteral("<option ");


            #line 106 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    Write(IsValue(option.Value, model, modelString));


            #line default
            #line hidden
                    WriteLiteral(" value=\"");


            #line 106 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    Write(option.Value);


            #line default
            #line hidden
                    WriteLiteral("\">");


            #line 106 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    Write(option.Title);


            #line default
            #line hidden
                    WriteLiteral("</option>");


            #line 106 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("        ");


            #line 107 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                if (data != null)
                {
                    foreach (var option in data)
                    {
                        var optionValue = TypeHelpers.GetPropertyValue(option, fieldSettings.OptionValue).ToString();
                        var value       = TypeHelpers.GetPropertyValue(option, fieldSettings.OptionTitle);
                        if (fieldSettings.Localizable && value is Guid)
                        {
                            value = Lp.GetMessage((Guid)value);
                        }


            #line default
            #line hidden
                        WriteLiteral("                <option ");


            #line 117 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        Write(IsValue(optionValue, model, modelString));


            #line default
            #line hidden
                        WriteLiteral(" value=\"");


            #line 117 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        Write(optionValue);


            #line default
            #line hidden
                        WriteLiteral("\">");


            #line 117 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        if (fieldSettings.Levels)
                        {
                            for (var i = 0; i < (Int32.Parse(TypeHelpers.GetPropertyValue(option, "Level").ToString()) - 1); i++)
                            {
            #line default
            #line hidden
                                WriteLiteral("&nbsp;-&nbsp;");


            #line 120 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                            }

            #line default
            #line hidden
                            WriteLiteral("○&nbsp;");

                            WriteLiteral(" ");


            #line 120 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        }

            #line default
            #line hidden

            #line 120 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        Write(value);


            #line default
            #line hidden
                        WriteLiteral("</option>\r\n");


            #line 121 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    }
                }


            #line default
            #line hidden
                WriteLiteral("    </select>\r\n");


            #line 124 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
            }
            else
            {
                string val   = string.Empty;
                string label = string.Empty;
                if (model != null)
                {
                    if (fieldSettings.Multiple)
                    {
                        label = string.Join(", ", ((IListSource)model).GetList().Cast <object>().ToList().Select <object, string>(a => (TypeHelpers.GetPropertyValue(a, fieldSettings.OptionTitle)).ToString()));
                    }
                    else
                    {
                        label = (TypeHelpers.GetPropertyValue(model, fieldSettings.OptionTitle)).ToString();
                        val   = (TypeHelpers.GetPropertyValue(model, fieldSettings.OptionValue)).ToString();
                    }
                }


            #line default
            #line hidden
                WriteLiteral("    <input");

                WriteLiteral(" type=\"hidden\"");

                WriteAttribute("name", Tuple.Create(" name=\"", 5826), Tuple.Create("\"", 5883)

            #line 141 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5833), Tuple.Create <System.Object, System.Int32>(fieldSettings.Name

            #line default
            #line hidden
                                                                                                                 , 5833), false)
                               , Tuple.Create(Tuple.Create("", 5854), Tuple.Create(".", 5854), true)

            #line 141 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5855), Tuple.Create <System.Object, System.Int32>(fieldSettings.OptionValue

            #line default
            #line hidden
                                                                                                                 , 5855), false)
                               );

                WriteAttribute("id", Tuple.Create(" id=\"", 5884), Tuple.Create("\"", 5939)

            #line 141 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5889), Tuple.Create <System.Object, System.Int32>(fieldSettings.Name

            #line default
            #line hidden
                                                                                                                 , 5889), false)
                               , Tuple.Create(Tuple.Create("", 5910), Tuple.Create("_", 5910), true)

            #line 141 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5911), Tuple.Create <System.Object, System.Int32>(fieldSettings.OptionValue

            #line default
            #line hidden
                                                                                                                 , 5911), false)
                               );

                WriteAttribute("value", Tuple.Create(" value=\"", 5940), Tuple.Create("\"", 5952)

            #line 141 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5948), Tuple.Create <System.Object, System.Int32>(val

            #line default
            #line hidden
                                                                                                                 , 5948), false)
                               );

                WriteLiteral(" />\r\n");

                WriteLiteral("    <input");

                WriteAttribute("value", Tuple.Create(" value=\"", 5968), Tuple.Create("\"", 5982)

            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                               , Tuple.Create(Tuple.Create("", 5976), Tuple.Create <System.Object, System.Int32>(label

            #line default
            #line hidden
                                                                                                                 , 5976), false)
                               );

                WriteLiteral(" class=\"autocomplete ozi-string\"");

                WriteLiteral(" type=\"text\"");

                WriteLiteral(" ");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(Html.Raw(ByCondition(fieldSettings.Multiple, "multiple='true'")));


            #line default
            #line hidden
                WriteLiteral(" data-hiddenid=\"");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.Name);


            #line default
            #line hidden
                WriteLiteral("_");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.OptionValue);


            #line default
            #line hidden
                WriteLiteral("\" data-sourcename=\"");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.Name);


            #line default
            #line hidden
                WriteLiteral("\" name=\"");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.Name);


            #line default
            #line hidden
                WriteLiteral(".");


            #line 142 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.OptionTitle);


            #line default
            #line hidden
                WriteLiteral("\" />\r\n");

                WriteLiteral("    <script>\r\n        var d;\r\n        try {\r\n            d = $(\"body\").data(\"");


            #line 146 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.Name);


            #line default
            #line hidden
                WriteLiteral("\");\r\n        } catch(e) {\r\n            \r\n        }\r\n        if (!d) {\r\n          " +
                             "      d = [\r\n");


            #line 152 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"


            #line default
            #line hidden

            #line 152 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                foreach (var option in data)
                {
                    var optionValue = TypeHelpers.GetPropertyValue(option, fieldSettings.OptionValue).ToString();
                    var value       = TypeHelpers.GetPropertyValue(option, fieldSettings.OptionTitle);


            #line default
            #line hidden
                    WriteLiteral("                        ");

                    WriteLiteral("{ value: \'");


            #line 156 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    Write(optionValue);


            #line default
            #line hidden
                    WriteLiteral("\', label : \'");


            #line 156 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    if (fieldSettings.Levels)
                    {
                        for (var i = 0; i < (Int32.Parse(TypeHelpers.GetPropertyValue(option, "Level").ToString()) - 1); i++)
                        {
            #line default
            #line hidden
                            WriteLiteral("&nbsp;-&nbsp;");


            #line 156 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                        }

            #line default
            #line hidden
                        WriteLiteral("○&nbsp;");


            #line 156 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    }

            #line default
            #line hidden

            #line 156 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                    Write(value);


            #line default
            #line hidden
                    WriteLiteral("\'},");

                    WriteLiteral("\r\n");


            #line 157 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("                ];\r\n                $(\"body\").data(\"");


            #line 159 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
                Write(fieldSettings.Name);


            #line default
            #line hidden
                WriteLiteral("\", d);\r\n            }\r\n    </script>\r\n");


            #line 162 "..\..\Areas\Admin\Views\Shared\EditorTemplates\ozi_Select.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("\r\n\r\n\r\n");
        }