From 188ebed599c70bf3f9fd1862d10770e0cbef1efa Mon Sep 17 00:00:00 2001 From: thientm27 Date: Wed, 23 Aug 2023 11:29:30 +0700 Subject: [PATCH] add create2 view --- .../PageUser/ClubBoardManage/Create.cshtml.cs | 2 +- .../PageUser/ClubBoardManage/Create2.cshtml | 114 ++++++++++-------- .../ClubBoardManage/Create2.cshtml.cs | 27 ++--- 3 files changed, 70 insertions(+), 73 deletions(-) diff --git a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create.cshtml.cs b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create.cshtml.cs index 3fd7972..613e87c 100644 --- a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create.cshtml.cs +++ b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create.cshtml.cs @@ -55,7 +55,7 @@ public IActionResult OnPost() HttpContext.Session.SetObjectAsJson("ClubBoard", ClubBoard); - return RedirectToPage("./Index"); + return RedirectToPage("./Create2"); } } } \ No newline at end of file diff --git a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml index 863300f..14fa9e7 100644 --- a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml +++ b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml @@ -7,56 +7,66 @@

Create2

-

Membership

-
-
-
-
-
-
- - -
-
- - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- -
-
-
-
- -
- Back to List -
- -@section Scripts { - @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +

+ Create New +

+ + + + + + + + + + + + + + +@foreach (var item in Model.Student) { + + + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Student[0].Code) + + @Html.DisplayNameFor(model => model.Student[0].Name) + + @Html.DisplayNameFor(model => model.Student[0].Address) + + @Html.DisplayNameFor(model => model.Student[0].DateOfBirth) + + @Html.DisplayNameFor(model => model.Student[0].Grade) + + @Html.DisplayNameFor(model => model.Student[0].Major) + + @Html.DisplayNameFor(model => model.Student[0].Status) +
+ @Html.DisplayFor(modelItem => item.Code) + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Address) + + @Html.DisplayFor(modelItem => item.DateOfBirth) + + @Html.DisplayFor(modelItem => item.Grade.Id) + + @Html.DisplayFor(modelItem => item.Major.Code) + + @Html.DisplayFor(modelItem => item.Status) + + Edit | + Details | + Delete +
diff --git a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml.cs b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml.cs index bd419a9..755f00e 100644 --- a/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml.cs +++ b/Clup-MemberShip/ClubMemberShip.Present/Pages/PageUser/ClubBoardManage/Create2.cshtml.cs @@ -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 @@ -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 { get;set; } = default!; - // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD - public async Task 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"); } } }