initial
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
@page
|
||||
@model _2021_backend.Pages.Sessions.CreateModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
|
||||
<h1>Create</h1>
|
||||
|
||||
<h4>InterviewTime</h4>
|
||||
<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="InterviewTime.Day" class="control-label"></label>
|
||||
<input asp-for="InterviewTime.Day" class="form-control" />
|
||||
<span asp-validation-for="InterviewTime.Day" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="InterviewTime.BeginTime" class="control-label"></label>
|
||||
<input asp-for="InterviewTime.BeginTime" class="form-control" />
|
||||
<span asp-validation-for="InterviewTime.BeginTime" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="InterviewTime.Place" class="control-label"></label>
|
||||
<select asp-for="InterviewTime.Place" class="form-control">
|
||||
<option value="200">200</option>
|
||||
<option value="204">204</option>
|
||||
</select>
|
||||
<span asp-validation-for="InterviewTime.Place" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="InterviewTime.Capacity" class="control-label"></label>
|
||||
<input asp-for="InterviewTime.Capacity" class="form-control" />
|
||||
<span asp-validation-for="InterviewTime.Capacity" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
<label class="form-check-label">
|
||||
<input class="form-check-input" asp-for="InterviewTime.SendSMS" /> @Html.DisplayNameFor(model => model.InterviewTime.SendSMS)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
<label class="form-check-label">
|
||||
<input class="form-check-input" asp-for="CreateTwo" /> @Html.DisplayNameFor(model => model.CreateTwo)
|
||||
</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");}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using _2021_backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _2021_backend.Pages.Sessions
|
||||
{
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private readonly _2021_backend.Data.BackendContext Context;
|
||||
|
||||
[Display(Name = "同时创建200和204场次")]
|
||||
[BindProperty]
|
||||
public bool CreateTwo { get; set; }
|
||||
[BindProperty]
|
||||
public Session InterviewTime { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
[Display(Name = "活动官")]
|
||||
public string ChiefGuid { get; set; }
|
||||
|
||||
|
||||
public List<SelectListItem> ChiefList { get; set; }
|
||||
|
||||
public CreateModel(_2021_backend.Data.BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGet()
|
||||
{
|
||||
var qlst = from e in Context.Users select (new SelectListItem { Value = e.Guid.ToString(), Text = e.Name, Selected = false, Disabled = false });
|
||||
var lst = qlst.ToList().Distinct().ToList();
|
||||
ChiefList = lst;
|
||||
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();
|
||||
}
|
||||
InterviewTime.Students = new List<Guid>();
|
||||
InterviewTime.Chiefs = new List<Guid>();
|
||||
Session interviewTimeSecond = new Session();
|
||||
if (CreateTwo)
|
||||
{
|
||||
string anotherPlace = InterviewTime.Place == "200" ? "204" : "200";
|
||||
Session tmp = Context.Sessions.FirstOrDefault(r => r.Place == anotherPlace && r.Day == InterviewTime.Day && InterviewTime.BeginTime == r.BeginTime);
|
||||
if (tmp == null)
|
||||
{
|
||||
interviewTimeSecond = new Session()
|
||||
{
|
||||
Day = InterviewTime.Day,
|
||||
BeginTime = InterviewTime.BeginTime,
|
||||
Place = anotherPlace,
|
||||
Chiefs = new List<Guid>(),
|
||||
SendSMS = InterviewTime.SendSMS,
|
||||
Students = new List<Guid>(),
|
||||
Capacity = InterviewTime.Capacity
|
||||
};
|
||||
Context.Add(interviewTimeSecond);
|
||||
Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
Context.Sessions.Add(InterviewTime);
|
||||
Context.SaveChanges();
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
@page
|
||||
@model _2021_backend.Pages.Sessions.DeleteModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
}
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<h3>你确定要把这场删掉吗?</h3>
|
||||
<div>
|
||||
<h4>删除场次</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.InterviewTime.Day)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.InterviewTime.Day)
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.InterviewTime.BeginTime)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.InterviewTime.BeginTime)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.InterviewTime.Capacity)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.InterviewTime.Capacity)
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" asp-for="InterviewTime.Guid" />
|
||||
<input type="submit" value="确定删除" class="btn btn-danger" /> |
|
||||
<a asp-page="./Index">Back to List</a>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,77 @@
|
||||
using _2021_backend.Data;
|
||||
using _2021_backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _2021_backend.Pages.Sessions
|
||||
{
|
||||
public class DeleteModel : PageModel
|
||||
{
|
||||
private readonly _2021_backend.Data.BackendContext Context;
|
||||
|
||||
public DeleteModel(_2021_backend.Data.BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Session InterviewTime { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string? id)
|
||||
{
|
||||
Guid guid = Guid.Parse(id);
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
InterviewTime = Context.Sessions.Find(guid);
|
||||
|
||||
if (InterviewTime == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string? id)
|
||||
{
|
||||
Guid guid = Guid.Parse(id);
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
InterviewTime = await Context.Sessions.FindAsync(guid);
|
||||
|
||||
if (InterviewTime != null)
|
||||
{
|
||||
if (InterviewTime.Students.Count > 0)
|
||||
{
|
||||
foreach (var x in InterviewTime.Students)
|
||||
{
|
||||
Student stu = Context.Students.Find(x);
|
||||
if (stu != null)
|
||||
{
|
||||
stu.InterviewTime = Guid.Empty;
|
||||
stu.Timelist.RemoveAll(it => it == guid);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
foreach(var x in Context.Students)
|
||||
{
|
||||
x.Timelist.RemoveAll(it => it == guid);
|
||||
}
|
||||
Context.Sessions.Remove(InterviewTime);
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
@page
|
||||
@model _2021_backend.Pages.Sessions.DetailsModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
||||
}
|
||||
|
||||
<h1>Details</h1>
|
||||
|
||||
<div>
|
||||
<h4>InterviewTime</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.Day)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.Day)
|
||||
</dd>
|
||||
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.BeginTime)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.BeginTime)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.Place)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.Place)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.Chiefs)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@{
|
||||
var nm = "";
|
||||
foreach (var e in Model.CurSession.Chiefs)
|
||||
{
|
||||
nm += Model.Context.Users.Find(e).Name + " ";
|
||||
}
|
||||
@Html.DisplayFor(model => nm);
|
||||
}
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.Capacity)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.Capacity)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
已经报名人数
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.Students.Count)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.CurSession.SendSMS)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.CurSession.SendSMS)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a asp-page="./Edit" asp-route-id="@Model.CurSession.Guid">Edit</a> |
|
||||
<a asp-page="./Index">Back to List</a>
|
||||
</div>
|
||||
@@ -0,0 +1,39 @@
|
||||
using _2021_backend.Data;
|
||||
using _2021_backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _2021_backend.Pages.Sessions
|
||||
{
|
||||
public class DetailsModel : PageModel
|
||||
{
|
||||
public _2021_backend.Data.BackendContext Context;
|
||||
|
||||
public DetailsModel(_2021_backend.Data.BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public Session CurSession { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string? id)
|
||||
{
|
||||
Guid guid = Guid.Parse(id);
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
CurSession = Context.Sessions.Find(guid);
|
||||
if (CurSession == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
@page
|
||||
@model _2021_backend.Pages.Sessions.EditModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
||||
}
|
||||
|
||||
<h1>编辑</h1>
|
||||
|
||||
<h4>InterviewTime</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="CurSession.Guid" />
|
||||
<input type="hidden" asp-for="CurGuid">
|
||||
<div class="form-group">
|
||||
<label asp-for="newDay" class="control-label"></label>
|
||||
<input asp-for="newDay" class="form-control" />
|
||||
<span asp-validation-for="CurSession.Day" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="newTime" class="control-label"></label>
|
||||
<input asp-for="newTime" class="form-control" />
|
||||
<span asp-validation-for="CurSession.BeginTime" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="newPlace" class="control-label"></label>
|
||||
<input asp-for="newPlace" class="form-control" />
|
||||
<span asp-validation-for="CurSession.Place" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="newCapacity" class="control-label"></label>
|
||||
<input asp-for="newCapacity" class="form-control" />
|
||||
<span asp-validation-for="CurSession.Capacity" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
<label class="form-check-label">
|
||||
<input class="form-check-input" asp-for="CurSession.SendSMS" /> @Html.DisplayNameFor(model => model.CurSession.SendSMS)
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<h4>该时段的活动者</h4>
|
||||
<form method="post">
|
||||
<label class="col-sm-2">添加一个</label>
|
||||
<select asp-items=Model.Stulist id="stuselect" asp-for="addedStu" class="col-sm-2"></select>
|
||||
<input type="hidden" asp-for="CurGuid" />
|
||||
<input type="submit" value="Go!" class="btn btn-primary" style="margin-left:5px" asp-page-handler="Add" />
|
||||
</form>
|
||||
<br />
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>学号</th>
|
||||
<th>姓名</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var it in Model.CurSession.Students)
|
||||
{
|
||||
<tr>
|
||||
@{
|
||||
var stu = Model.Context.Students.Find(it);
|
||||
if (stu != null)
|
||||
{
|
||||
var id = stu.Stuid;
|
||||
<td>@Html.DisplayFor(model=>id)</td>
|
||||
<td>@Html.DisplayFor(model=>stu.Name)</td>
|
||||
<td>
|
||||
|
||||
<a asp-page="/Students/Details" asp-route-idstr=@stu.Guid.ToString() class="btn btn-primary">详细信息</a>
|
||||
<div style="float:left">
|
||||
<form method="post">
|
||||
<input type="hidden" asp-for="CurGuid">
|
||||
<input type="submit" value="删除" class="btn btn-danger" asp-page-handler="Delete" asp-route-id=@stu.Guid.ToString() />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
<h4>活动官们</h4>
|
||||
<form method="post">
|
||||
<label class="col-sm-2">添加一个</label>
|
||||
<select id="chiefselect"asp-items=Model.ChiefList asp-for="addedChief" class="col-sm-2"></select>
|
||||
<input type="hidden" asp-for="CurGuid" />
|
||||
<input type="submit" value="Go!" class="btn btn-primary" style="margin-left:5px" asp-page-handler="AddChief" />
|
||||
</form>
|
||||
<br />
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>姓名</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var it in Model.CurSession.Chiefs)
|
||||
{
|
||||
<tr>
|
||||
@{
|
||||
var chf = Model.Context.Users.Find(it);
|
||||
if (chf != null)
|
||||
{
|
||||
<td>@Html.DisplayFor(model=>chf.Name)</td>
|
||||
<td>
|
||||
<div style="float:left">
|
||||
<form method="post">
|
||||
<input type="hidden" asp-for="CurGuid">
|
||||
<input type="submit" value="删除" class="btn btn-danger" asp-page-handler="DeleteChief" asp-route-id=@chf.Guid.ToString() />
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<a asp-page="./Index">Back to List</a>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||
<script type="text/javascirpt" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" />
|
||||
<script>
|
||||
$(function(){
|
||||
$("#chiefselect").select2();
|
||||
$("#stuselect").select2();
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
using _2021_backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace _2021_backend.Pages.Sessions
|
||||
{
|
||||
public class EditModel : PageModel
|
||||
{
|
||||
public _2021_backend.Data.BackendContext Context;
|
||||
|
||||
public EditModel(_2021_backend.Data.BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Session CurSession { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public string CurGuid { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public string ChiefSearch { get; set; }
|
||||
|
||||
public List<SelectListItem> ChiefList { get; set; }
|
||||
|
||||
public List<SelectListItem> Stulist { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public Guid addedChief { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public string addedStu { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public string ChiefName { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
[BindProperty]
|
||||
[Display(Name ="活动地点")]
|
||||
[RegularExpression(@"^20[04]$", ErrorMessage = "200或204")]
|
||||
[Required()]
|
||||
public string newPlace { get; set; }
|
||||
|
||||
|
||||
[BindProperty]
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
|
||||
[Required()]
|
||||
public DateTime newDay { get; set; }
|
||||
[BindProperty]
|
||||
[DataType(DataType.Time)]
|
||||
[DisplayFormat(DataFormatString = "{0:t}", ApplyFormatInEditMode = true)]
|
||||
[Required()]
|
||||
public DateTime newTime { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
[Required()]
|
||||
public bool sendSMS { get; set; }
|
||||
[BindProperty]
|
||||
public int newCapacity { get; set; }
|
||||
|
||||
public IActionResult Construct(string id)
|
||||
{
|
||||
Guid guid = Guid.Parse(id);
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
CurGuid = id;
|
||||
CurSession = Context.Sessions.Find(guid);
|
||||
|
||||
newDay = CurSession.Day;
|
||||
newTime = CurSession.BeginTime;
|
||||
newCapacity = CurSession.Capacity;
|
||||
sendSMS = CurSession.SendSMS;
|
||||
newPlace = CurSession.Place;
|
||||
|
||||
if (CurSession == null) return RedirectToPage("./Index", new { errmsg = "未找到该活动场次" });
|
||||
var qlst = from e in Context.Users select (new SelectListItem { Value = e.Guid.ToString(), Text = e.Name, Selected = false, Disabled = false });
|
||||
ChiefList = qlst.ToList().Distinct().ToList();
|
||||
|
||||
var slst = from e in Context.Students where e.InterviewTime == Guid.Empty select new SelectListItem { Value = e.Guid.ToString(), Text = e.Name, Selected = false, Disabled = false };
|
||||
Stulist = slst.ToList().Distinct().ToList();
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string id)
|
||||
{
|
||||
return Construct(id);
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
var ssn = Context.Sessions.Find(Guid.Parse(CurGuid));
|
||||
ssn.SendSMS = sendSMS;
|
||||
ssn.Day = newDay;
|
||||
ssn.BeginTime = newTime;
|
||||
ssn.Capacity = newCapacity;
|
||||
ssn.Place = newPlace;
|
||||
Context.SaveChanges();
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(string id)
|
||||
{
|
||||
CurSession = Context.Sessions.Find(Guid.Parse(CurGuid));
|
||||
var guid = Guid.Parse(id);
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
if (Context.Students.Any(it => it.Guid == guid))
|
||||
{
|
||||
Context.Students.Find(guid).InterviewTime = Guid.Empty;
|
||||
CurSession.Students.RemoveAll(it => it == guid);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
}
|
||||
return Construct(CurGuid);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddAsync()
|
||||
{
|
||||
CurSession = Context.Sessions.Find(Guid.Parse(CurGuid));
|
||||
var guid = Guid.Parse(addedStu);
|
||||
if (!string.IsNullOrEmpty(addedStu))
|
||||
{
|
||||
if (Context.Students.Any(it => it.Guid == guid))
|
||||
{
|
||||
var stu = Context.Students.Find(guid);
|
||||
if(stu.InterviewTime != Guid.Empty)
|
||||
{
|
||||
var oldtime = Context.Sessions.Find(stu.InterviewTime);
|
||||
if(oldtime != null)
|
||||
{
|
||||
oldtime.Students.RemoveAll(s => s == stu.Guid);
|
||||
Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
stu.InterviewTime = CurSession.Guid;
|
||||
stu.Status = status.已选时间;
|
||||
CurSession.Students.Add(guid);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
}
|
||||
return Construct(CurGuid);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddChiefAsync()
|
||||
{
|
||||
CurSession = Context.Sessions.Find(Guid.Parse(CurGuid));
|
||||
if (Context.Users.Any(it => it.Guid == addedChief))
|
||||
{
|
||||
CurSession.Chiefs.Add(addedChief);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct(CurGuid);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteChiefAsync(string id)
|
||||
{
|
||||
var guid = Guid.Parse(id);
|
||||
CurSession = Context.Sessions.Find(Guid.Parse(CurGuid));
|
||||
if (CurSession.Chiefs.Contains(guid))
|
||||
{
|
||||
CurSession.Chiefs.Remove(guid);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct(CurGuid);
|
||||
}
|
||||
|
||||
private bool InterviewTimeExists(Guid id)
|
||||
{
|
||||
return Context.Sessions.Any(e => e.Guid == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
@page
|
||||
@model _2021_backend.Pages.Sessions.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "活动时间管理";
|
||||
}
|
||||
|
||||
<h5 class="text-red">
|
||||
<strong>@Html.DisplayFor(model => Model.Errmsg)</strong>
|
||||
</h5>
|
||||
<h5><strong>全部活动场次</strong></h5>
|
||||
<a asp-page="./Create" class="btn btn-outline-info m-2">创建新的场次</a>
|
||||
<a asp-page="./Export" class="btn btn-outline-info m-2">导出</a>
|
||||
<form class="form-inline" method="post">
|
||||
<div class="m-2">
|
||||
筛选日期
|
||||
<select asp-for="Day" asp-items="Model.DayList" class="form-control">
|
||||
<option value="">全部</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div class="m-2">
|
||||
筛选场次
|
||||
<select asp-for="Room" class="form-control">
|
||||
<option value="">全部</option>
|
||||
<option value="200">200</option>
|
||||
<option value="204">204</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="m-2">
|
||||
<label class="form-check-label">
|
||||
只显示未满场次
|
||||
<input class="form-check-input" asp-for="onlyShowUnFull" />
|
||||
</label>
|
||||
</div>
|
||||
<input type="submit" value="筛选" class="btn btn-outline-primary m-2" />
|
||||
<input type="submit" value="自动生成新的排班" class="btn btn-outline-warning m-2" asp-page-handler="Arrange" />
|
||||
<input type="submit" value="全部清空" class="btn btn-outline-danger m-2" asp-page-handler="ClearAll" />
|
||||
<input type="submit" value="整理一下" class="btn btn-outline-info m-2" asp-page-handler="Tidy" />
|
||||
<input type="submit" value="重置全部场次" class="btn btn-outline-danger m-2" asp-page-handler="ResetAll" />
|
||||
<input type="submit" value="保存当前结果" class="btn btn-outline-danger m-2" asp-page-handler="Save" />
|
||||
<div class="m-2">
|
||||
加载存档
|
||||
<select asp-for="savename" class="form-control" asp-items="Model.Files">
|
||||
</select>
|
||||
</div>
|
||||
<input type="submit" value="Go!" class="btn btn-outline-danger m-2" asp-page-handler="Load" />
|
||||
|
||||
@*<input type="submit" value="保存这个结果!" class="btn btn-outline-warning m-2" asp-page-handler="Save"/>
|
||||
<div class="m-2">
|
||||
加载以前的结果
|
||||
<select asp-for="TargetIndex" class="form-control" asp-items="@Model.SaveNames">
|
||||
</select>
|
||||
</div>*@
|
||||
@*<input type="submit" value="Load!" class="btn btn-outline-primary m-2" asp-page-handler="Load"/>*@
|
||||
|
||||
</form>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
序号
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.LoadedSessions[0].Day)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.LoadedSessions[0].BeginTime)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.LoadedSessions[0].Place)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.LoadedSessions[0].Chiefs)
|
||||
</th>
|
||||
<th>
|
||||
剩余可用人数
|
||||
</th>
|
||||
<th>
|
||||
容量
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.LoadedSessions[0].SendSMS)
|
||||
</th>
|
||||
<th>
|
||||
参与者
|
||||
</th>
|
||||
<th>
|
||||
操作
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@{
|
||||
var idx = 0;
|
||||
}
|
||||
@foreach (var item in Model.LoadedSessions)
|
||||
{
|
||||
<tr class="@{
|
||||
if (item.Day.Date.Add(item.BeginTime.TimeOfDay).CompareTo(DateTime.Now) < 0)
|
||||
@("table-secondary")
|
||||
else if (item.Students.Count == item.Capacity)
|
||||
@("table-warning")
|
||||
else if(item.Place=="200")
|
||||
@("table-success")
|
||||
else
|
||||
@("table-info")
|
||||
} ">
|
||||
<td>
|
||||
@{
|
||||
idx++;
|
||||
@Html.DisplayFor(mi => idx)
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Day)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.BeginTime)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Place)
|
||||
</td>
|
||||
<td>
|
||||
@{
|
||||
var str = "";
|
||||
foreach (var i in item.Chiefs)
|
||||
{
|
||||
str += Model.Context.Users.Find(i).Name + " ";
|
||||
}
|
||||
@Html.DisplayFor(modelItem => str)
|
||||
;
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Capacity)
|
||||
</td>
|
||||
<td>
|
||||
@{
|
||||
var cnt = item.Capacity - item.Students.Count;
|
||||
@Html.DisplayFor(modelItem => cnt)
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SendSMS)
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@foreach (var it in item.Students)
|
||||
{
|
||||
var q = Model.Context.Students.Find(it);
|
||||
var s = q.Name;
|
||||
<a asp-page="/Students/Details" asp-route-idstr=@it.ToString()>@Html.DisplayFor(modelItem => s)</a>
|
||||
@: 
|
||||
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<a asp-page="./Edit" asp-route-id="@item.Guid">编辑</a> |
|
||||
<a asp-page="./Delete" asp-route-id="@item.Guid">删除</a> |
|
||||
<a asp-page-handler="Reset" asp-route-id="@item.Guid">重置</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,283 @@
|
||||
using _2021_backend.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
using System.IO;
|
||||
|
||||
namespace _2021_backend.Pages.Sessions
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
public readonly _2021_backend.Data.BackendContext Context;
|
||||
public IndexModel(_2021_backend.Data.BackendContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
public List<Session> LoadedSessions { get; set; }
|
||||
public SelectList DayList { get; set; }
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public string Room { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public string Errmsg { get;set; }
|
||||
|
||||
[BindProperty]
|
||||
public string savename { get; set; }
|
||||
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public bool onlyShowUnFull { get; set; }
|
||||
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public DateTime Day { get; set; }
|
||||
|
||||
[BindProperty]
|
||||
public int TargetIndex { get; set; }
|
||||
|
||||
|
||||
public SelectList Files { get; set; }
|
||||
|
||||
public IActionResult Construct(string errmsg)
|
||||
{
|
||||
Errmsg = errmsg;
|
||||
var q = from s in Context.Sessions select s;
|
||||
if (Day != DateTime.MinValue)
|
||||
{
|
||||
q = from t in q where t.Day == Day select t;
|
||||
}
|
||||
if (Room == "200" || Room == "204")
|
||||
{
|
||||
q = from t in q where t.Place == Room select t;
|
||||
}
|
||||
if (onlyShowUnFull)
|
||||
{
|
||||
q = from t in q where t.Capacity != t.Students.Count select t;
|
||||
}
|
||||
LoadedSessions = q.ToList();
|
||||
LoadedSessions.Sort((Session a, Session b) =>
|
||||
{
|
||||
var x = a.Day.Date.Add(a.BeginTime.TimeOfDay).CompareTo(DateTime.Now);
|
||||
var y = b.Day.Date.Add(b.BeginTime.TimeOfDay).CompareTo(DateTime.Now);
|
||||
if (x != y) return y - x;
|
||||
else
|
||||
{
|
||||
var z = a.Day.Date.Add(a.BeginTime.TimeOfDay).CompareTo(b.Day.Date.Add(b.BeginTime.TimeOfDay));
|
||||
if (z != 0) return z;
|
||||
else
|
||||
{
|
||||
if (a.BeginTime < b.BeginTime) return -1;
|
||||
else if (a.BeginTime > b.BeginTime) return 1;
|
||||
else if (a.Place == "200") return -1;
|
||||
else if (a.Place == "204") return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
var l = from it in LoadedSessions select it.Day;
|
||||
DayList = new SelectList(l.Distinct());
|
||||
if (!Directory.Exists("./saves")) Directory.CreateDirectory("./saves");
|
||||
Files = new SelectList(Directory.GetFiles("./saves").ToList());
|
||||
//Console.WriteLine(Files);
|
||||
return Page();
|
||||
}
|
||||
public async Task<IActionResult> OnGetAsync(string errmsg)
|
||||
{
|
||||
return Construct(errmsg);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetResetAsync(Guid id)
|
||||
{
|
||||
if(Context.Sessions.Any(it => it.Guid == id))
|
||||
{
|
||||
var s = Context.Sessions.Find(id);
|
||||
foreach(var st in s.Students)
|
||||
{
|
||||
var e = Context.Students.Find(st);
|
||||
e.Status = status.需调整时间;
|
||||
e.InterviewTime = Guid.Empty;
|
||||
}
|
||||
s.Students.Clear();
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct("");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost()
|
||||
{
|
||||
return Construct("");
|
||||
}
|
||||
|
||||
//public async Task<IActionResult> OnPostLoadAsync()
|
||||
//{
|
||||
|
||||
// return Construct("");
|
||||
//}
|
||||
//public async Task<IActionResult> OnPostSaveAsync()
|
||||
//{
|
||||
|
||||
// return Construct("");
|
||||
//}
|
||||
|
||||
public async Task<IActionResult> OnPostArrangeAsync()
|
||||
{
|
||||
if (Utils.Arranger.Arrange(Context)) return Construct("");
|
||||
else return Construct("排班失败,无法满足条件");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostClearAllAsync()
|
||||
{
|
||||
foreach(var s in Context.Students)
|
||||
{
|
||||
s.InterviewTime = Guid.Empty;
|
||||
s.Status = status.需调整时间;
|
||||
s.Timelist.Clear();
|
||||
}
|
||||
Context.SaveChanges();
|
||||
foreach(var s in Context.Sessions)
|
||||
{
|
||||
Context.Sessions.Remove(s);
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct("");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostResetAllAsync()
|
||||
{
|
||||
var stus = Context.Students.ToList();
|
||||
foreach (var s in stus)
|
||||
{
|
||||
if(s.Status == status.已选时间)
|
||||
{
|
||||
s.InterviewTime = Guid.Empty;
|
||||
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Guid == it));
|
||||
s.Timelist.Sort((Guid a, Guid b) =>
|
||||
{
|
||||
var x = Context.Sessions.Find(a);
|
||||
var y = Context.Sessions.Find(b);
|
||||
var k1 = x.Day.CompareTo(y.Day);
|
||||
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
||||
return k1 != 0 ? k1 : k2;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Context.SaveChanges();
|
||||
foreach (var s in Context.Sessions)
|
||||
{
|
||||
s.Students.Clear();
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct("");
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostSaveAsync()
|
||||
{
|
||||
var lst = Context.Sessions.ToList();
|
||||
var str = JsonSerializer.Serialize(lst);
|
||||
Console.WriteLine("Saving arrangement: " + str);
|
||||
if(!Directory.Exists("./saves")) Directory.CreateDirectory("./saves/");
|
||||
System.IO.File.WriteAllText($"./saves/{DateTime.Now.ToString("MM-dd-hh-mm-ss")}.txt", str);
|
||||
return Construct("");
|
||||
}
|
||||
public async Task<IActionResult> OnPostTidyAsync()
|
||||
{
|
||||
var stus = Context.Students.ToList();
|
||||
var sess = Context.Sessions.ToList();
|
||||
foreach(var i in stus)
|
||||
{
|
||||
var tm = i.Timelist;
|
||||
var ntm = new List<Session>();
|
||||
foreach(var j in tm)
|
||||
{
|
||||
var k = sess.Find(it => it.Guid == j);
|
||||
ntm.Add(k);
|
||||
}
|
||||
ntm.Sort((Session a,Session b) =>
|
||||
{
|
||||
var x = a.Day.CompareTo(b.Day);
|
||||
var y = a.BeginTime.CompareTo(b.BeginTime);
|
||||
return x != 0 ? x : y;
|
||||
});
|
||||
List<Guid> nl = new List<Guid>();
|
||||
foreach(var j in ntm)
|
||||
{
|
||||
if(i.Status != status.不通过 && i.Status != status.通过 && i.Status != status.已确认时间)
|
||||
{
|
||||
if (j.Day.Date.Add(j.BeginTime.TimeOfDay).CompareTo(DateTime.Now) < 0 || (j.Students.Count >= j.Capacity && !j.Students.Any(k => k ==i.Guid) )) continue;
|
||||
nl.Add(j.Guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
nl.Add(j.Guid);
|
||||
}
|
||||
|
||||
}
|
||||
i.Timelist = nl;
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct("");
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> OnPostLoadAsync()
|
||||
{
|
||||
var str = "";
|
||||
|
||||
List<Session> loads = new List<Session>();
|
||||
if (!string.IsNullOrEmpty(savename)) str = System.IO.File.ReadAllText(savename);
|
||||
loads = JsonSerializer.Deserialize<List<Session>>(str);
|
||||
|
||||
var stus = Context.Students.ToList();
|
||||
foreach (var s in stus)
|
||||
{
|
||||
if (s.Status == status.已选时间)
|
||||
{
|
||||
s.InterviewTime = Guid.Empty;
|
||||
s.Timelist.RemoveAll(it => !Context.Sessions.Any(k => k.Guid == it));
|
||||
s.Timelist.Sort((Guid a, Guid b) =>
|
||||
{
|
||||
var x = Context.Sessions.Find(a);
|
||||
var y = Context.Sessions.Find(b);
|
||||
var k1 = x.Day.CompareTo(y.Day);
|
||||
var k2 = x.BeginTime.CompareTo(y.BeginTime);
|
||||
return k1 != 0 ? k1 : k2;
|
||||
});
|
||||
}
|
||||
}
|
||||
Context.SaveChanges();
|
||||
foreach (var s in Context.Sessions)
|
||||
{
|
||||
s.Students.Clear();
|
||||
}
|
||||
Context.SaveChanges();
|
||||
foreach(var item in loads)
|
||||
{
|
||||
Session s = Context.Sessions.Find(item.Guid);
|
||||
if(s != null)
|
||||
{
|
||||
s.BeginTime = item.BeginTime;
|
||||
s.Day = item.Day;
|
||||
s.Capacity = item.Capacity;
|
||||
s.SendSMS = item.SendSMS;
|
||||
s.Chiefs = item.Chiefs;
|
||||
s.Students = new List<Guid>();
|
||||
foreach(var s2 in item.Students)
|
||||
{
|
||||
if (Context.Students.Any(k => k.Guid == s2))
|
||||
{
|
||||
Context.Students.Find(s2).InterviewTime = item.Guid;
|
||||
s.Students.Add(s2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Context.SaveChanges();
|
||||
return Construct("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user