open changes
This commit is contained in:
52
wishlist/Pages/BlogPost/Create.razor
Normal file
52
wishlist/Pages/BlogPost/Create.razor
Normal file
@@ -0,0 +1,52 @@
|
||||
@page "/BlogPost/Create"
|
||||
|
||||
<PageTitle>Create</PageTitle>
|
||||
|
||||
@*<AuthorizeView Roles="Admin">*@
|
||||
<AuthorizeView Policy="@ProjectPolicies.BlogPostCreateClaimPolicy.Name">
|
||||
<Authorized>
|
||||
<h1>Create</h1>
|
||||
<h4>BlogPost</h4>
|
||||
<hr />
|
||||
@if (blogPost == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
|
||||
<EditForm Model="@blogPost" OnValidSubmit="@HandleValidSubmit" Context="createBlogPost">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">@nameof(BlogPostViewModel.Title)</label>
|
||||
<InputText @bind-Value="blogPost.Title" class="form-control" />
|
||||
<ValidationMessage For="@(() => blogPost.Title)" class="text-danger" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label">@nameof(BlogPostViewModel.Content)</label>
|
||||
<InputText @bind-Value="blogPost.Content" class="form-control" />
|
||||
<ValidationMessage For="@(() => blogPost.Content)" class="text-danger" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</div>
|
||||
|
||||
</EditForm>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="/BlogPost">Back to List</a>
|
||||
</div>
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p>Not Authorized</p>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
26
wishlist/Pages/BlogPost/Create.razor.cs
Normal file
26
wishlist/Pages/BlogPost/Create.razor.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using global::Wishlist.Models;
|
||||
using global::Wishlist.Services;
|
||||
|
||||
namespace Wishlist.Pages.BlogPost
|
||||
{
|
||||
public partial class Create
|
||||
{
|
||||
|
||||
private BlogPostViewModel? blogPost;
|
||||
|
||||
private async void HandleValidSubmit()
|
||||
{
|
||||
var model = Mapper.Map<BlogPostViewModel, Models.BlogPost>(blogPost);
|
||||
bool result = await BlogPostService.AddBlogPostAsync(model);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost");
|
||||
}
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
blogPost = new();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
53
wishlist/Pages/BlogPost/Delete.razor
Normal file
53
wishlist/Pages/BlogPost/Delete.razor
Normal file
@@ -0,0 +1,53 @@
|
||||
@page "/BlogPost/Delete/{id:int}"
|
||||
|
||||
<PageTitle>Delete</PageTitle>
|
||||
|
||||
@*<AuthorizeView Roles="Admin">*@
|
||||
<AuthorizeView Policy="@ProjectPolicies.BlogPostDeleteClaimPolicy.Name">
|
||||
<Authorized>
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
|
||||
@if (blogPost == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div>
|
||||
<h4>BlogPost</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Id)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Id
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Title)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Title
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Content)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Content
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-danger" @onclick="DeleteButtonClick">Delete</button> |
|
||||
<a href="/BlogPost">Back to List</a>
|
||||
</div>
|
||||
}
|
||||
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p>Not Authorized</p>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
33
wishlist/Pages/BlogPost/Delete.razor.cs
Normal file
33
wishlist/Pages/BlogPost/Delete.razor.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using global::Wishlist.Models;
|
||||
using global::Wishlist.Services;
|
||||
|
||||
namespace Wishlist.Pages.BlogPost
|
||||
{
|
||||
public partial class Delete
|
||||
{
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private BlogPostViewModel? blogPost;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPost == null)
|
||||
{
|
||||
var result = await BlogPostService.GetbyId(id);
|
||||
if (result != null)
|
||||
blogPost = Mapper.Map<Models.BlogPost, BlogPostViewModel>(result);
|
||||
}
|
||||
}
|
||||
|
||||
private async void DeleteButtonClick()
|
||||
{
|
||||
bool result = await BlogPostService.DeletebyIdAsync(id);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
49
wishlist/Pages/BlogPost/Details.razor
Normal file
49
wishlist/Pages/BlogPost/Details.razor
Normal file
@@ -0,0 +1,49 @@
|
||||
@page "/BlogPost/Details/{id:int}"
|
||||
|
||||
<PageTitle>Details</PageTitle>
|
||||
|
||||
<AuthorizeView Policy="@ProjectPolicies.BlogPostReadClaimPolicy.Name">
|
||||
<Authorized>
|
||||
<h1>Details</h1>
|
||||
@if (blogPost == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div>
|
||||
<h4>BlogPost</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Id)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Id
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Title)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Title
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@nameof(BlogPost.Content)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@blogPost.Content
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/BlogPost/Edit/@blogPost.Id">Edit</a> |
|
||||
<a href="/BlogPost">Back to List</a>
|
||||
</div>
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p>Not Authorized</p>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
26
wishlist/Pages/BlogPost/Details.razor.cs
Normal file
26
wishlist/Pages/BlogPost/Details.razor.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using global::Wishlist.Models;
|
||||
using global::Wishlist.Services;
|
||||
|
||||
namespace Wishlist.Pages.BlogPost
|
||||
{
|
||||
public partial class Details
|
||||
{
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private BlogPostViewModel? blogPost;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPost == null)
|
||||
{
|
||||
var result = await BlogPostService.GetbyId(id);
|
||||
if (result != null)
|
||||
blogPost = Mapper.Map<Models.BlogPost, BlogPostViewModel>(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
56
wishlist/Pages/BlogPost/Edit.razor
Normal file
56
wishlist/Pages/BlogPost/Edit.razor
Normal file
@@ -0,0 +1,56 @@
|
||||
@page "/BlogPost/Edit/{id:int}"
|
||||
|
||||
<PageTitle>Edit</PageTitle>
|
||||
|
||||
@*<AuthorizeView Roles="Admin">*@
|
||||
<AuthorizeView Policy="@ProjectPolicies.BlogPostUpdateClaimPolicy.Name">
|
||||
<Authorized>
|
||||
<h1>Edit</h1>
|
||||
<h4>BlogPost</h4>
|
||||
<hr />
|
||||
@if (blogPost == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
|
||||
<EditForm Model="@blogPost" OnValidSubmit="@HandleValidSubmit" Context="editBlogPost">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">@nameof(BlogPostViewModel.Title)</label>
|
||||
<InputText @bind-Value="blogPost.Title" class="form-control" />
|
||||
<ValidationMessage For="@(() => blogPost.Title)" class="text-danger" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label">@nameof(BlogPostViewModel.Content)</label>
|
||||
<InputText @bind-Value="blogPost.Content" class="form-control" />
|
||||
<ValidationMessage For="@(() => blogPost.Content)" class="text-danger" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</div>
|
||||
|
||||
|
||||
</EditForm>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="/BlogPost">Back to List</a>
|
||||
</div>
|
||||
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p>Not Authorized</p>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
36
wishlist/Pages/BlogPost/Edit.razor.cs
Normal file
36
wishlist/Pages/BlogPost/Edit.razor.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Wishlist.Models;
|
||||
using Wishlist.Services;
|
||||
|
||||
namespace Wishlist.Pages.BlogPost
|
||||
{
|
||||
public partial class Edit
|
||||
{
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private BlogPostViewModel? blogPost;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPost == null)
|
||||
{
|
||||
var result = await BlogPostService.GetbyId(id);
|
||||
if (result != null)
|
||||
blogPost = Mapper.Map<Models.BlogPost, BlogPostViewModel>(result);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private async void HandleValidSubmit()
|
||||
{
|
||||
var model = Mapper.Map<BlogPostViewModel, Models.BlogPost>(blogPost);
|
||||
bool result = await BlogPostService.UpdateBlogPostAsync(id, model);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
53
wishlist/Pages/BlogPost/Index.razor
Normal file
53
wishlist/Pages/BlogPost/Index.razor
Normal file
@@ -0,0 +1,53 @@
|
||||
@page "/BlogPost"
|
||||
|
||||
<PageTitle>Index</PageTitle>
|
||||
|
||||
<AuthorizeView Policy="@ProjectPolicies.BlogPostReadClaimPolicy.Name">
|
||||
<Authorized>
|
||||
<h1>Index</h1>
|
||||
<p>
|
||||
<a href="/BlogPost/Create">Create New</a>
|
||||
</p>
|
||||
@if (blogPosts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@nameof(BlogPostViewModel.Id)</th>
|
||||
<th>@nameof(BlogPostViewModel.Title)</th>
|
||||
<th>@nameof(BlogPostViewModel.Content)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var blogpost in blogPosts)
|
||||
{
|
||||
<tr>
|
||||
<td>@blogpost.Id</td>
|
||||
<td>@blogpost.Title</td>
|
||||
<td>@blogpost.Content</td>
|
||||
<td>
|
||||
<a href="/BlogPost/Details/@blogpost.Id">Details</a> |
|
||||
<AuthorizeView Policy="@nameof(ProjectPolicies.BlogPostUpdateClaimPolicy)" Context="editLink">
|
||||
<a href="/BlogPost/Edit/@blogpost.Id">Edit</a> |
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="@nameof(ProjectPolicies.BlogPostDeleteClaimPolicy)" Context="deleteLink">
|
||||
<a href="/BlogPost/Delete/@blogpost.Id">Delete</a>
|
||||
</AuthorizeView>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p>Not Authorized</p>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
20
wishlist/Pages/BlogPost/Index.razor.cs
Normal file
20
wishlist/Pages/BlogPost/Index.razor.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using global::Wishlist.Models;
|
||||
using global::Wishlist.Services;
|
||||
|
||||
namespace Wishlist.Pages.BlogPost
|
||||
{
|
||||
public partial class Index
|
||||
{
|
||||
private IEnumerable<BlogPostViewModel>? blogPosts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPosts == null)
|
||||
{
|
||||
var result = await BlogPostService.GetAllAsync();
|
||||
blogPosts = Mapper.Map<IEnumerable<Models.BlogPost>, IEnumerable<BlogPostViewModel>>(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
8
wishlist/Pages/BlogPost/_Imports.razor
Normal file
8
wishlist/Pages/BlogPost/_Imports.razor
Normal file
@@ -0,0 +1,8 @@
|
||||
@using AutoMapper;
|
||||
@using global::Wishlist.Data;
|
||||
@using global::Wishlist.Models;
|
||||
@using global::Wishlist.Services;
|
||||
|
||||
@inject IMapper Mapper;
|
||||
@inject NavigationManager NavigationManager;
|
||||
@inject BlogPostService BlogPostService;
|
||||
Reference in New Issue
Block a user