This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
333 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Edit2.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
@page | ||
@model ClubMemberShip.Web.Pages.PageUser.ClubBoardManage.Edit2 | ||
|
||
@{ | ||
ViewData["Title"] = "Edit2"; | ||
} | ||
|
||
<h1>Change member of your club board</h1> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Code) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Name) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Address) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].DateOfBirth) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Grade) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Major) | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.NotAddStudent) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Code) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Address) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.DateOfBirth) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Grade.GradeYear.Year) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Major.Name) | ||
</td> | ||
<td> | ||
<form asp-page="./Edit2" method="post" asp-page-handler="Add" asp-route-id="@item.Id"> | ||
<button type="submit">Add</button> | ||
</form> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
<div> | ||
<ul class="pagination"> | ||
@for (var i = 1; i <= Model.TotalPages1; i++) | ||
{ | ||
<li class="page-item @(i == Model.PageIndex1 ? "active" : "")"> | ||
<a asp-page="./Edit2" asp-route-PageIndex1="@i" class="page-link">@i</a> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Code) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Name) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Address) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].DateOfBirth) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Grade) | ||
</th> | ||
<th> | ||
@Html.DisplayNameFor(model => model.NotAddStudent[0].Major) | ||
</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in Model.AddedStudent) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Code) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Name) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Address) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.DateOfBirth) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Grade.GradeYear.Year) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Major.Name) | ||
</td> | ||
<td> | ||
<form asp-page="./Edit2" method="post" asp-page-handler="Remove" asp-route-id="@item.Id"> | ||
<button type="submit">Remove</button> | ||
</form> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<form asp-page="./Edit2" method="post" asp-page-handler="Submit"> | ||
<button type="submit">Submit</button> | ||
</form> |
133 changes: 133 additions & 0 deletions
133
Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Edit2.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using ClubMemberShip.Repo.Models; | ||
using ClubMemberShip.Service; | ||
using ClubMemberShip.Web.Pages.PageUser.StudentActivity; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ClubMemberShip.Web.Pages.PageUser.ClubBoardManage | ||
{ | ||
public class Edit2 : PageModel | ||
{ | ||
private readonly IStudentServices _studentServices; | ||
private readonly IClubServices _clubServices; | ||
private readonly IClubBoardService _clubBoardService; | ||
private readonly IMemberRoleService _memberRoleService; | ||
|
||
|
||
public Edit2(IStudentServices studentServices, IClubServices clubServices, | ||
IClubBoardService clubBoardService, IMemberRoleService memberRoleService) | ||
{ | ||
_studentServices = studentServices; | ||
_clubServices = clubServices; | ||
_clubBoardService = clubBoardService; | ||
_memberRoleService = memberRoleService; | ||
} | ||
|
||
|
||
public IList<Student> NotAddStudent { get; set; } = default!; | ||
public IList<Student> AddedStudent { get; set; } = default!; | ||
[BindProperty(SupportsGet = true)] public int PageIndex1 { get; set; } = 1; | ||
public int PageSize1 { get; set; } = 3; | ||
public int TotalPages1; | ||
|
||
public IActionResult OnGet() | ||
{ | ||
var studentLogin = _studentServices.GetById(HttpContext.Session.GetString("User")); | ||
if (studentLogin == null) | ||
{ | ||
return RedirectToPage("/Login"); | ||
} | ||
|
||
AddedStudent = new List<Student>(); | ||
var sessionData = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ?? | ||
new AddedStudentObject(); | ||
|
||
var ignoreList = sessionData.List; | ||
foreach (var o in ignoreList) | ||
{ | ||
AddedStudent.Add(_studentServices.GetStudentById(o)!); | ||
} | ||
|
||
var clubBoard = HttpContext.Session.GetObjectFromJson<ClubBoard>("ClubBoard"); | ||
if (clubBoard == null) | ||
{ | ||
return RedirectToPage("./Index", new { clubId = clubBoard.ClubId }); | ||
} | ||
|
||
var data = _clubServices.GetStudentInClub(PageIndex1 - 1, PageSize1, clubBoard.ClubId, ignoreList); | ||
TotalPages1 = data.TotalPagesCount; | ||
NotAddStudent = data.Items.ToList(); | ||
|
||
return Page(); | ||
} | ||
|
||
public IActionResult OnPostAdd(int? id) | ||
{ | ||
var studentLogin = _studentServices.GetById(HttpContext.Session.GetString("User")); | ||
if (studentLogin == null) | ||
{ | ||
return RedirectToPage("/Login"); | ||
} | ||
|
||
var studentAdded = _studentServices.GetStudentById((int)id); | ||
if (studentAdded == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var sessionData = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ?? | ||
new AddedStudentObject(); | ||
sessionData.List.Add((int)id); | ||
HttpContext.Session.SetObjectAsJson("AddedStudent", sessionData); | ||
|
||
return OnGet(); | ||
} | ||
|
||
public IActionResult OnPostRemove(int? id) | ||
{ | ||
var studentLogin = _studentServices.GetById(HttpContext.Session.GetString("User")); | ||
if (studentLogin == null) | ||
{ | ||
return RedirectToPage("/Login"); | ||
} | ||
|
||
var studentAdded = _studentServices.GetStudentById((int)id); | ||
if (studentAdded == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var sessionData = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ?? | ||
new AddedStudentObject(); | ||
sessionData.List.Remove((int)id); | ||
HttpContext.Session.SetObjectAsJson("AddedStudent", sessionData); | ||
|
||
return OnGet(); | ||
} | ||
|
||
public IActionResult OnPostSubmit() | ||
{ | ||
var studentLogin = _studentServices.GetById(HttpContext.Session.GetString("User")); | ||
if (studentLogin == null) | ||
{ | ||
return RedirectToPage("/Login"); | ||
} | ||
|
||
var addedStudent = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ?? | ||
new AddedStudentObject(); | ||
var clubBoard = HttpContext.Session.GetObjectFromJson<ClubBoard>("ClubBoard"); | ||
|
||
if (clubBoard == null) | ||
{ | ||
return RedirectToPage("./Create"); | ||
} | ||
|
||
|
||
var originList = _memberRoleService.GetAllMemberOfBoard(clubBoard.Id); | ||
var originIds = originList.Select(o => o.Id).ToList(); | ||
_memberRoleService.RemoveMultipleMember(clubBoard.ClubId, clubBoard.Id, originIds); | ||
_memberRoleService.AddMultipleMember(clubBoard.ClubId, clubBoard.Id, addedStudent.List); | ||
return RedirectToPage("./Index", new { clubId = clubBoard.ClubId }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.