The site may contain modules such as articles, products, pictures, messages, and so on.
The main functions of the column module, enabling or disabling modules, module permissions settings, module upload settings and so on.
permission settings and upload settings are specifically considered later, to show or disable the module first.
1. Add an administrative connection in the top navigation bar
Open home/header.cshtml, add code in <nav>
2. Add Module interface
usingNinesky.models;usingSystem.Linq;namespaceninesky.areas.admin.repository{/// <summary> ///Background Management Module interface/// <remarks> ///Version v1.0///Create 2013.12.10/// </remarks> /// </summary> InterfaceInterfaceModule:Ninesky.Repository.InterfaceModule {/// <summary> ///Find Module/// </summary> /// <returns>List of all modules</returns>Iqueryable<module>Find (); /// <summary> ///Modifying module information/// </summary> /// <param name= "module" >Module</param> /// <returns>whether the modification was successful</returns> BOOLModify (module module); }}
3. Interface Example
usingNinesky.models;usingSystem.Linq;namespaceninesky.areas.admin.repository{/// <summary> ///Module Interface Example/// <remarks> ///Version v1.0///Create 2013.12.12/// </remarks> /// </summary> Public classModulerepository:ninesky.repository.modulerepository,interfacemodule { PublicIqueryable<module>Find () {returnNcontext.modules; } Public BOOLModify (module module) {NContext.Modules.Attach (module); Ncontext.entry<Module> (Module). State =System.Data.EntityState.Modified; returnNcontext.savechanges () >0; } }}
4. Add Controller Modulecontroller
First, add an action that implements the return module list
/// <summary> /// List /// </summary> /// <param name= "Enable" > enabled state. "0-All, 1-enabled, 2-disabled"</param>// <returns>// A view that contains strongly typed list\<Module\> is returned on a normal request <br/>// Ajax request return JSON type list\<Module\>// </returns> public actionresult Items (int0) { var _ Modules = modulerepository.find (); if return Json (_modules); return View (_modules); }
Menu
/// <summary> /// Menu /// </summary> /// <returns></returns> Public actionresult Menu () { return Partialview (Modulerepository.find ()); }
Menu View
@model IEnumerable<Ninesky. Models.module><DivID= "Westmenu"class= "Easyui-accordion"> <Divtitle= "Module List"class= "Leftsidebar"> <ul>@foreach (var item in Model) {<Li>@Html. ActionLink (item. Name, "Index", "Module", new {id = Item. ModuleID}, new {@class = "Westmenuitem"})</Li> } </ul> </Div></Div>@* @Scripts. Render ("~/areas/admin/scripts/category.js") *@<Scripttype= "Text/javascript">Westmenu ();</Script>
Module Information page
/// <summary> /// Module Information page /// </summary> /// <param name= "id" ></param> /// <returns></returns> Public ActionResult Index (int ID) { return Partialview ( Modulerepository.find (ID)); }
@model Ninesky.Models.Module<Divclass= "C_navbar">Background Management >> Module Management >> module information</Div><Divclass= "Easyui-tabs"> <Divtitle= "Basic Information"> <Divclass= "Fs_wapper">@using (Html.BeginForm ("Modify", "Module", FormMethod.Post, new {id = "module_base"})) { @Html. AntiForgeryToken () @Html. ValidationSummary (True)<Divclass= "header">@Html. hiddenfor (model = model. ModuleID)</Div>@Html. ValidationSummary ()<Tableclass= "FieldSet"> <TR> <th>@Html. labelfor (model = model. Name)<span>*</span></th> <TD>@Html. textboxfor (model = model. Name, new {disabled = "disabled"})</TD> </TR> <TR> <th>@Html. labelfor (model = model. Enable)<span>*</span></th> <TD>@Html. editorfor (model = model. Enable) @Html. validationmessagefor (model = model. Description)</TD> </TR> <TR> <th>@Html. labelfor (model = model. Model)<span>*</span></th> <TD>@Html. textboxfor (model = model. Model, new {disabled = "disabled"})</TD> </TR> <TR> <th>@Html. labelfor (model = model. Description)</th> <TD>@Html. editorfor (model = model. Description) @Html. validationmessagefor (model = model. Description)</TD> </TR> <TR> <th></th> <TD> <aID= "Btn_modulebase_save"class= "Easyui-linkbutton">Save</a> </TR> </Table>} @Scripts. Render ("~/areas/admin/scripts/module.js")<Script>Modulebase_ready (); </Script> </Div> </Div> <Divtitle= "Upload Settings">......</Div> <Divtitle= "Permission Settings">......</Div></Div>
Here the upload settings and permission settings are added later.
5. Add enable/disable module in controller to handle action
/// <summary> ///Modifying module information/// </summary> /// <returns></returns> PublicActionResult Modify (int? ModuleID,BOOL? Enable,stringDescription) {Jsonviewmodel _jsonviewmodel=NewJsonviewmodel () {authentication =0, Success =true }; BOOL_modifyed =false; if(ModuleID = =NULL) {_jsonviewmodel.success=false; _jsonviewmodel.validationlist.add ("ModuleID","module ID cannot be empty"); } if(Enable = =NULL) {_jsonviewmodel.success=false; _jsonviewmodel.validationlist.add ("Enable","enable state cannot be empty"); } if(_jsonviewmodel.success) {var_module = Modulerepository.find ((int) ModuleID); if(_module = =NULL) {_jsonviewmodel.success=false; _jsonviewmodel.message="Module exists"; } Else { if(_module. Enable! = enable) {_module. Enable = (BOOL) Enable; _modifyed =true; } if(_module. Description! = Description) {_module. Description = Description; _modifyed =true; } if(_modifyed) {if(Modulerepository.modify (_module)) {_jsonviewmodel.success =true; _jsonviewmodel.message ="Modify the module successfully. "; } Else{_jsonviewmodel.success =false; _jsonviewmodel.message ="data could not be saved to the database"; } } Else{_jsonviewmodel.success =false; _jsonviewmodel.message ="data has not changed"; } } } Else_jsonviewmodel.message ="Data validation failed! "; returnJson (_jsonviewmodel); }
6. Module Filter
Write a filter here, Modulefilter. Namespace Ninesky.extensions. function is added to the module above, when the module is closed, the front-desk users can not access the module content.
usingninesky.repository;usingSYSTEM.WEB.MVC;namespaceninesky.extensions{/// <summary> ///Module Filter///Masking Disabled Modules/// <remarks> ///Version v1.0///Create 2013.12.12/// </remarks> /// </summary> Public classModulefilter:actionfilterattribute {/// <summary> ///model name/// </summary> Public stringModel {Get;Set; } Public Override voidonactionexecuting (ActionExecutingContext filtercontext) {if(string. IsNullOrEmpty (Model)) Filtercontext.result =NewContentresult () {Content ="module not specified" }; Switch(Model) { Case "article": Interfacemodule _modulerepository=Newmodulerepository (); var_module =_modulerepository.find (Model); if(_module = =NULL) Filtercontext.result =NewContentresult () {Content ="specified module not found" }; Else if(!_module. Enable) Filtercontext.result =NewContentresult () {Content = _module. Name +"is closed" }; Break; default: Filtercontext.result=NewContentresult () {Content ="specified module not found" }; Break; } } }}
=================
Code Network disk or group Ninesky2013-12-12.zip