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); }
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ý 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); }
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); }