Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Edit basic information club board, remove detail page club board
Browse files Browse the repository at this point in the history
  • Loading branch information
thientm27 committed Aug 23, 2023
1 parent 3475740 commit ed6f74c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 157 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page
@using ClubMemberShip.Repo.Models
@model ClubMemberShip.Web.Pages.PageUser.ClubBoardManage.EditModel

@{
Expand All @@ -8,48 +9,104 @@
<h1>Edit</h1>

<h4>ClubBoard</h4>
<hr />
<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="ClubBoard.Id" />
<input type="hidden" asp-for="ClubBoard.Id"/>
<div class="form-group">
<label asp-for="ClubBoard.ClubId" class="control-label"></label>
<select asp-for="ClubBoard.ClubId" class="form-control" asp-items="ViewBag.ClubId"></select>
<select disabled="disabled" asp-for="ClubBoard.ClubId" class="form-control" asp-items="ViewBag.ClubId"></select>
<input hidden="hidden" asp-for="ClubBoard.ClubId" value="@Model.ClubBoard.ClubId"/>
<span asp-validation-for="ClubBoard.ClubId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ClubBoard.Name" class="control-label"></label>
<input asp-for="ClubBoard.Name" class="form-control" />
@{
if (@Model.ClubBoard.Name == "Owner")
{
<input asp-for="ClubBoard.Name" readonly="readonly" class="form-control" required="required"/>
}
else
{
<input asp-for="ClubBoard.Name" class="form-control" required="required"/>
}
}

<span asp-validation-for="ClubBoard.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ClubBoard.ShortDecription" class="control-label"></label>
<input asp-for="ClubBoard.ShortDecription" class="form-control" />
<input asp-for="ClubBoard.ShortDecription" class="form-control" required="required"/>
<span asp-validation-for="ClubBoard.ShortDecription" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ClubBoard.LongDecription" class="control-label"></label>
<input asp-for="ClubBoard.LongDecription" class="form-control" />
<input asp-for="ClubBoard.LongDecription" class="form-control" required="required"/>
<span asp-validation-for="ClubBoard.LongDecription" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ClubBoard.Status" class="control-label"></label>
<input asp-for="ClubBoard.Status" class="form-control" />
<span asp-validation-for="ClubBoard.Status" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
<input type="submit" value="Save" class="btn btn-primary"/>
</div>
</form>
</div>
</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>
</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>
</tr>
}
</tbody>
</table>

<div>
<a asp-page="./Index">Back to List</a>
<a asp-page="./Index" asp-route-clubId="@Model.ClubBoard.Id">Back to List</a>
</div>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
Original file line number Diff line number Diff line change
@@ -1,77 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ClubMemberShip.Repo.Models;
using ClubMemberShip.Service;

namespace ClubMemberShip.Web.Pages.PageUser.ClubBoardManage
{
public class EditModel : PageModel
{
private readonly ClubMemberShip.Repo.Models.ClubMembershipContext _context;

public EditModel(ClubMemberShip.Repo.Models.ClubMembershipContext context)
private IClubBoardService _clubBoardService;
private IClubServices _clubServices;
private IMemberRoleService _memberRoleService;
public IList<Student> NotAddStudent { get; set; } = default!;
[BindProperty(SupportsGet = true)] public int PageIndex1 { get; set; } = 1;
public int PageSize1 { get; set; } = 3;
public int TotalPages1;

public EditModel(IClubBoardService clubBoardService, IClubServices clubServices,
IMemberRoleService memberRoleService)
{
_context = context;
_clubBoardService = clubBoardService;
_clubServices = clubServices;
_memberRoleService = memberRoleService;
}

[BindProperty]
public ClubBoard ClubBoard { get; set; } = default!;
[BindProperty] public ClubBoard ClubBoard { get; set; } = default!;

public async Task<IActionResult> OnGetAsync(int? id)
public IActionResult OnGet(int? id)
{
if (id == null || _context.ClubBoards == null)
if (id == null)
{
return NotFound();
}

var clubboard = await _context.ClubBoards.FirstOrDefaultAsync(m => m.Id == id);
var clubboard = _clubBoardService.GetById(id);
if (clubboard == null)
{
return NotFound();
}
ClubBoard = clubboard;
ViewData["ClubId"] = new SelectList(_context.Clubs, "Id", "Code");
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();
}

_context.Attach(ClubBoard).State = EntityState.Modified;
ClubBoard = clubboard;
ViewData["ClubId"] = new SelectList(_clubServices.Get(), "Id", "Name");

try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ClubBoardExists(ClubBoard.Id))
{
return NotFound();
}
else
{
throw;
}
}

return RedirectToPage("./Index");
var data = _memberRoleService.GetPaginationAllMemberOfBoard(PageIndex1 - 1, PageSize1, ClubBoard.Id);
TotalPages1 = data.TotalPagesCount;
NotAddStudent = data.Items.ToList();
return Page();
}

private bool ClubBoardExists(int id)
public IActionResult OnPost()
{
return (_context.ClubBoards?.Any(e => e.Id == id)).GetValueOrDefault();
_clubBoardService.Update(ClubBoard);
return RedirectToPage("./Index", new { clubId = ClubBoard.ClubId });
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.Id">Details</a> |

@{
if (item.Name != "Owner")
Expand Down
2 changes: 2 additions & 0 deletions Clup-MemberShip/ClubMemberShip.Service/IMemberRoleService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using ClubMemberShip.Repo.Models;
using ClubMemberShip.Repo.Utils;

namespace ClubMemberShip.Service;

public interface IMemberRoleService : IGenericService<MemberRole>
{
public void AddMultipleMember(int clubId, int clubBoardId, List<int> studentId);
public List<Student> GetAllMemberOfBoard(int boardId);
public Pagination<Student> GetPaginationAllMemberOfBoard(int pageIndex, int pageSize, int boardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public List<Student> GetAllMemberOfBoard(int clubId)
var membership =
UnitOfWork.MemberShipRepo.Get(filter: o => listId.Contains(o.Id));

var listStudentId = membership.Select(o => o.Id);
return UnitOfWork.StudentRepo.Get(filter: o => listStudentId.Contains(o.Id));
var listStudentId = membership.Select(o => o.StudentId);
return UnitOfWork.StudentRepo.Get(filter: o => listStudentId.Contains(o.Id), includeProperties: "Grade,Major");
}

public Pagination<Student> GetPaginationAllMemberOfBoard(int pageIndex, int pageSize, int boardId)
{
var listEntities = GetAllMemberOfBoard(boardId);
return UnitOfWork.StudentRepo.ToPagination(listEntities, pageIndex, pageSize);
}
}

0 comments on commit ed6f74c

Please sign in to comment.