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

Commit

Permalink
add create2 view
Browse files Browse the repository at this point in the history
  • Loading branch information
thientm27 committed Aug 23, 2023
1 parent 2702620 commit 188ebed
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IActionResult OnPost()

HttpContext.Session.SetObjectAsJson("ClubBoard", ClubBoard);

return RedirectToPage("./Index");
return RedirectToPage("./Create2");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,66 @@

<h1>Create2</h1>

<h4>Membership</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="Membership.StudentId" class="control-label"></label>
<select asp-for="Membership.StudentId" class ="form-control" asp-items="ViewBag.StudentId"></select>
</div>
<div class="form-group">
<label asp-for="Membership.ClubId" class="control-label"></label>
<select asp-for="Membership.ClubId" class ="form-control" asp-items="ViewBag.ClubId"></select>
</div>
<div class="form-group">
<label asp-for="Membership.Id" class="control-label"></label>
<input asp-for="Membership.Id" class="form-control" />
<span asp-validation-for="Membership.Id" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Membership.JoinDate" class="control-label"></label>
<input asp-for="Membership.JoinDate" class="form-control" />
<span asp-validation-for="Membership.JoinDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Membership.QuitDate" class="control-label"></label>
<input asp-for="Membership.QuitDate" class="form-control" />
<span asp-validation-for="Membership.QuitDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Membership.NickName" class="control-label"></label>
<input asp-for="Membership.NickName" class="form-control" />
<span asp-validation-for="Membership.NickName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Membership.Status" class="control-label"></label>
<input asp-for="Membership.Status" class="form-control" />
<span asp-validation-for="Membership.Status" class="text-danger"></span>
</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");}
<p>
<a asp-page="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Student[0].Code)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].Address)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].DateOfBirth)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].Grade)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].Major)
</th>
<th>
@Html.DisplayNameFor(model => model.Student[0].Status)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Student) {
<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.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Major.Code)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.Id">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ClubMemberShip.Repo.Models;

namespace ClubMemberShip.Web.Pages.PageUser.ClubBoardManage
Expand All @@ -18,29 +18,16 @@ public Create2Model(ClubMemberShip.Repo.Models.ClubMembershipContext context)
_context = context;
}

public IActionResult OnGet()
{
ViewData["ClubId"] = new SelectList(_context.Clubs, "Id", "Code");
ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Code");
return Page();
}

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

public IList<Student> Student { get;set; } = default!;

// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
public async Task<IActionResult> OnPostAsync()
public async Task OnGetAsync()
{
if (!ModelState.IsValid || _context.Memberships == null || Membership == null)
if (_context.Students != null)
{
return Page();
Student = await _context.Students
.Include(s => s.Grade)
.Include(s => s.Major).ToListAsync();
}

_context.Memberships.Add(Membership);
await _context.SaveChangesAsync();

return RedirectToPage("./Index");
}
}
}

0 comments on commit 188ebed

Please sign in to comment.