Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar65
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нурбек Созоев
webinar65
Commits
5d3a488e
Commit
5d3a488e
authored
Jun 27, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил контроллер для работы с ролями
parent
f0f5322d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
0 deletions
+136
-0
RoleController.cs
webinar65/Controllers/RoleController.cs
+45
-0
Startup.cs
webinar65/Startup.cs
+1
-0
RoleCreateViewModel.cs
webinar65/ViewModels/RoleCreateViewModel.cs
+10
-0
UserCreateViewModel.cs
webinar65/ViewModels/UserCreateViewModel.cs
+21
-0
Create.cshtml
webinar65/Views/Role/Create.cshtml
+20
-0
Index.cshtml
webinar65/Views/Role/Index.cshtml
+38
-0
_Layout.cshtml
webinar65/Views/Shared/_Layout.cshtml
+1
-0
No files found.
webinar65/Controllers/RoleController.cs
0 → 100644
View file @
5d3a488e
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
webinar65.Models
;
using
webinar65.ViewModels
;
namespace
webinar65.Controllers
{
public
class
RoleController
:
Controller
{
private
RoleManager
<
IdentityRole
>
_roleManager
;
public
RoleController
(
RoleManager
<
IdentityRole
>
roleManager
)
{
_roleManager
=
roleManager
;
}
public
IActionResult
Index
()
{
return
View
(
_roleManager
.
Roles
);
}
[
HttpGet
]
public
IActionResult
Create
()
=>
View
();
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
(
RoleCreateViewModel
model
)
{
if
(
ModelState
.
IsValid
)
{
var
result
=
await
_roleManager
.
CreateAsync
(
new
IdentityRole
(
model
.
RoleName
));
if
(
result
.
Succeeded
)
return
RedirectToAction
(
"Index"
);
foreach
(
var
error
in
result
.
Errors
)
{
ModelState
.
AddModelError
(
""
,
error
.
Description
);
}
}
return
View
(
model
);
}
}
}
webinar65/Startup.cs
View file @
5d3a488e
...
...
@@ -61,6 +61,7 @@ namespace webinar65
app
.
UseHttpsRedirection
();
app
.
UseStaticFiles
();
app
.
UseCookiePolicy
();
app
.
UseAuthentication
();
app
.
UseMvc
(
routes
=>
{
...
...
webinar65/ViewModels/RoleCreateViewModel.cs
0 → 100644
View file @
5d3a488e
using
System.ComponentModel.DataAnnotations
;
namespace
webinar65.ViewModels
{
public
class
RoleCreateViewModel
{
[
Required
]
public
string
RoleName
{
get
;
set
;
}
}
}
webinar65/ViewModels/UserCreateViewModel.cs
0 → 100644
View file @
5d3a488e
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
Microsoft.AspNetCore.Identity
;
using
webinar65.Models
;
namespace
webinar65.ViewModels
{
public
class
UserCreateViewModel
{
[
Required
]
public
string
Username
{
get
;
set
;
}
[
Required
]
public
string
Email
{
get
;
set
;
}
[
Required
]
public
string
Password
{
get
;
set
;
}
public
List
<
IdentityRole
>
Roles
{
get
;
set
;
}
}
}
webinar65/Views/Role/Create.cshtml
0 → 100644
View file @
5d3a488e
@model webinar65.ViewModels.RoleCreateViewModel
@{
ViewBag.Title = "Create Role";
Layout = "_Layout";
}
<h2>Create Role</h2>
<div asp-validation-summary="All" class="text-danger"></div>
<form asp-action="Create" method="post">
<div class="form-group">
<label asp-for="RoleName">Role Name</label>
<input asp-for="RoleName" class="form-control"/>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a asp-action="Index" class="btn btn-secondary">Cancel</a>
</form>
webinar65/Views/Role/Index.cshtml
0 → 100644
View file @
5d3a488e
@using Microsoft.AspNetCore.Identity
@model IEnumerable<Microsoft.AspNetCore.Identity.IdentityRole>
@{
ViewBag.Title = "Roles";
Layout = "_Layout";
}
<h2>Roles</h2>
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Role name</th>
</tr>
</thead>
<tbody>
@if (!Model.Any())
{
<tr>
<td colspan="3" class="text-center">No Roles</td>
</tr>
}
else
{
foreach (IdentityRole role in Model)
{
<tr>
<td>@role.Id</td>
<td>@role.Name</td>
</tr>
}
}
</tbody>
</table>
<a asp-action="Create" class="btn btn-primary">Create</a>
webinar65/Views/Shared/_Layout.cshtml
View file @
5d3a488e
...
...
@@ -30,6 +30,7 @@
</div>
<div
class=
"navbar-collapse collapse"
>
<ul
class=
"nav navbar-nav"
>
<li><a
asp-area=
""
asp-controller=
"Role"
asp-action=
"Index"
>
Roles
</a></li>
<li><a
asp-area=
""
asp-controller=
"Home"
asp-action=
"Index"
>
Home
</a></li>
<li><a
asp-area=
""
asp-controller=
"Home"
asp-action=
"About"
>
About
</a></li>
<li><a
asp-area=
""
asp-controller=
"Home"
asp-action=
"Contact"
>
Contact
</a></li>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment