This commit is contained in:
2021-10-19 06:29:11 +08:00
commit 60131e4608
131 changed files with 46479 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
@page
@model _2021_backend.Pages.Users.CreateModel
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="NowUser.stuID" class="control-label"></label>
<input asp-for="NowUser.stuID" class="form-control" />
<span asp-validation-for="NowUser.stuID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NowUser.Name" class="control-label"></label>
<input asp-for="NowUser.Name" class="form-control" />
<span asp-validation-for="NowUser.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NowUser.Secret" class="control-label"></label>
<input asp-for="NowUser.Secret" class="form-control" />
<span asp-validation-for="NowUser.Secret" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="NowUser.isManager" /> @Html.DisplayNameFor(model => model.NowUser.isManager)
</label>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
+58
View File
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using _2021_backend.Data;
using _2021_backend.Models;
using Microsoft.EntityFrameworkCore;
namespace _2021_backend.Pages.Users
{
public class CreateModel : PageModel
{
private readonly _2021_backend.Data.BackendContext _context;
public IList<Submission> Record { get; set; }
public int PageCount { get; set; }
public int PageId { get; set; }
[BindProperty(SupportsGet =true,Name ="search")]
public string SearchString { get; set; }
public CreateModel(_2021_backend.Data.BackendContext context)
{
_context = context;
}
public IActionResult OnGet()
{
return Page();
}
[BindProperty]
public User NowUser { get; set; }
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
if (await _context.Users.AsNoTracking().Where(u => u.stuID == NowUser.stuID).FirstOrDefaultAsync() != null)
{
}
else
{
NowUser.Secret = Utils.EvaCryptoHelper.Password2Secret(NowUser.Secret);
_context.Users.Add(NowUser);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
}
}
+41
View File
@@ -0,0 +1,41 @@
@page
@model _2021_backend.Pages.Users.DeleteModel
@{
ViewData["Title"] = "Delete";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>User</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.stuID)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.stuID)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.Name)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.Name)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.isManager)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.isManager)
</dd>
</dl>
<form method="post">
<input type="hidden" asp-for="User.Guid" />
<input type="submit" value="Delete" class="btn btn-danger" /> |
<a asp-page="./Index">Back to List</a>
</form>
</div>
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using _2021_backend.Data;
using _2021_backend.Models;
namespace _2021_backend.Pages.Users
{
public class DeleteModel : PageModel
{
private readonly _2021_backend.Data.BackendContext _context;
public DeleteModel(_2021_backend.Data.BackendContext context)
{
_context = context;
}
[BindProperty]
public new User User { get; set; }
public async Task<IActionResult> OnGetAsync(string id)
{
Guid guid = Guid.Parse(id);
if (id == null)
{
return NotFound();
}
User = _context.Users.Find(guid);
if (User == null)
{
return NotFound();
}
return Page();
}
public async Task<IActionResult> OnPostAsync(string id)
{
Guid guid = Guid.Parse(id);
if (id == null)
{
return NotFound();
}
User = _context.Users.Find(id);
if (User != null)
{
_context.Users.Remove(User);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
}
}
+43
View File
@@ -0,0 +1,43 @@
@page
@model _2021_backend.Pages.Users.DetailsModel
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>User</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.stuID)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.stuID)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.Name)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.Name)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.Secret)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model=>model.SECRET)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.User.isManager)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.User.isManager)
</dd>
</dl>
</div>
<div>
<a asp-page="./Edit" asp-route-id="@Model.User.Guid">Edit</a> |
<a asp-page="./Index">Back to List</a>
</div>
+41
View File
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using _2021_backend.Data;
using _2021_backend.Models;
namespace _2021_backend.Pages.Users
{
public class DetailsModel : PageModel
{
private readonly _2021_backend.Data.BackendContext _context;
public DetailsModel(_2021_backend.Data.BackendContext context)
{
_context = context;
}
public string SECRET = "EVa N13 @!@";
public new User User { get; set; }
public async Task<IActionResult> OnGetAsync(string id)
{
Guid guid = Guid.Parse(id);
if (id == null)
{
return NotFound();
}
User = _context.Users.Find(guid);
if (User == null)
{
return NotFound();
}
return Page();
}
}
}
+50
View File
@@ -0,0 +1,50 @@
@page
@model _2021_backend.Pages.Users.EditModel
@{
ViewData["Title"] = "Edit";
}
<h1>Edit</h1>
<h4>User</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="USER.Guid" />
<div class="form-group">
<label asp-for="USER.stuID" class="control-label"></label>
<input asp-for="USER.stuID" class="form-control" />
<span asp-validation-for="USER.stuID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="USER.Name" class="control-label"></label>
<input asp-for="USER.Name" class="form-control" />
<span asp-validation-for="USER.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="USER.Secret" class="control-label"></label>
<input asp-for="USER.Secret" class="form-control" />
<span asp-validation-for="USER.Secret" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="USER.isManager" /> @Html.DisplayNameFor(model => model.USER.isManager)
</label>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-page="./Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
+101
View File
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using _2021_backend.Data;
using _2021_backend.Models;
namespace _2021_backend.Pages.Users
{
public class EditModel : PageModel
{
private readonly _2021_backend.Data.BackendContext _context;
public EditModel(_2021_backend.Data.BackendContext context)
{
_context = context;
}
[BindProperty]
public new User USER { get; set; }
private string _secret { get; set; }
public async Task<IActionResult> OnGetAsync(string? id)
{
if (id == null)
{
return NotFound();
}
Guid guid = Guid.Parse(id);
USER = _context.Users.Find(guid);
if (USER == null)
{
return NotFound();
}
_secret = USER.Secret;
USER.Secret = string.Empty;
return Page();
}
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
if (await _context.Users.AsNoTracking().Where(u => u.stuID == USER.stuID).CountAsync() > 0
&& (await _context.Users.AsNoTracking().Where(u => u.stuID == USER.stuID).FirstOrDefaultAsync()).Guid != USER.Guid
)
return new ConflictResult();
if (USER.Secret == null || USER.Secret == String.Empty)
{
var user = await _context.Users.AsNoTracking().Where(u => u.Guid == USER.Guid).FirstOrDefaultAsync();
user.Name = USER.Name;
user.stuID = USER.stuID;
user.isManager = USER.isManager;
_context.Attach(user).State = EntityState.Modified;
}
else
{
var user = await _context.Users.AsNoTracking().Where(u => u.Guid == USER.Guid).FirstOrDefaultAsync();
user.Name = USER.Name;
user.stuID = USER.stuID;
user.isManager = USER.isManager;
user.Secret = Utils.EvaCryptoHelper.Password2Secret(USER.Secret);
_context.Attach(user).State = EntityState.Modified;
}
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!UserExists(USER.Guid))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToPage("./Index");
}
private bool UserExists(Guid id)
{
return _context.Users.Any(e => e.Guid == id);
}
}
}
+50
View File
@@ -0,0 +1,50 @@
@page
@model _2021_backend.Pages.Users.IndexModel
@{
ViewData["Title"] = "Index";
}
<h4>用户管理</h4>
<p>
<a asp-page="Create">新加一个好兄弟</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.User[0].stuID)
</th>
<th>
@Html.DisplayNameFor(model => model.User[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.User[0].isManager)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.User) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.stuID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.isManager)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.Guid">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.Guid">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.Guid">Delete</a>
</td>
</tr>
}
</tbody>
</table>
+29
View File
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using _2021_backend.Data;
using _2021_backend.Models;
namespace _2021_backend.Pages.Users
{
public class IndexModel : PageModel
{
private readonly _2021_backend.Data.BackendContext _context;
public IndexModel(_2021_backend.Data.BackendContext context)
{
_context = context;
}
public string SECRET = "EVa N13 @!@";
public new IList<User> User { get;set; }
public async Task OnGetAsync()
{
User = await _context.Users.ToListAsync();
}
}
}