ASP.NET MVC+EF +EasyUI framework implementation of Privilege Management Series (

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

  ASP.NET MVC+EF +EasyUI framework implementation authority series

  (opening)

(1):The frame building

 (2):Design of Demo database access layer

(3):The interface oriented programming

(4 ):The business logic layer of the package 

    (5):The Jquery easyUI implementation 

(6):EF context instance management 

(7):DBSession package

(8):The DBSession thread only  

    (9):TT touch version of learning

(10):VSS source code management       (11): verification code implementation and the underlying modify     (12): user asynchronous log and T4 template

     (13):Design of authority   (14): the main framework of       (15): login access database model and detailed user error

  Objective: the first blog we wrote a simple login code detailed errors, you is it right? I feel very simple, in fact, I feel too, but it is also the needs of others out, so I just wrote, now so I feel we are written in a very slow, but I do write enough detailed, also is the basic step by step out of wonderful teaching how to write, so I always say this series from the beginning to look, and then watched over, so we will reap a lot of things, but now I think I write carefully or

1. Library architecture extended

  (1)If you look at this series I, see here, you can see my solution or each class are shown in the following, as shown in Fig.:

  

  (2)Then as shown above., We are not feeling very much., Of course I believe most feel not to, Because of this project I am not a big project, It relates to the library is just 6, But you can imagine, If your library is more than 100, More than 200 or even more? So we kept it is it right? I feel very confused., So VS provides a virtual folder for us (folder itself does not exist, Display only under the VS folder, If you open the project location, Did not find these folders), So we click to add a new solution folder in solution above right, In this way we can achieve what I said above function, Then the modified architecture as shown in Fig.:

    

  (3)Implement virtual folder, is stored in the realization of business logic layer and data access layer

  (4)The InterFace virtual folder is stored in the realization of interface, business logic layer and data access layer.

  (5)Model virtual folder, is stored in the public class and Entity Framework.

2 in a fixed folder DLL file generation

  (1)First, why are we in a fixed folder DLL file generated? To our previous project writing that is not fine, of course, it still has such benefits, please listen to me say slowly.

  (2)If it is a small project. We follow the above it can be, but if we project is many, there are dozens of hundreds of? Then we above the kind of serious is not good, because the one or two projects which generation is not the past, then your solution will be generated is not the past, so we now hope that the one or two item generation is not the past, but our solution can still generate the past, this kind of words we have the following solutions.

  (3)For example: BLL layer project our dependence on DAL layer, it even if the DAL layer formation is not in the past, we also asked BLL layer can generate the past, but if we add project reference it is no good, because if we add project reference if he will go to the generation of DAL layer and BLL layer of production words, but the DAL layer will be in error, so the solution build will fail.

  (4)So how to solve? At first, we create a new folder in solution below Lib, is designed to store all of the DLL files. At that time we to attribute all the library to modify some of the content, select the build properties, right-click the class library, and then modify the output path (DLL output files to the folder specified below) to the folder we built, and then save it, then to folder check can be, as shown in Fig. as shown in:

     

  (5)Finally, we will all the library are in accordance with the above said format changes, then we can go to have a look the folder we build things, as shown in Fig.:

     

  (6)So this time we project if you want to add the quotation we can directly go to the folder to add references, and not to each project add reference, in this way we can solve the present things, from now on the foundation of the project we basically has been done, we can start to realize the information written in front of all the finally, we will we achieve content was checked in to source control.

3 users to add to achieve the overall introduction

  (1)According to the above, here we began to realize the user, or a word, user features I would write a little more, there are roles and permissions you understand, do not say, so we still see directly above:

  (2)Here we are using the easyUI user to add controls to create the following development, if we add users said we should be divided into several steps to implement? Here we talk about: the first is the interface to build, we have seen the easyUI set up the interface, the second is Jquery asynchronous request code, finally we project the main code, that's how to realize the function, we have the following according to these three points, to achieve the user to add this functionality.

4 add users steps

  (1)Set interface using easyUI, we have in front of said reference easyUI things, the HTML code is as follows:

  1 <!Popup ---------------------------- add user information --------------------------.>
  2 
  3     <div id="DivAddUser" class="easyui-dialog" style="width:580px;height:400px;padding:10px 20px"
  4 
  5             closed="true" resizable="true" modal="true" buttons="#dlg-buttons">
  6 
  7         <form id="ff" method="post" novalidate="novalidate">
  8 
  9             <fieldset>
 10 
 11                 <legend>The user information required</legend>
 12 
 13                 <table id="tblAdd">
 14 
 15                     <tr>
 16 
 17                         <td><label for="UserName">Login name: </label></td>
 18 
 19                         <td>
 20 
 21                             <input class="easyui-validatebox" type="text" id="UserName" name="UserName" data-options="required:true,validType:'length[1,32]'" />
 22 
 23                         </td>          
 24 
 25                         <td><label for="RealName">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Real name: </label></td>
 26 
 27                         <td>
 28 
 29                             <input class="easyui-validatebox" type="text" id="RealName" name="RealName"  data-options="required:true,validType:'length[1,200]'" />
 30 
 31                         </td>
 32 
 33                     </tr>
 34 
 35                     <tr>
 36 
 37                         <td><label for="UserPassword">Cipher: </label></td>
 38 
 39                         <td>
 40 
 41                             <input class="easyui-validatebox" type="text" id="UserPassword" name="UserPassword" data-options="required:true,validType:'length[1,200]'" />
 42 
 43                         </td>
 44 
 45                         <td><label for="OKUserPassword">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Confirm password: </label></td>
 46 
 47                         <td>
 48 
 49                             <input class="easyui-validatebox" type="text" id="OKUserPassword" name="OKUserPassword" data-options="required:true" validType="equalTo['UserPassword']" invalidMessage="The two passwords do not match" />
 50 
 51                         </td>
 52 
 53                     </tr>
 54 
 55                 </table>
 56 
 57             </fieldset>
 58 
 59             <br />
 60 
 61             <fieldset>
 62 
 63                 <legend>Customer optional information</legend>
 64 
 65                 <table id="tblAdd1">
 66 
 67                     <tr>
 68 
 69                         <td><label for="Email">EMail: </label></td>
 70 
 71                         <td>
 72 
 73                             <input class="easyui-validatebox" type="text" id="Email" name="Email"  data-options="validType:'email'"/>
 74 
 75                         </td>
 76 
 77                         <td><label for="SecurityLevel">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Security level: </label></td>
 78 
 79                         <td>
 80 
 81                             <select id="SecurityLevel" class="easyui-combobox" style="width:154px;" name="SecurityLevel" data-options="required:true">
 82 
 83                                 <option value="1">1</option>
 84 
 85                                 <option value="2">2</option>
 86 
 87                                 <option value="3">3</option>
 88 
 89                                 <option value="4">4</option>
 90 
 91                                 <option value="5">5</option>
 92 
 93                                 <option value="6">6</option>
 94 
 95                                 <option value="7">7</option>
 96 
 97                                 <option value="8">8</option>
 98 
 99                                 <option value="9">9</option>
100 
101                                 <option value="10">10</option>
102 
103                             </select>
104 
105                         </td>
106 
107                     </tr>
108 
109                     <tr>
110 
111                         <td><label for="Gender">Gender: </label></td>
112 
113                         <td>
114 
115                             <input  class="easyui-validatebox" type="radio" name="Gender" id="Boy" value="Male" checked="checked" />Male&nbsp;&nbsp;
116 
117                             <input  class="easyui-validatebox" type="radio" name="Gender" id="Girl" value="Female" />Female&nbsp;&nbsp;
118 
119                             <input  class="easyui-validatebox" type="radio" name="Gender" id="No" value="Unknown" />Unknown
120 
121                         </td>
122 
123                          <td><label for="Birthday">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date of birth: </label></td>
124 
125                         <td>
126 
127                             <input id="Birthday" style="width:154px;" class="easyui-datebox" required="required" name="Birthday" />
128 
129                         </td>
130 
131                     </tr>
132 
133                     <tr>
134 
135                         <td><label for="Mobile">Phone number: </label></td>
136 
137                         <td>
138 
139                             <input class="easyui-numberbox" type="text" id="Mobile" name="Mobile"/>
140 
141                         </td>
142 
143                         <td><label for="Telephone">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Telephone number: </label></td>
144 
145                         <td>
146 
147                             <input class="easyui-numberbox" type="text" id="Telephone" name="Telephone"/>
148 
149                         </td>
150 
151                     </tr>
152 
153                     <tr>
154 
155                         <td><label for="QICQ">QQ number: </label></td>
156 
157                         <td>
158 
159                             <input class="easyui-numberbox" type="text" id="QICQ" name="QICQ" />
160 
161                         </td>
162 
163                           <td><label for="SortCode">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ordering code: </label></td>
164 
165                         <td>
166 
167                             <input class="easyui-validatebox" type="text" id="SortCode" name="SortCode" />
168 
169                         </td>
170 
171                     </tr>
172 
173                     <tr>
174 
175                         <td><label for="Description">Note information: </label></td>
176 
177                         <td colspan="3">
178 
179                             <textarea  style="height:50px; width:406px;" id="Description" name="Description" ></textarea>
180 
181                         </td>
182 
183                     </tr>
184 
185                     <tr>
186 
187                         <td colspan="4" style="text-align:center; padding-top:10px">
188 
189                             <a href="javascript:void(0)" class="easyui-linkbutton" id="btnRegist" iconcls="icon-ok" >Determine</a>
190 
191                             <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#AddUserDialog').dialog('close')">Close</a>
192 
193                         </td>
194 
195                     </tr>
196 
197                 </table>
198 
199             </fieldset>
200 
201         </form>
202 
203     </div>

  (2)Jquery sends an asynchronous request to use, the code as follows:

 1 //Bound register button events
 2 
 3         function bindRegisteButtonClickEvent() {
 4 
 5             $("#btnRegist").click(function () {
 6 
 7                 //To determine whether the user information through verification
 8 
 9                 var validate = $("#ff").form('validate');
10 
11                 if (validate == false) {
12 
13                     return false;
14 
15                 }
16 
17                 //Gets the parameter passed to the front desk
18 
19                 var postData = {
20 
21                     UserName: $("#UserName").val(),
22 
23                     RealName: $("#RealName").val(),
24 
25                     UserPassword: $("#UserPassword").val(),
26 
27                     Email: $("#Email").val(),
28 
29                     SecurityLevel: $("#SecurityLevel").combobox('getValue'),
30 
31                     Gender: $('input[name="Gender"]:checked').val(),
32 
33                     Birthday: $("#Birthday").datebox('getValue'),
34 
35                     Mobile: $("#Mobile").val(),
36 
37                     Telephone: $("#Telephone").val(),
38 
39                     QICQ: $("#QICQ").val(),
40 
41                     SortCode: $("#SortCode").val(),
42 
43                     Description: $("#Description").val()
44 
45                 };
46 
47                 //The asynchronous request to the background save user data
48 
49                 $.post("/UserInfo/RegisterUser", postData, function (data) {
50 
51                     if (data = "OK") {
52 
53                         //Successfully added 1 to close the pop-up layer, 2 refresh DataGird
54 
55                         alert("Added successfully");
56 
57                         $("#DivAddUser").dialog("close");
58 
59                         $("#test").datagrid("reload");
60 
61                     }
62 
63                     else {
64 
65                         alert("Failed to add, please check");
66 
67                     }
68 
69                 });
70 
71             });
72 
73         }

  (3)Add the user controller, controller of the code are as follows:

 1 public ActionResult RegisterUser(BaseUser userInfo)
 2 
 3         {
 4 
 5             //Save some need to input the database information first
 6 
 7             userInfo.Code = Guid.NewGuid().ToString();  //Some data randomly generated
 8 
 9             userInfo.QuickQuery = userInfo.UserName;   //To obtain the data query code
10 
11             userInfo.UserFrom = "Add to";               //User source
12 
13             userInfo.Lang = "Chinese";                   //The default system identification is Chinese
14 
15             userInfo.IsStaff = (Int32?)StaffEnum.OK;         //The default is the clerk
16 
17             userInfo.IsVisible = (Int32?)VisibleEnum.OK;     //The default display information
18 
19             userInfo.Enabled =(Int32?)EnabledEnum.OK;       //The default user effectively
20 
21             userInfo.AuditStatus ="Has the audit";         //The default add user has been reviewed
22 
23             userInfo.DeletionStateCode = (Int32?)DeletionStateCodeEnum.Normal;    //The default is no pseudo delete
24 
25             userInfo.CreateOn = DateTime.Parse(DateTime.Now.ToString());     //The default user created date
26 
27             BaseUser user = Session["UserInfo"] as BaseUser;
28 
29             userInfo.CreateUserID = user.Code;   //Access to add this user management ID
30 
31             userInfo.CreateBy = user.UserName;//Gets the name of the user manager to add
32 
33             //Add user code execution
34 
35             _userInfoService.AddEntity(userInfo);
36 
37             return Content("OK");
38 
39        }

5 Summary

  (1)Here we add the function of user is realized, but there are still a lot of issues we need to pay attention to, some simple Bug or verification tomorrow I is you say, this blog space has been very long, not long, I hope you understand, if you have any questions can leave a message, thank you your watch.

  (2)Finally a for everyone to have a look to add the success of the drawings, as shown in Fig.:

     

  (3)Well, we all go to bed earlier, good body is half of success!

.NET developer blog: www.kencery.com


  Kencery returns the series begins


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Addison at November 16, 2013 - 2:51 AM