Click or drag to resize

Web Controller

SOWI Web Controller Template creates a web controller of model MVC with

  • SOWI App as business logical

  • SOWI Data as data model

This topic contains the following sections:

Requirement

The web project based on SOWI Web Project

The SOWI App which presents the business logic must be available.

The SOWI Data which presents the data model must be available.

The SOWI Template package must be installed

Check following references (normally already specified):
SOWIData, SOWIData.Helper, SOWIWeb.Helper, SOWIWeb.Foundation and SOWIApp.Foundation

Check exist the SOWI Configuration (file: SOWIApp.sconfig) into folder App_Data

Template

Create a SOWI Web Controller with the template

  1. Choose or create a new SOWI Web project into Solution Explorer

  2. Expand his items and select the Controllers folder

  3. Add SOWI Web Controller via template

    Call context menu and choose menu item Add, New Item...

    ScreenSOWIWeb Controller Template Content Menu
  4. The dialog Add New Item appears

    Choose Installed, Visual C# and SOWIWebController.Template

    Edit the web controller name into textbox Name e.g. TestUser (without suffix Controller)

    Push button Add

    ScreenSOWIWeb Controller Template Add New Item
  5. The dialog SOWI Web Controller appears

    Choose the App Class into the class list

    Choose the Data Item Class into the class list

    Push button OK

    ScreenSOWIWeb Controller Template Dialog

Now the following item is created:

The elements contain all standard functions and are therefore executable.

Code Example
Note Note

The code may vary depending on your choice options and version.

Controller
C#
 1using SOWIData.Helper;
 2using System;
 3
 4namespace SOWIWeb.Foundation.TestWeb.Controllers
 5{
 6    /// <summary>
 7    /// Web controller
 8    /// </summary>
 9    public class TestUserController : SOWIWeb.Helper.ControllerStandard<SOWIData.Management.User>
10    {
11        #region --- AppModule ---
12
13        /// <summary>
14        /// Temporary App object for better performance
15        /// </summary>
16        private SOWIApp.Administrator.User _AppUser;
17
18        /// <summary>
19        /// Give a App object with full function (SOWIApp.Administrator.User)
20        /// </summary>
21        private SOWIApp.Administrator.User AppUser
22        {
23            get
24            {
25                if (SOWIWeb.Helper.Session.IsAuthenticated)
26                {
27                    if (_AppUser == null)
28                    {
29                        _AppUser = new SOWIApp.Administrator.User(SOWIWeb.Helper.Session.Token.ToGUID());
30                    }
31                    return _AppUser;
32                }
33                return null;
34            }
35        }
36
37        /// <summary>
38        /// Give a App object with standard function (see <see cref="SOWIApp.Foundation.IAppController{DataItemClass}"/>)
39        /// </summary>
40        protected override SOWIApp.Foundation.IAppController<SOWIData.Management.User> AppModule
41        { get { return (SOWIApp.Foundation.IAppController<SOWIData.Management.User>)this.AppUser; } }
42
43        #endregion
44
45        /// <summary>
46        /// Gives a new data item of type <see cref="SOWIData.Management.User"/>
47        /// </summary>
48        protected override SOWIData.Management.User GetNewDataItem { get { return new SOWIData.Management.User(); } }
49
50    }
51}
View Create
CSHTML
1@*
2    View: /TestUser/Create/
3*@
4
5@model SOWIData.Management.User
6
7@Html.Partial("~/Views/Form/Form.cshtml")
View Delete
CSHTML
1@*
2    View: /TestUser/Delete/
3*@
4
5@model SOWIData.Management.User
6
7@Html.Partial("~/Views/Form/Form.cshtml")
View Details
CSHTML
1@*
2    View: /TestUser/Details/
3*@
4
5@model SOWIData.Management.User
6
7@Html.Partial("~/Views/Form/Form.cshtml")
View Edit
CSHTML
1@*
2    View: /TestUser/Edit/
3*@
4
5@model SOWIData.Management.User
6
7@Html.Partial("~/Views/Form/Form.cshtml")
View Index
CSHTML
1@*
2    View: /TestUser/Index/
3*@
4
5@*@model IEnumerable<SOWIData.Management.User>*@
6@model IEnumerable<object>
7
8@Html.Partial("~/Views/Form/Form.cshtml")
See Also