Ejemplo n.º 1
0
        protected override void OnCreating(ControlFormResult <UserModel> controlForm)
        {
            controlForm.AddProperty("Password", new ControlTextAttribute
            {
                Type              = ControlText.Password,
                MaxLength         = 128,
                Required          = true,
                LabelText         = "Password",
                ContainerCssClass = "col-xs-6 col-md-6",
                ContainerRowIndex = 1
            });
            controlForm.AddProperty("ConfirmPassword", new ControlTextAttribute
            {
                Type              = ControlText.Password,
                MaxLength         = 128,
                Required          = true,
                EqualTo           = "Password",
                LabelText         = "Confirm Password",
                ContainerCssClass = "col-xs-6 col-md-6",
                ContainerRowIndex = 1
            });

            var callbackUrl = Request.QueryString["callbackUrl"];

            if (!string.IsNullOrEmpty(callbackUrl))
            {
                controlForm.AddHiddenValue("CallbackUrl", callbackUrl);
            }

            controlForm.ShowBoxHeader        = false;
            controlForm.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml;
            controlForm.FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml;
        }
        public ActionResult InstallerModuleFileZip()
        {
            var result = new ControlFormResult
            {
                Title                = T("Installer module").Text,
                FormActionUrl        = Url.Action("SaveModule"),
                CssClass             = "form-edit-page",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml,
                FormMethod           = FormMethod.Post,
                IsAjaxSupported      = false
            };


            result.AddProperty("AssemblyName", new ControlTextAttribute
            {
                Required          = true,
                MaxLength         = 255,
                LabelText         = "Assembly Name",
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, string.Empty);

            result.AddProperty("UploadedFile", new ControlFileUploadAttribute
            {
                EnableFineUploader = false,
                LabelText          = T("Hãy nén module định dạng .zip"),
                ContainerCssClass  = "col-md-6",
                ContainerRowIndex  = 2,
                AllowedExtensions  = "*.zip",
            }, string.Empty);

            return(result);
        }
Ejemplo n.º 3
0
        public override void BindControlField(ControlFormResult controlForm, object value)
        {
            var attribute = new ControlGridAttribute(MinPhotos, MaxPhotos)
            {
                PropertyName     = Name,
                LabelText        = Title,
                PropertyType     = typeof(List <MediaPart>),
                ShowLabelControl = false,
                EnabledScroll    = true
            };

            controlForm.AddProperty(Name, attribute, value);
        }
Ejemplo n.º 4
0
        public override void BindControlField(ControlFormResult controlForm, object value)
        {
            var attribute = new ControlNumericAttribute
            {
                LabelText         = Title,
                Required          = Required,
                Order             = Position,
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 10
            };

            controlForm.AddProperty(Name, attribute, value);
        }
Ejemplo n.º 5
0
        public override void BindControlField(ControlFormResult controlForm, object value)
        {
            var attribute = new ControlTextAttribute();

            switch (TextType)
            {
            case TextFieldType.SingleLine:
                attribute.Type      = ControlText.TextBox;
                attribute.MaxLength = MaxLength;
                break;

            case TextFieldType.Email:
                attribute.Type      = ControlText.Email;
                attribute.MaxLength = MaxLength;
                break;

            case TextFieldType.Url:
                attribute.Type      = ControlText.Url;
                attribute.MaxLength = MaxLength;
                break;

            case TextFieldType.MultiLine:
                attribute.Type = ControlText.MultiText;
                break;

            case TextFieldType.RichText:
                attribute.Type = ControlText.RichText;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            attribute.LabelText         = Title;
            attribute.Required          = Required;
            attribute.Order             = Position;
            attribute.ContainerCssClass = "col-md-6";
            attribute.ContainerRowIndex = 10;

            if (TextType == TextFieldType.RichText || TextType == TextFieldType.MultiLine)
            {
                attribute.ContainerCssClass = "col-md-12";
            }

            controlForm.AddProperty(Name, attribute, value);
        }
Ejemplo n.º 6
0
        public override void BindControlField(ControlFormResult controlForm, object value)
        {
            var attribute = new ControlGridAttribute(0, MaxPhotos)
            {
                PropertyName     = Name,
                LabelText        = Title,
                PropertyType     = typeof(List <PictureTooltip>),
                ShowLabelControl = false,
                EnabledScroll    = true
            };

            controlForm.RegisterExternalDataSource(Name + ".Button", "moregold", "moregrey", "moreblack", "moredarkblue", "moreblue", "morelightblue", "morelightblue2", "morewatergreen", "morelightgreen", "moregreen", "moreyellow", "moreorange", "morered", "morepurple", "moreviolet", "morelightviolet", "morefucsia");
            controlForm.RegisterExternalDataSource(Name + ".Background", "bgblack", "bgwhite");
            controlForm.RegisterExternalDataSource(Name + ".Round", "roundBgW", "roundBgB");
            controlForm.RegisterExternalDataSource(Name + ".AnimationType", "ltr-slide", "rtl-slide", "btt-slide", "ttb-slide");

            controlForm.AddProperty(Name, attribute, value);
        }
Ejemplo n.º 7
0
        public override void BindControlField(ControlFormResult controlForm, object value)
        {
            ControlChoiceAttribute attribute;

            switch (ChoiceType)
            {
            case ChoiceFieldType.DropDownList:
                attribute = new ControlChoiceAttribute(ControlChoice.DropDownList);
                break;

            case ChoiceFieldType.RadioButtonList:
                attribute = new ControlChoiceAttribute(ControlChoice.RadioButtonList);
                break;

            case ChoiceFieldType.CheckboxiesList:
                attribute = new ControlChoiceAttribute(ControlChoice.CheckBoxList);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            attribute.LabelText         = Title;
            attribute.Required          = Required;
            attribute.Order             = Position;
            attribute.ContainerCssClass = "col-md-6";
            attribute.ContainerRowIndex = 10;

            var split           = Values.Split(System.Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var selectListItems = split.Select(str => new SelectListItem {
                Text = str, Value = str
            }).ToList();

            if (!Required && ChoiceType == ChoiceFieldType.DropDownList)
            {
                selectListItems.Insert(0, new SelectListItem());
            }

            attribute.SelectListItems = selectListItems;

            controlForm.AddProperty(Name, attribute, value);
        }
        public ActionResult Unsubscribe()
        {
            WorkContext.Breadcrumbs.Add(T("Newsletters"));
            WorkContext.Breadcrumbs.Add(T("Unsubscribe"));

            var result = new ControlFormResult()
            {
                Title            = T("Unsubscribe").Text,
                UpdateActionName = "UnsubscribePost",
                SubmitButtonText = T("Submit")
            };

            result.AddProperty("EmailAddress", new ControlTextAttribute
            {
                Name              = "EmailAddress",
                LabelText         = "Email Address",
                ContainerCssClass = "col-sm-6 col-md-6",
                PropertyType      = typeof(string)
            });

            return(result);
        }
Ejemplo n.º 9
0
        private ActionResult UserProfile(int userId, bool editMode = false)
        {
            var result = new ControlFormResult
            {
                UpdateActionName = "UpdateProfile",
                SubmitButtonText = T("Save").Text,
                ReadOnly         = !editMode
            };

            string title;
            bool   onlyPublicProperties = false;

            if (editMode)
            {
                if (userId == WorkContext.CurrentUser.Id)
                {
                    title = T("Edit My Profile");
                }
                else if (WorkContext.CurrentUser.SuperUser || CheckPermission(StandardPermissions.FullAccess))
                {
                    title = T("Edit Profile");
                }
                else
                {
                    return(new HttpUnauthorizedResult());
                }
            }
            else
            {
                if (userId == WorkContext.CurrentUser.Id)
                {
                    title = T("My Profile");

                    result.AddAction(addToTop: false)
                    .HasText(T("Edit"))
                    .HasUrl(Url.Action("EditMyProfile"))
                    .HasButtonStyle(ButtonStyle.Primary);
                }
                else if (WorkContext.CurrentUser.SuperUser || CheckPermission(StandardPermissions.FullAccess))
                {
                    var user = service.GetUser(userId);
                    title = string.Format(T("Profile for '{0}'", user.UserName));

                    result.AddAction(addToTop: false)
                    .HasText(T("Edit"))
                    .HasUrl(Url.Action("EditProfile", RouteData.Values.Merge(new { userId })))
                    .HasButtonStyle(ButtonStyle.Primary);
                }
                else
                {
                    var user = service.GetUser(userId);
                    title = string.Format(T("Profile for '{0}'", user.UserName));
                    onlyPublicProperties = true;
                }

                result.CancelButtonText = T("Close");
            }

            result.Title = title;

            result.AddHiddenValue("UserId", userId.ToString());

            bool hasProperties = false;

            foreach (var provider in userProfileProviders.Value)
            {
                var newGroup = result.AddGroupedLayout(provider.Category);

                foreach (var field in provider.GetFields(WorkContext, userId, onlyPublicProperties))
                {
                    hasProperties = true;

                    result.AddProperty(field.Name, field, field.Value);
                    newGroup.Add(field.Name);
                }
            }

            if (!hasProperties)
            {
                return(new ContentViewResult
                {
                    Title = title,
                    BodyContent = T("There is no profile available to view.")
                });
            }

            return(result);
        }
        public ActionResult Edit(int id)
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý đối tác"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Sửa thông tin đối tác"), Url = Url.Action("Index")
            });

            var          service   = WorkContext.Resolve <IPartnerService>();
            var          records   = service.GetRecords(x => x.Id == id || x.RefId == id);
            PartnerModel model     = records.First(x => x.Id == id);
            var          modelType = model.GetType();

            var result = new ControlFormResult <PartnerModel>(model);

            result.Title            = this.T("Sửa thông tin đối tác");
            result.FormMethod       = FormMethod.Post;
            result.Layout           = ControlFormLayout.Tab;
            result.UpdateActionName = "Update";
            result.ShowCancelButton = false;
            result.ShowBoxHeader    = false;

            result.RegisterFileUploadOptions("Logo.FileName", new ControlFileUploadOptions
            {
                AllowedExtensions = "jpg,jpeg,png,gif"
            });

            var mainTab           = result.AddTabbedLayout("Thông tin chính");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = modelType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);
            var listHidden      = new List <string>
            {
                "Id", "SortOrder", "Logo", "PhoneNumber", "Email", "Website"
            };

            if (languages.Count > 0)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = records.FirstOrDefault(x => x.LanguageCode == language.CultureCode) ?? model;

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (listHidden.Contains(controlAttribute.Key))
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }
                }
            }

            result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Create")).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);
            return(result);
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int id)
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý chuyên mục"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Sửa thông tin chuyên mục"), Url = Url.Action("Index")
            });

            var             service   = WorkContext.Resolve <ICategoriesService>();
            var             records   = service.GetRecords(x => x.Id == id || x.RefId == id);
            CategoriesModel model     = records.First(x => x.Id == id);
            var             modelType = model.GetType();

            var result = new ControlFormResult <CategoriesModel>(model);

            result.Title            = this.T("Sửa thông chuyên mục");
            result.FormMethod       = FormMethod.Post;
            result.Layout           = ControlFormLayout.Tab;
            result.UpdateActionName = "Update";
            result.ShowCancelButton = false;
            result.ShowBoxHeader    = false;

            result.ExcludeProperty(x => x.Alias);
            result.ExcludeProperty(x => x.Name);
            result.ExcludeProperty(x => x.ShortName);
            result.ExcludeProperty(x => x.Url);
            result.ExcludeProperty(x => x.Tags);
            result.ExcludeProperty(x => x.Notes);
            result.ExcludeProperty(x => x.Description);
            result.ExcludeProperty(x => x.Tags);

            var mainTab           = result.AddTabbedLayout("Thông tin chính");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = modelType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);
            var listHidden      = new List <string>
            {
                "Id", "OrderBy", "MenuOrderBy", "ParentId",
                "HasChilden", "IsHome", "IsActived",
                "IsDeleted", "IsDisplayMenu", "IsDisplayFooter"
            };

            if (languages.Count > 0)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = records.FirstOrDefault(x => x.LanguageCode == language.CultureCode) ?? model;

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (listHidden.Contains(controlAttribute.Key))
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }
                }
            }
            result.RegisterExternalDataSource(x => x.ParentId, BindCategories());

            result.AddAction().HasText(T("Add Images")).HasUrl(Url.Action("Edit", "AdminImages", new { id = 0, cateId = model.Id, articlesId = 0 })).HasButtonStyle(ButtonStyle.Info);
            result.AddAction().HasText(this.T("Clear")).HasUrl(this.Url.Action("Edit", RouteData.Values.Merge(new { id = 0 }))).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);

            return(result);
        }
Ejemplo n.º 12
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var listItem = listItemService.GetById(id);
            var list     = listService.GetById(listItem.ListId);

            var result = new ControlFormResult
            {
                Title            = T("Edit List Item").Text,
                UpdateActionName = "Update",
                CssClass         = "form-edit-list-item"
            };

            result.AddProperty("Id", new ControlHiddenAttribute(), listItem.Id);
            result.AddProperty("ListId", new ControlHiddenAttribute(), listItem.ListId);
            result.AddProperty("Title", new ControlTextAttribute
            {
                LabelText         = "Title",
                Required          = true,
                MaxLength         = 255,
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, listItem.Title);

            result.AddProperty("Slug", new ControlSlugAttribute
            {
                LabelText         = "Slug",
                Required          = true,
                MaxLength         = 255,
                HelpText          = string.Format(T("List item url will become {0}/{{slug}}").Text, list.Url),
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, listItem.Slug);

            result.AddProperty("PictureUrl", new ControlFileUploadAttribute
            {
                EnableFineUploader = true,
                LabelText          = "Picture Url",
                UploadFolder       = list.Name,
                ContainerCssClass  = "col-md-6",
                ContainerRowIndex  = 1
            }, listItem.PictureUrl);

            var categories     = listCategoryService.GetCategories(listItem.ListId);
            var selectLists    = new List <SelectListItem>();
            var rootCategories = categories.Where(x => x.ParentId == null).OrderBy(x => x.Position).ThenBy(x => x.Name);

            GetCategoriesSelectList(rootCategories, selectLists, categories, "");

            var itemCategories = listCategoryService.GetItemCategories(id);

            result.AddProperty("Categories", new ControlChoiceAttribute(ControlChoice.DropDownList)
            {
                LabelText         = "Categories",
                SelectListItems   = selectLists,
                PropertyType      = typeof(string),
                EnableChosen      = true,
                AllowMultiple     = true,
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 1
            }, itemCategories);

            if (list.EnabledMetaTags)
            {
                result.AddProperty("MetaKeywords", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Keywords",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, listItem.MetaKeywords);
                result.AddProperty("MetaDescription", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Description",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, listItem.MetaDescription);
            }

            result.AddProperty("Position", new ControlNumericAttribute
            {
                LabelText         = "Position",
                Required          = true,
                PropertyType      = typeof(int),
                ContainerCssClass = "col-md-1",
                ContainerRowIndex = 3
            }, listItem.Position);

            result.AddProperty("Enabled", new ControlChoiceAttribute(ControlChoice.CheckBox)
            {
                LabelText         = "",
                AppendText        = "Enabled",
                PropertyType      = typeof(bool),
                ContainerCssClass = "col-md-1",
                ContainerRowIndex = 3
            }, listItem.Enabled);

            var fields = listFieldService.GetFields(listItem.ListId);

            IDictionary <string, object> values;

            if (!string.IsNullOrEmpty(listItem.Values))
            {
                try
                {
                    values = listItem.Values.SharpDeserialize <IDictionary <string, object> >();
                }
                catch
                {
                    values = new Dictionary <string, object>();
                }
            }
            else
            {
                values = new Dictionary <string, object>();
            }

            foreach (var field in fields)
            {
                var value = values.ContainsKey(field.Name) ? values[field.Name] : null;
                field.BindControlField(result, value);
            }

            WorkContext.Breadcrumbs.Add(T("Manage Lists"), Url.Action("Index", "List"));
            WorkContext.Breadcrumbs.Add(list.Name, Url.Action("Index", "ListItem", new { listId = list.Id }));

            return(result);
        }
Ejemplo n.º 13
0
        public ActionResult Create(int listId)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var list = listService.GetById(listId);

            var result = new ControlFormResult
            {
                Title            = T("Create List Item").Text,
                UpdateActionName = "Update",
                CssClass         = "form-edit-list-item",
            };

            result.AddProperty("Id", new ControlHiddenAttribute(), 0);
            result.AddProperty("ListId", new ControlHiddenAttribute(), listId);
            result.AddProperty("Title", new ControlTextAttribute
            {
                Required          = true,
                MaxLength         = 255,
                LabelText         = "Title",
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, string.Empty);

            result.AddProperty("Slug", new ControlSlugAttribute
            {
                MaxLength         = 255,
                HelpText          = string.Format(T("List item url will become {0}/{{slug}}").Text, list.Url),
                LabelText         = "Slug",
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, string.Empty);

            result.AddProperty("PictureUrl", new ControlFileUploadAttribute
            {
                EnableFineUploader = true,
                LabelText          = "Picture Url",
                UploadFolder       = list.Name,
                ContainerCssClass  = "col-md-6",
                ContainerRowIndex  = 1
            }, string.Empty);

            var categories     = listCategoryService.GetCategories(listId);
            var selectList     = new List <SelectListItem>();
            var rootCategories = categories.Where(x => x.ParentId == null).OrderBy(x => x.Position).ThenBy(x => x.Name);

            GetCategoriesSelectList(rootCategories, selectList, categories, "");

            result.AddProperty("Categories", new ControlChoiceAttribute(ControlChoice.DropDownList)
            {
                LabelText         = "Categories",
                SelectListItems   = selectList,
                PropertyType      = typeof(string),
                EnableChosen      = true,
                AllowMultiple     = true,
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 1
            }, new Guid[] { });

            if (list.EnabledMetaTags)
            {
                result.AddProperty("MetaKeywords", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Keywords",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, string.Empty);

                result.AddProperty("MetaDescription", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Description",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, string.Empty);
            }

            result.AddProperty("Position", new ControlNumericAttribute
            {
                Required          = true,
                PropertyType      = typeof(int),
                LabelText         = "Position",
                ContainerCssClass = "col-md-1",
                ContainerRowIndex = 3
            }, 0);

            result.AddProperty("Enabled", new ControlChoiceAttribute(ControlChoice.CheckBox)
            {
                PropertyType      = typeof(bool),
                LabelText         = "",
                AppendText        = "Enabled",
                ContainerCssClass = "col-md-2",
                ContainerRowIndex = 3
            }, true);

            var fields = listFieldService.GetFields(listId);

            foreach (var field in fields)
            {
                field.BindControlField(result, string.Empty);
            }

            return(result);
        }
Ejemplo n.º 14
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(WidgetPermissions.ManageWidgets))
            {
                return(new HttpUnauthorizedResult());
            }

            var widgetService = WorkContext.Resolve <IWidgetService>();
            var records       = widgetService.GetRecords(x => x.Id == id || x.RefId == id);
            var widgets       = widgetService.GetWidgets(records);
            var widget        = widgets.First(x => x.Id == id);
            var widgetType    = widget.GetType();

            WorkContext.Breadcrumbs.Add(T("Widgets"), Url.Action("Index"));
            WorkContext.Breadcrumbs.Add(widget.Title);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var result = new ControlFormResult <IWidget>(widget, widgetType)
            {
                Title                = T("Edit Widget").Text,
                UpdateActionName     = "Update",
                Layout               = ControlFormLayout.Tab,
                ShowCloseButton      = true,
                IsAjaxSupported      = false,
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            result.AddHiddenValue("WidgetType", GetFullTypeName(widget.GetType()));
            if (widget.PageId.HasValue)
            {
                result.AddHiddenValue("PageId", widget.PageId.Value.ToString());
            }

            var mainTab           = result.AddTabbedLayout("Widget Settings");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = widgetType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            result.ExcludeProperty(x => x.Localized);
            if (!widget.HasTitle)
            {
                result.ExcludeProperty(x => x.ShowTitleOnPage);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);

            if (languages.Count > 1)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = widgets.FirstOrDefault(x => x.CultureCode == language.CultureCode) ??
                                            widget.ShallowCopy();

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (controlAttribute.Key == "Id")
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }

                    if (!widget.HasTitle)
                    {
                        result.ExcludeProperty("Title." + language.CultureCode);
                        result.ExcludeProperty("ShowTitleOnPage." + language.CultureCode);
                    }
                }
            }

            var zoneService = WorkContext.Resolve <IZoneService>();
            var zones       = zoneService.GetRecords().ToDictionary(x => x.Id, x => x.Name);

            result.RegisterExternalDataSource(x => x.ZoneId, zones);

            return(widget.BuildEditor(this, WorkContext, result));
        }
        public ActionResult Edit(int id)
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý tuyển dụng"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Sửa thông tin tuyển dụng"), Url = Url.Action("Index")
            });

            var records            = service.GetRecords(x => x.Id == id || x.RefId == id);
            RecruitmentModel model = records.First(x => x.Id == id);
            var modelType          = model.GetType();

            if (string.IsNullOrEmpty(model.Contents) || model.Contents.Trim() == "<br />")
            {
                var viewRenderer = new ViewRenderer {
                    Context = ControllerContext
                };
                var viewTemplate = viewRenderer.RenderPartialView(string.Format(Extensions.Constants.ViewRecruitmentTemplate, WorkContext.CurrentCulture), null);
                model.Contents = viewTemplate;
            }

            var result = new ControlFormResult <RecruitmentModel>(model);

            result.Title            = this.T("Sửa thông tin tuyển dụng");
            result.FormMethod       = FormMethod.Post;
            result.Layout           = ControlFormLayout.Tab;
            result.UpdateActionName = "Update";
            result.ShowCancelButton = false;
            result.ShowBoxHeader    = false;

            result.ExcludeProperty(x => x.Alias);
            result.ExcludeProperty(x => x.Contents);
            result.ExcludeProperty(x => x.Position);
            result.ExcludeProperty(x => x.Summary);
            result.ExcludeProperty(x => x.Title);
            result.ExcludeProperty(x => x.TimeWork);

            var mainTab           = result.AddTabbedLayout("Thông tin chính");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = modelType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);
            var listHidden      = new List <string>
            {
                "Id", "CategoryId", "IsDeleted", "FinishDate"
            };

            if (languages.Count > 0)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = records.FirstOrDefault(x => x.LanguageCode == language.CultureCode) ?? model;

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (listHidden.Contains(controlAttribute.Key))
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }
                }
            }
            result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Create")).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);

            result.RegisterExternalDataSource(x => x.CategoryId, y => BindCategories());

            return(result);
        }