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

Commit

Permalink
Edit club board
Browse files Browse the repository at this point in the history
  • Loading branch information
thientm27 committed Aug 23, 2023
1 parent 0daacad commit f5b672a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ namespace ClubMemberShip.Web.Pages.PageUser.ClubBoardManage
public class Create2Model : PageModel
{
private readonly IStudentServices _studentServices;
private readonly IParticipantService _participantService;
private readonly IClubActivityService _clubActivityService;
private readonly IMemberShipService _memberShipService;
private readonly IClubServices _clubServices;
private readonly IClubBoardService _clubBoardService;
private readonly IMemberRoleService _memberRoleService;


public Create2Model(IStudentServices studentServices, IClubServices clubServices,
IParticipantService participantService, IClubActivityService clubActivityService,
IMemberShipService memberShipService)
IClubBoardService clubBoardService, IMemberRoleService memberRoleService)
{
_studentServices = studentServices;
_clubServices = clubServices;
_participantService = participantService;
_clubActivityService = clubActivityService;
_memberShipService = memberShipService;
_clubBoardService = clubBoardService;
_memberRoleService = memberRoleService;
}

public IList<Student> Student { get; set; } = default!;
Expand Down Expand Up @@ -101,11 +99,6 @@ public IActionResult OnPostRemove(int? id)
return NotFound();
}

// if (id == studentLogin.Id) // remove current
// {
// return OnGet();
// }

var sessionData = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ??
new AddedStudentObject();
sessionData.List.Remove((int)id);
Expand All @@ -124,25 +117,22 @@ public IActionResult OnPostSubmit()

var addedStudent = HttpContext.Session.GetObjectFromJson<AddedStudentObject>("AddedStudent") ??
new AddedStudentObject();
var clubActivity = HttpContext.Session.GetObjectFromJson<ClubActivity>("ClubBoard");

var clubBoard = HttpContext.Session.GetObjectFromJson<ClubBoard>("ClubBoard");

if (clubActivity == null)
if (clubBoard == null)
{
return RedirectToPage("./Create");
}

// var activity = _clubActivityService.AddWithResult(clubActivity);
var clubBoardData = _clubServices.CreateClubBoard(clubBoard);

// if (activity == null)
// {
// return RedirectToPage("./Create");
// }

// addedStudent.List.Add(studentLogin.Id);
// _participantService.AddMultipleMember(activity.ClubId, activity.Id, addedStudent.List);
if (clubBoardData == null)
{
return RedirectToPage("./Create");
}

return RedirectToPage("../Index");
_memberRoleService.AddMultipleMember(clubBoardData.ClubId, clubBoard.Id, addedStudent.List);
return RedirectToPage("./Index", new { clubId = clubBoardData.ClubId });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

<form method="post">
<input type="hidden" asp-for="ClubBoard.Id" />
<input type="hidden" asp-for="ClubBoard.ClubId" />
<input type="submit" value="Delete" class="btn btn-danger" /> |
<a asp-page="./Index">Back to List</a>
<a asp-page="./Index" asp-route-clubId="@Model.ClubId">Back to List</a>
</form>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,54 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using ClubMemberShip.Repo.Models;
using ClubMemberShip.Service;

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

public DeleteModel(ClubMemberShip.Repo.Models.ClubMembershipContext context)
public DeleteModel(IClubBoardService clubBoardService)
{
_context = context;
_clubBoardService = clubBoardService;
}

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

public async Task<IActionResult> OnGetAsync(int? id)
public int ClubId { get; set; }

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();
}
else
else
{
ClubBoard = clubboard;
}

ClubId = clubboard.ClubId;
return Page();
}

public async Task<IActionResult> OnPostAsync(int? id)
public IActionResult OnPost(int? id)
{
if (id == null || _context.ClubBoards == null)
if (id == null)
{
return NotFound();
}
var clubboard = await _context.ClubBoards.FindAsync(id);

if (clubboard != null)
{
ClubBoard = clubboard;
_context.ClubBoards.Remove(ClubBoard);
await _context.SaveChangesAsync();
}

return RedirectToPage("./Index");
_clubBoardService.Delete(ClubBoard.Id);
return RedirectToPage("./Index", new { clubid = ClubBoard.ClubId });
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Html.DisplayNameFor(model => model.ClubBoard[0].LongDecription)
</th>
<th>
@Html.DisplayNameFor(model => model.ClubBoard[0].Club)
@Html.DisplayNameFor(model => model.ClubBoard[0].Club.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.ClubBoard[0].Status)
Expand Down
1 change: 1 addition & 0 deletions Clup-MemberShip/ClubMemberShip.Present/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
builder.Services.AddScoped<IMemberShipService, MemberShipService>();
builder.Services.AddScoped<IParticipantService, ParticipantService>();
builder.Services.AddScoped<IClubBoardService, ClubBoardService>();
builder.Services.AddScoped<IMemberRoleService, MemberRoleService>();
builder.Services.AddRazorPages(options => { options.Conventions.AddPageRoute("/Login", ""); });

var app = builder.Build();
Expand Down
8 changes: 8 additions & 0 deletions Clup-MemberShip/ClubMemberShip.Service/IMemberRoleService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using ClubMemberShip.Repo.Models;

namespace ClubMemberShip.Service;

public interface IMemberRoleService : IGenericService<MemberRole>
{
public void AddMultipleMember(int clubId, int clubBoardId, List<int> studentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public override Result Add(ClubBoard newEntity)

public List<ClubBoard> GetByClubId(int clubId)
{
return UnitOfWork.ClubBoardRepo.Get(filter: o => o.ClubId == clubId);
return UnitOfWork.ClubBoardRepo.Get(filter: o => o.ClubId == clubId, includeProperties: "Club");
}
}
9 changes: 6 additions & 3 deletions Clup-MemberShip/ClubMemberShip.Service/Service/ClubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ public Pagination<Student> GetStudentInClub(int pageIndex, int pageSize, int clu
includeProperties: "Major,Grade");
return UnitOfWork.StudentRepo.ToPagination(listEntities, pageIndex, pageSize);
}

public Pagination<Student> GetStudentInClub(int pageIndex, int pageSize, int clubId, List<int> ignoreList)
{
var joinedList =
UnitOfWork.MemberShipRepo.Get(filter: o => o.ClubId == clubId && o.Status == Status.Active);
var studentInClubId = joinedList.Select(joined => joined.StudentId).ToList();
var listEntities = UnitOfWork.StudentRepo.Get(filter: o => studentInClubId.Contains(o.Id) && !ignoreList.Contains(o.Id),
var listEntities = UnitOfWork.StudentRepo.Get(
filter: o => studentInClubId.Contains(o.Id) && !ignoreList.Contains(o.Id),
includeProperties: "Major,Grade");

return UnitOfWork.StudentRepo.ToPagination(listEntities, pageIndex, pageSize);
}

public Pagination<Student> GetStudentRegisterInClub(int pageIndex, int pageSize, int clubId)
{
var joinedList =
Expand Down Expand Up @@ -175,7 +178,7 @@ public Pagination<ClubActivity> GetActivityInClub(int pageIndex, int pageSize, i

public ClubBoard? CreateClubBoard(ClubBoard newClubBoard, bool save = true)
{
var maxId = UnitOfWork.ClubBoardRepo.Get().Max(o => o.Id);
var maxId = UnitOfWork.ClubBoardRepo.GetIgnoreDeleted().Max(o => o.Id);
newClubBoard.Id = maxId + 1;

var result = UnitOfWork.ClubBoardRepo.Create(newClubBoard);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using ClubMemberShip.Repo;
using ClubMemberShip.Repo.Models;
using ClubMemberShip.Repo.Utils;

namespace ClubMemberShip.Service.Service;

public class MemberRoleService : GenericService<MemberRole>, IMemberRoleService
{
public MemberRoleService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}

public override List<MemberRole>? Get()
{
throw new NotImplementedException();
}

public override Pagination<MemberRole> GetPagination(int pageIndex, int pageSize)
{
throw new NotImplementedException();
}

public override MemberRole? GetById(object? id)
{
throw new NotImplementedException();
}

public override Result Update(MemberRole newEntity)
{
throw new NotImplementedException();
}

public override Result Delete(object idToDelete)
{
throw new NotImplementedException();
}

public override Result Add(MemberRole newEntity)
{
throw new NotImplementedException();
}

public void AddMultipleMember(int clubId, int clubBoardId, List<int> studentId)
{
var membership =
UnitOfWork.MemberShipRepo.Get(filter: o => o.ClubId == clubId && studentId.Contains(o.StudentId));

foreach (var o in membership)
{
var existed = UnitOfWork.MemberRoleRepo.GetIgnoreDeleted(filter: p =>
p.MembershipId == o.Id && p.ClubBoardId == clubBoardId);

if (existed.Count > 0)
{
existed[0].Status = Status.Active;
}
else
{
UnitOfWork.MemberRoleRepo.Create(new MemberRole
{
MembershipId = o.Id,
ClubBoardId = clubBoardId,
StartDay = DateTime.Today,
EndDay = default,
Role = null,
});
}
}

UnitOfWork.SaveChange();
}
}

0 comments on commit f5b672a

Please sign in to comment.