Web Controller Modify |
This example modifies the SOWI Web Administrator standard User controller
This topic contains the following sections:
Change the Data Item Toolbar. Adds a toolbar button called "Ticket Option" into toolbar data item list
Create a new class in folder Controllers
Tip: using the project item template SOWIClass
Inheritance the user web controller from SOWI Web Administrator
See also: SOWIWeb.Administrator.ControllersUserController
public class TicketUserController : SOWIWeb.Administrator.Controllers.UserController { // ... }
Write a constructor method without parameter and initialize the base class (SOWIWeb.Administrator.Controllers.UserController)
Tip: using the code snippet SOWI Class Constructor (shortcut scsClassConstr) and append code for initialize the base class
/// <summary> /// Initializes a new instance of the TicketUserController class. /// Constructor without parameter /// </summary> public TicketUserController() : base() { }
Override the method IndexGetToolbarItem and write code for adds a button in the toolbar
See also: UserControllerIndexGetToolbarItem and SOWIWeb.HelperToolbarButton
/// <summary> /// Adds a toolbar button for Ticket options /// </summary> /// <returns>Toolbar list for Index view</returns> /// <seealso cref="SOWIWeb.Helper.ToolbarButton"/> /// <seealso cref="SOWIWeb.Administrator.Controllers.UserController.IndexGetToolbarItem"/> protected override List<ToolbarButton> IndexGetToolbarItem() { List<ToolbarButton> lToolbarItem = base.IndexGetToolbarItem(); lToolbarItem.Add(new SOWIWeb.Helper.ToolbarButton(SOWIWeb.Helper.ButtonType.Action, pMVCController: "TicketUserOption", pMVCAction: "IndexByUser", pLabel: "Ticket Option")); return lToolbarItem; }
Complete code example
1using System.Collections.Generic; 2using SOWIWeb.Helper; 3 4namespace SOWIWeb.ProTic.Controllers 5{ 6 /// <summary> 7 /// Ticket user web controller based on SOWI Web Administrator User Controller 8 /// </summary> 9 /// <seealso cref="SOWIWeb.Administrator.Controllers.UserController"/> 10 public class TicketUserController : SOWIWeb.Administrator.Controllers.UserController 11 { 12 /// <summary> 13 /// Initializes a new instance of the TicketUserController class. 14 /// Constructor without parameter 15 /// </summary> 16 public TicketUserController() : base() { } 17 18 /// <summary> 19 /// Adds a toolbar button for Ticket options 20 /// </summary> 21 /// <returns>Toolbar list for Index view</returns> 22 /// <seealso cref="SOWIWeb.Helper.ToolbarButton"/> 23 /// <seealso cref="SOWIWeb.Administrator.Controllers.UserController.IndexGetToolbarItem"/> 24 protected override List<ToolbarButton> IndexGetToolbarItem() 25 { 26 List<ToolbarButton> lToolbarItem = base.IndexGetToolbarItem(); 27 lToolbarItem.Add(new SOWIWeb.Helper.ToolbarButton(SOWIWeb.Helper.ButtonType.Action, 28 pMVCController: "TicketUserOption", 29 pMVCAction: "IndexByUser", 30 pLabel: "Ticket Option")); 31 return lToolbarItem; 32 } 33 } 34}
Go to source code file Global.asax.cs
Add into method Application_Start the map routes
Note: the order of map route is important
See also: SOWIWeb.Foundation.AppRouteConfig and RegisterRoutes
//* route redirection User/Index to TicketUser/Index * RouteTable.Routes.MapRoute( name: "UserIndex", url: "User/Index/{id}/{parameter}", defaults: new { controller = "TicketUser", action = "Index", id = "", parameter = "" }); //* route redirection TicketUser/Details to User/Details * RouteTable.Routes.MapRoute( name: "UserDetails", url: "TicketUser/Details/{id}/{parameter}", defaults: new { controller = "User", action = "Details", id = "", parameter = "" }); //* standard routes * SOWIWeb.Foundation.App.RouteConfig.RegisterRoutes(RouteTable.Routes);
Complete code example
1/// <summary> 2/// SOWI Web application start event. 3/// Sets global routes and redirection of TicketUser. 4/// </summary> 5/// <seealso cref="SOWIWeb.Foundation.App.RouteConfig"/> 6/// <seealso cref="SOWIWeb.Foundation.App.RouteConfig.RegisterRoutes(RouteCollection, string, string, string, string)"/> 7protected void Application_Start() 8{ 9 //* note: order of map route is important * 10 11 //* route redirection User/Index to TicketUser/Index * 12 RouteTable.Routes.MapRoute( 13 name: "UserIndex", 14 url: "User/Index/{id}/{parameter}", 15 defaults: new { controller = "TicketUser", action = "Index", id = "", parameter = "" }); 16 17 //* route redirection TicketUser/Details to User/Details * 18 RouteTable.Routes.MapRoute( 19 name: "UserDetails", 20 url: "TicketUser/Details/{id}/{parameter}", 21 defaults: new { controller = "User", action = "Details", id = "", parameter = "" }); 22 23 //* standard routes * 24 SOWIWeb.Foundation.App.RouteConfig.RegisterRoutes(RouteTable.Routes); 25 26 // ... 27 28}