Added BlazorAppRadzenGoogleMaps
This commit is contained in:
25
src/BlazorAppRadzenGoogleMaps/BlazorAppRadzenGoogleMaps.sln
Normal file
25
src/BlazorAppRadzenGoogleMaps/BlazorAppRadzenGoogleMaps.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.34928.147
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorAppRadzenGoogleMaps", "BlazorAppRadzenGoogleMaps\BlazorAppRadzenGoogleMaps.csproj", "{DB165D3E-AA09-41CA-BE81-442FB34DBEC9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DB165D3E-AA09-41CA-BE81-442FB34DBEC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB165D3E-AA09-41CA-BE81-442FB34DBEC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB165D3E-AA09-41CA-BE81-442FB34DBEC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB165D3E-AA09-41CA-BE81-442FB34DBEC9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {601C8290-6BDC-456B-9665-AE57581D4875}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Radzen.Blazor" Version="4.31.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="/" />
|
||||
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
|
||||
|
||||
<link rel="stylesheet" href="_content/Radzen.Blazor/css/standard-base.css">
|
||||
|
||||
@* <link rel="stylesheet" href="app.css" /> *@
|
||||
@* <link rel="stylesheet" href="BlazorAppRadzenBLOGTEMPLATE.styles.css" /> *@
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png" />
|
||||
<HeadOutlet @rendermode="InteractiveServer" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<Routes @rendermode="InteractiveServer" />
|
||||
|
||||
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,65 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject DialogService DialogService
|
||||
@inject ContextMenuService ContextMenuService
|
||||
@inject TooltipService TooltipService
|
||||
@inject NotificationService NotificationService
|
||||
|
||||
<RadzenDialog />
|
||||
<RadzenNotification />
|
||||
<RadzenTooltip />
|
||||
<RadzenContextMenu />
|
||||
|
||||
|
||||
@* <RadzenComponents /> *@
|
||||
|
||||
|
||||
|
||||
<RadzenLayout style="grid-template-areas: 'rz-sidebar rz-header' 'rz-sidebar rz-body';">
|
||||
<RadzenHeader>
|
||||
<RadzenRow JustifyContent="JustifyContent.Start" AlignItems="AlignItems.Center" Gap="0">
|
||||
<RadzenColumn Size="5">
|
||||
<RadzenSidebarToggle Click="@SidebarToggleClick"></RadzenSidebarToggle>
|
||||
</RadzenColumn>
|
||||
<RadzenColumn Size="7">
|
||||
<RadzenStack AlignItems="AlignItems.Center" Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End"></RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
</RadzenHeader>
|
||||
<RadzenBody Expanded="@sidebarExpanded">
|
||||
<RadzenRow class="rz-mx-auto rz-px-4 rz-pt-2 rz-pt-md-4 rz-pt-lg-6 rz-pt-xl-12 rz-pb-2 rz-pb-lg-12" Style="max-width: 1440px;">
|
||||
<RadzenColumn Size="12">
|
||||
@Body
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
</RadzenBody>
|
||||
<RadzenSidebar Expanded="@sidebarExpanded" style="z-index: 2">
|
||||
<RadzenStack AlignItems="Radzen.AlignItems.Center" class="rz-py-4 rz-py-lg-6" Style="padding: var(--rz-panel-menu-item-padding); border-bottom: var(--rz-panel-menu-item-border);">
|
||||
|
||||
@* <RadzenImage Path="images/logo.png" style="width: 48px; height: 48px;"></RadzenImage>
|
||||
*@
|
||||
<RadzenText Text="appname" TextStyle="Radzen.Blazor.TextStyle.Subtitle1" class="rz-mb-0" style="color: var(--rz-sidebar-color);" />
|
||||
</RadzenStack>
|
||||
|
||||
<NavMenu />
|
||||
|
||||
<RadzenStack AlignItems="Radzen.AlignItems.Center" Gap="0" class="rz-py-4 rz-py-lg-6" Style="padding: var(--rz-panel-menu-item-padding);">
|
||||
<RadzenText Text="appname v1.0.0" TextStyle="Radzen.Blazor.TextStyle.Caption" style="color: var(--rz-text-disabled-color);" TagName="Radzen.Blazor.TagName.P" TextAlign="Radzen.TextAlign.Center" />
|
||||
<RadzenText Text="Copyright Ⓒ 2024" TextStyle="Radzen.Blazor.TextStyle.Caption" class="rz-mb-0" style="color: var(--rz-text-disabled-color);" TagName="Radzen.Blazor.TagName.P" TextAlign="Radzen.TextAlign.Center" />
|
||||
</RadzenStack>
|
||||
|
||||
</RadzenSidebar>
|
||||
</RadzenLayout>
|
||||
|
||||
|
||||
@code {
|
||||
bool sidebarExpanded = true;
|
||||
|
||||
void SidebarToggleClick()
|
||||
{
|
||||
sidebarExpanded = !sidebarExpanded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
<RadzenPanelMenu>
|
||||
|
||||
<RadzenPanelMenuItem Text="Home" Path="/" />
|
||||
<RadzenPanelMenuItem Text="Posts" Path="/BlogPost" />
|
||||
<RadzenPanelMenuItem Text="GoogleMap" Path="/GoogleMap" />
|
||||
|
||||
</RadzenPanelMenu>
|
||||
@@ -0,0 +1,77 @@
|
||||
@page "/BlogPost/Create"
|
||||
|
||||
<RadzenText Text="Create" TextStyle="TextStyle.H5" />
|
||||
|
||||
@if (blogPostViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="New Post">
|
||||
<RadzenStack Gap="2rem">
|
||||
<EditForm Context="editFormNewPost" Model="@blogPostViewModel" OnValidSubmit="HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="title" class="form-control" placeholder="Title"
|
||||
@bind-Value="blogPostViewModel.Title" />
|
||||
<ValidationMessage For="@(() => blogPostViewModel.Title)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Content" for="content" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="content" class="form-control" placeholder="Content"
|
||||
@bind-Value="blogPostViewModel.Content" />
|
||||
<ValidationMessage For="@(() => blogPostViewModel.Content)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenButton Text="Save" Icon="save"
|
||||
ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" />
|
||||
|
||||
</EditForm>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoBlogPostIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
private BlogPostViewModel? blogPostViewModel;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
blogPostViewModel = new();
|
||||
}
|
||||
|
||||
protected async Task HandleValidSubmit()
|
||||
{
|
||||
if (blogPostViewModel == null) return;
|
||||
|
||||
var blogPost = Mapper.Map<BlogPostViewModel, BlogPost>(blogPostViewModel);
|
||||
bool result = await BlogPostService.AddBlogPostAsync(blogPost);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost/");
|
||||
|
||||
}
|
||||
|
||||
private void NavigatetoBlogPostIndex() => NavigationManager.NavigateTo("/BlogPost");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
@page "/BlogPost/Delete/{id:int}"
|
||||
|
||||
<h3>Delete</h3>
|
||||
|
||||
@if (blogPostViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="Post Delete">
|
||||
<RadzenStack>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Id" for="id" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="id" class="form-control" placeholder="Id" ReadOnly=true
|
||||
Value="@blogPostViewModel.Id.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="title" class="form-control" placeholder="Title" ReadOnly=true
|
||||
Value="@blogPostViewModel.Title" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="REMOVE" Icon="delete_forever" ButtonStyle="ButtonStyle.Danger"
|
||||
Click="RemoveButtonClick" />
|
||||
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoBlogPostIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
BlogPostViewModel? blogPostViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPostViewModel == null)
|
||||
{
|
||||
var blogPost = await BlogPostService.GetbyId(id);
|
||||
if (blogPost == null)
|
||||
return;
|
||||
|
||||
blogPostViewModel = Mapper.Map<BlogPost, BlogPostViewModel>(blogPost);
|
||||
}
|
||||
}
|
||||
|
||||
private async void RemoveButtonClick()
|
||||
{
|
||||
bool result = await BlogPostService.DeletebyIdAsync(id);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost");
|
||||
}
|
||||
|
||||
private void NavigatetoBlogPostIndex() => NavigationManager.NavigateTo("/BlogPost");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
@page "/BlogPost/Detail/{id:int}"
|
||||
|
||||
<h3>Detail</h3>
|
||||
|
||||
@if (blogPostViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="Post Detail">
|
||||
<RadzenStack>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Id" for="id" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="id" class="form-control" placeholder="Id" ReadOnly=true
|
||||
Value="@blogPostViewModel.Id.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="title" class="form-control" placeholder="Title" ReadOnly=true
|
||||
Value="@blogPostViewModel.Title" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Content" for="content" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="content" class="form-control" placeholder="Content" ReadOnly=true
|
||||
Value="@blogPostViewModel.Content" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoBlogPostIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
BlogPostViewModel? blogPostViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPostViewModel == null)
|
||||
{
|
||||
var blogPost = await BlogPostService.GetbyId(id);
|
||||
if (blogPost == null)
|
||||
return;
|
||||
|
||||
blogPostViewModel = Mapper.Map<BlogPost, BlogPostViewModel>(blogPost);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void NavigatetoBlogPostIndex() => NavigationManager.NavigateTo("/BlogPost");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
@page "/BlogPost/Edit/{id:int}"
|
||||
|
||||
<h3>Edit</h3>
|
||||
|
||||
@if (blogPostViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="Edit Post">
|
||||
<RadzenStack Gap="2rem">
|
||||
<EditForm Context="editFormEdit" Model="@blogPostViewModel" OnValidSubmit="HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="title" class="form-control" placeholder="Title"
|
||||
@bind-Value="blogPostViewModel.Title" />
|
||||
<ValidationMessage For="@(() => blogPostViewModel.Title)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Content" for="content" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="content" class="form-control" placeholder="Content"
|
||||
@bind-Value="blogPostViewModel.Content" />
|
||||
<ValidationMessage For="@(() => blogPostViewModel.Content)" />
|
||||
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenButton Text="Save" Icon="save"
|
||||
ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" />
|
||||
|
||||
</EditForm>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoBlogPostIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
BlogPostViewModel? blogPostViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (blogPostViewModel == null)
|
||||
{
|
||||
var blogPost = await BlogPostService.GetbyId(id);
|
||||
if (blogPost == null)
|
||||
return;
|
||||
|
||||
blogPostViewModel = Mapper.Map<BlogPost, BlogPostViewModel>(blogPost);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnPaste(HtmlEditorPasteEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
void OnChange(string html)
|
||||
{
|
||||
}
|
||||
|
||||
void OnInput(string html)
|
||||
{
|
||||
}
|
||||
|
||||
void OnExecute(HtmlEditorExecuteEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
protected async Task HandleValidSubmit()
|
||||
{
|
||||
if (blogPostViewModel == null) return;
|
||||
|
||||
var blogPost = Mapper.Map<BlogPostViewModel, BlogPost>(blogPostViewModel);
|
||||
bool result = await BlogPostService.UpdateBlogPostAsync(id, blogPost);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/BlogPost/");
|
||||
}
|
||||
|
||||
private void NavigatetoBlogPostIndex() => NavigationManager.NavigateTo("/BlogPost");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
@page "/BlogPost"
|
||||
|
||||
<PageTitle>Posts</PageTitle>
|
||||
|
||||
<RadzenRow>
|
||||
|
||||
<RadzenColumn SizeSM="12" SizeMD="12" SizeLG="4">
|
||||
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
|
||||
<RadzenText Text="Posts" TextStyle="TextStyle.H5" />
|
||||
<RadzenButton Text="Create" Icon="add_circle_outline"
|
||||
Click="NavigatetoCreate"
|
||||
ButtonStyle="ButtonStyle.Success" class="rz-mb-2 rz-p-2" />
|
||||
</RadzenStack>
|
||||
|
||||
</RadzenColumn>
|
||||
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenDataGrid KeyProperty="Id" IsLoading="@isLoading" ShowPagingSummary=true
|
||||
Count="@totalCount" Data="@blogPosts" LoadData="@LoadData"
|
||||
FilterPopupRenderMode="PopupRenderMode.OnDemand"
|
||||
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
|
||||
FilterMode="FilterMode.Advanced" AllowSorting="true" AllowFiltering="true"
|
||||
AllowPaging="true" PageSize="@itemPageSize" PagerHorizontalAlign="HorizontalAlign.Center"
|
||||
TItem="BlogPostViewModel" ColumnWidth="200px">
|
||||
<Columns>
|
||||
<RadzenDataGridColumn TItem="BlogPostViewModel" Property="Id" Filterable="false" Title="Id" Frozen="true" Width="30px" MinWidth="30px" TextAlign="TextAlign.Center" />
|
||||
|
||||
<RadzenDataGridColumn TItem="BlogPostViewModel" Property="Title" Title="Title" />
|
||||
<RadzenDataGridColumn TItem="BlogPostViewModel" Property="Content" Title="Content" />
|
||||
|
||||
<RadzenDataGridColumn TItem="BlogPostViewModel" Context="blogPost" Filterable="false" Sortable="false" Width="150px" TextAlign="TextAlign.Center">
|
||||
<Template Context="blogPost">
|
||||
|
||||
<RadzenRow JustifyContent="JustifyContent.Center">
|
||||
<RadzenButton Icon="pageview" ButtonStyle="ButtonStyle.Info" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoDetail(blogPost.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
<RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Warning" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoEdit(blogPost.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
<RadzenButton Icon="delete_forever" ButtonStyle="ButtonStyle.Danger" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoDelete(blogPost.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
</RadzenRow>
|
||||
|
||||
</Template>
|
||||
</RadzenDataGridColumn>
|
||||
</Columns>
|
||||
</RadzenDataGrid>
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
const int itemPageSize = 10;
|
||||
private bool isLoading;
|
||||
private int totalCount;
|
||||
private IEnumerable<BlogPostViewModel>? blogPosts;
|
||||
|
||||
private async Task LoadData(LoadDataArgs args)
|
||||
{
|
||||
isLoading = true;
|
||||
|
||||
var result = await BlogPostService.GetBlogPostsAsync(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);
|
||||
|
||||
blogPosts = Mapper.Map<IEnumerable<BlogPost>, IEnumerable<BlogPostViewModel>>(result.Result);
|
||||
totalCount = result.TotalCount;
|
||||
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private void NavigatetoCreate() => NavigationManager.NavigateTo("/BlogPost/Create");
|
||||
private void NavigatetoDetail(int id) => NavigationManager.NavigateTo($"/BlogPost/Detail/{id}");
|
||||
private void NavigatetoEdit(int id) => NavigationManager.NavigateTo($"/BlogPost/Edit/{id}");
|
||||
private void NavigatetoDelete(int id) => NavigationManager.NavigateTo($"/BlogPost/Delete/{id}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@using BlazorAppRadzenGoogleMaps.Data;
|
||||
@using BlazorAppRadzenGoogleMaps.Models;
|
||||
@using BlazorAppRadzenGoogleMaps.Services;
|
||||
@using BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject BlogPostService BlogPostService
|
||||
@@ -0,0 +1,36 @@
|
||||
@page "/Error"
|
||||
@using System.Diagnostics
|
||||
|
||||
<PageTitle>Error</PageTitle>
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
|
||||
@code{
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private string? RequestId { get; set; }
|
||||
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
protected override void OnInitialized() =>
|
||||
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
@page "/GoogleMap/Create"
|
||||
|
||||
<RadzenText Text="Create" TextStyle="TextStyle.H5" />
|
||||
|
||||
@if (mapMarkerViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="New MapMarker">
|
||||
<RadzenStack Gap="2rem">
|
||||
<EditForm Context="editFormNewMapMarker" Model="@mapMarkerViewModel" OnValidSubmit="HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="title" class="form-control" placeholder="Title"
|
||||
@bind-Value="mapMarkerViewModel.Title" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Title)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lat" for="lat" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputNumber id="lat" class="form-control" placeholder="Lat"
|
||||
@bind-Value="mapMarkerViewModel.Lat" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Lat)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lng" for="lng" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputNumber id="lng" class="form-control" placeholder="Lng"
|
||||
@bind-Value="mapMarkerViewModel.Lng" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Lng)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenButton Text="Save" Icon="save"
|
||||
ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" />
|
||||
|
||||
</EditForm>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoGoogleMapIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
private MapMarkerViewModel? mapMarkerViewModel;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
mapMarkerViewModel = new();
|
||||
}
|
||||
|
||||
protected async Task HandleValidSubmit()
|
||||
{
|
||||
if (mapMarkerViewModel == null) return;
|
||||
|
||||
var mapMarker = Mapper.Map<MapMarkerViewModel, MapMarker>(mapMarkerViewModel);
|
||||
bool result = await MapMarkerService.AddMapMarkerAsync(mapMarker);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/GoogleMap/");
|
||||
|
||||
}
|
||||
|
||||
private void NavigatetoGoogleMapIndex() => NavigationManager.NavigateTo("/GoogleMap");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
@page "/GoogleMap/Delete/{id:int}"
|
||||
|
||||
<h3>Delete</h3>
|
||||
|
||||
@if (mapMarkerViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="MapMarker Delete">
|
||||
<RadzenStack>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Id" for="id" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="id" class="form-control" placeholder="Id" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Id.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="title" class="form-control" placeholder="Title" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Title" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="REMOVE" Icon="delete_forever" ButtonStyle="ButtonStyle.Danger"
|
||||
Click="RemoveButtonClick" />
|
||||
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoGoogleMapIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private MapMarkerViewModel? mapMarkerViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (mapMarkerViewModel == null)
|
||||
{
|
||||
var mapMarker = await MapMarkerService.GetbyId(id);
|
||||
if (mapMarker == null)
|
||||
return;
|
||||
|
||||
mapMarkerViewModel = Mapper.Map<MapMarker, MapMarkerViewModel>(mapMarker);
|
||||
}
|
||||
}
|
||||
|
||||
private async void RemoveButtonClick()
|
||||
{
|
||||
bool result = await MapMarkerService.DeletebyIdAsync(id);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/GoogleMap");
|
||||
}
|
||||
|
||||
private void NavigatetoGoogleMapIndex() => NavigationManager.NavigateTo("/GoogleMap");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
@page "/GoogleMap/Detail/{id:int}"
|
||||
|
||||
<h3>Detail</h3>
|
||||
|
||||
@if (mapMarkerViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="MapMarker Detail">
|
||||
<RadzenStack>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Id" for="id" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="id" class="form-control" placeholder="Id" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Id.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="title" class="form-control" placeholder="Title" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Title" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lat" for="lat" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="lat" class="form-control" placeholder="Lat" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Lat.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lng" for="lng" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<RadzenTextBox id="lng" class="form-control" placeholder="Lng" ReadOnly=true
|
||||
Value="@mapMarkerViewModel.Lng.ToString()" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoGoogleMapIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private MapMarkerViewModel? mapMarkerViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (mapMarkerViewModel == null)
|
||||
{
|
||||
var mapMarker = await MapMarkerService.GetbyId(id);
|
||||
if (mapMarker == null)
|
||||
return;
|
||||
|
||||
mapMarkerViewModel = Mapper.Map<MapMarker, MapMarkerViewModel>(mapMarker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void NavigatetoGoogleMapIndex() => NavigationManager.NavigateTo("/GoogleMap");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
@page "/GoogleMap/Edit/{id:int}"
|
||||
|
||||
<h3>Edit</h3>
|
||||
|
||||
@if (mapMarkerViewModel == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<RadzenStack>
|
||||
<RadzenFieldset Text="Edit MapMarker">
|
||||
<RadzenStack Gap="2rem">
|
||||
<EditForm Context="editFormEdit" Model="@mapMarkerViewModel" OnValidSubmit="HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Title" for="title" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputText id="title" class="form-control" placeholder="Title"
|
||||
@bind-Value="mapMarkerViewModel.Title" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Title)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lat" for="lat" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputNumber id="lat" class="form-control" placeholder="Lat"
|
||||
@bind-Value="mapMarkerViewModel.Lat" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Lat)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow AlignItems="AlignItems.Center" Class="rz-mb-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="2" SizeLG="2">
|
||||
<RadzenLabel Text="Lng" for="lng" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn SizeSM="12" SizeMD="10" SizeLG="10">
|
||||
<InputNumber id="lng" class="form-control" placeholder="Lng"
|
||||
@bind-Value="mapMarkerViewModel.Lng" />
|
||||
<ValidationMessage For="@(() => mapMarkerViewModel.Lng)" />
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenButton Text="Save" Icon="save"
|
||||
ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" />
|
||||
|
||||
</EditForm>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenFieldset>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Back" Icon="arrow_back" Class="rz-mt-2"
|
||||
Click="NavigatetoGoogleMapIndex"
|
||||
ButtonStyle="ButtonStyle.Primary" />
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public int id { get; set; }
|
||||
|
||||
private MapMarkerViewModel? mapMarkerViewModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (mapMarkerViewModel == null)
|
||||
{
|
||||
var mapMarker = await MapMarkerService.GetbyId(id);
|
||||
if (mapMarker == null)
|
||||
return;
|
||||
|
||||
mapMarkerViewModel = Mapper.Map<MapMarker, MapMarkerViewModel>(mapMarker);
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task HandleValidSubmit()
|
||||
{
|
||||
if (mapMarkerViewModel == null) return;
|
||||
|
||||
var mapMarker = Mapper.Map<MapMarkerViewModel, MapMarker>(mapMarkerViewModel);
|
||||
bool result = await MapMarkerService.UpdateMapMarkerAsync(id, mapMarker);
|
||||
if (result)
|
||||
NavigationManager.NavigateTo("/GoogleMap/");
|
||||
}
|
||||
|
||||
private void NavigatetoGoogleMapIndex() => NavigationManager.NavigateTo("/GoogleMap");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
@page "/GoogleMap"
|
||||
|
||||
@inject Microsoft.JSInterop.IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>GoogleMap</PageTitle>
|
||||
|
||||
<RadzenRow>
|
||||
<RadzenColumn SizeSM="12" SizeMD="12" SizeLG="12">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
|
||||
<RadzenText Text="GoogleMap" TextStyle="TextStyle.H5" />
|
||||
</RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenRow class="rz-mb-2 rz-p-2">
|
||||
<RadzenColumn SizeSM="12" SizeMD="12" SizeLG="12">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
|
||||
|
||||
<RadzenGoogleMap @ref=map ApiKey=@YOUR_GOOGLE_MAP_API_KEY style="height: 400px; width: 100%;"
|
||||
Options=@(new Dictionary<string, object> { { "disableDoubleClickZoom", true } })
|
||||
Zoom=@zoom Center=@mapCenter
|
||||
MapClick=@OnMapClick MarkerClick=@OnMarkerClick
|
||||
Data="radzenGoogleMapMarkers">
|
||||
</RadzenGoogleMap>
|
||||
|
||||
</RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
|
||||
<RadzenRow>
|
||||
<RadzenColumn SizeSM="12" SizeMD="12" SizeLG="4">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
|
||||
<RadzenText Text="MapMarkers" TextStyle="TextStyle.H5" />
|
||||
<RadzenButton Text="Create" Icon="add_circle_outline"
|
||||
Click="NavigatetoCreate"
|
||||
ButtonStyle="ButtonStyle.Success" class="rz-mb-2 rz-p-2" />
|
||||
</RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
<RadzenDataGrid KeyProperty="Id" IsLoading="@isLoading" ShowPagingSummary=true
|
||||
Count="@totalCount" Data="@mapMarkers" LoadData="@LoadData"
|
||||
FilterPopupRenderMode="PopupRenderMode.OnDemand"
|
||||
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
|
||||
FilterMode="FilterMode.Advanced" AllowSorting="true" AllowFiltering="true"
|
||||
AllowPaging="true" PageSize="@itemPageSize" PagerHorizontalAlign="HorizontalAlign.Center"
|
||||
TItem="MapMarkerViewModel" ColumnWidth="200px">
|
||||
<Columns>
|
||||
<RadzenDataGridColumn TItem="MapMarkerViewModel" Property="Id" Filterable="false" Title="Id" Frozen="true" Width="30px" MinWidth="30px" TextAlign="TextAlign.Center" />
|
||||
|
||||
<RadzenDataGridColumn TItem="MapMarkerViewModel" Property="Title" Title="Title" />
|
||||
<RadzenDataGridColumn TItem="MapMarkerViewModel" Property="Lat" Title="Lat" />
|
||||
<RadzenDataGridColumn TItem="MapMarkerViewModel" Property="Lng" Title="Lng" />
|
||||
|
||||
<RadzenDataGridColumn TItem="MapMarkerViewModel" Context="mapMarker" Filterable="false" Sortable="false" Width="150px" TextAlign="TextAlign.Center">
|
||||
<Template Context="mapMarker">
|
||||
|
||||
<RadzenRow JustifyContent="JustifyContent.Center">
|
||||
<RadzenButton Icon="pageview" ButtonStyle="ButtonStyle.Info" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoDetail(mapMarker.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
<RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Warning" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoEdit(mapMarker.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
<RadzenButton Icon="delete_forever" ButtonStyle="ButtonStyle.Danger" Variant="Variant.Flat" Size="ButtonSize.Medium"
|
||||
Click="@(args => NavigatetoDelete(mapMarker.Id))" @onclick:stopPropagation="true">
|
||||
</RadzenButton>
|
||||
</RadzenRow>
|
||||
|
||||
</Template>
|
||||
</RadzenDataGridColumn>
|
||||
</Columns>
|
||||
</RadzenDataGrid>
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
const int itemPageSize = 10;
|
||||
private bool isLoading;
|
||||
private int totalCount;
|
||||
private IEnumerable<MapMarkerViewModel>? mapMarkers;
|
||||
|
||||
private RadzenGoogleMap map;
|
||||
private string YOUR_GOOGLE_MAP_API_KEY = "";
|
||||
private int zoom = 3;
|
||||
private GoogleMapPosition mapCenter = new GoogleMapPosition() { Lat = 39.931348444036296, Lng = 32.86293982331063 };
|
||||
private IEnumerable<RadzenGoogleMapMarker>? radzenGoogleMapMarkers;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
isLoading = true;
|
||||
|
||||
var result = await MapMarkerService.GetMapMarkersAsync();
|
||||
|
||||
mapMarkers = Mapper.Map<IEnumerable<MapMarker>, IEnumerable<MapMarkerViewModel>>(result.Result);
|
||||
totalCount = result.TotalCount;
|
||||
|
||||
List<RadzenGoogleMapMarker> gMapMarkers = new();
|
||||
foreach (var mapMarker in mapMarkers)
|
||||
gMapMarkers.Add(new() { Title = mapMarker.Title, Label = mapMarker.Title, Position = new() { Lat = mapMarker.Lat, Lng = mapMarker.Lng } });
|
||||
radzenGoogleMapMarkers = gMapMarkers;
|
||||
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task LoadData(LoadDataArgs args)
|
||||
{
|
||||
isLoading = true;
|
||||
|
||||
var result = await MapMarkerService.GetMapMarkersAsync(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);
|
||||
|
||||
mapMarkers = Mapper.Map<IEnumerable<MapMarker>, IEnumerable<MapMarkerViewModel>>(result.Result);
|
||||
totalCount = result.TotalCount;
|
||||
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private void NavigatetoCreate() => NavigationManager.NavigateTo("/GoogleMap/Create");
|
||||
private void NavigatetoDetail(int id) => NavigationManager.NavigateTo($"/GoogleMap/Detail/{id}");
|
||||
private void NavigatetoEdit(int id) => NavigationManager.NavigateTo($"/GoogleMap/Edit/{id}");
|
||||
private void NavigatetoDelete(int id) => NavigationManager.NavigateTo($"/GoogleMap/Delete/{id}");
|
||||
|
||||
void OnMapClick(GoogleMapClickEventArgs args) { }
|
||||
|
||||
async Task OnMarkerClick(RadzenGoogleMapMarker marker)
|
||||
{
|
||||
var message = $"Custom information about <b>{marker.Title}</b>";
|
||||
|
||||
var code = $@"
|
||||
var map = Radzen['{map.UniqueID}'].instance;
|
||||
var marker = map.markers.find(m => m.title == '{marker.Title}');
|
||||
if(window.infoWindow) {{window.infoWindow.close();}}
|
||||
window.infoWindow = new google.maps.InfoWindow({{content: '{message}'}});
|
||||
setTimeout(() => window.infoWindow.open(map, marker), 200);
|
||||
";
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("eval", code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@using BlazorAppRadzenGoogleMaps.Data;
|
||||
@using BlazorAppRadzenGoogleMaps.Models;
|
||||
@using BlazorAppRadzenGoogleMaps.Services;
|
||||
@using BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject MapMarkerService MapMarkerService
|
||||
@@ -0,0 +1,7 @@
|
||||
@page "/"
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
@@ -0,0 +1,6 @@
|
||||
<Router AppAssembly="typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
||||
@* <FocusOnNavigate RouteData="routeData" Selector="h1" /> *@
|
||||
</Found>
|
||||
</Router>
|
||||
@@ -0,0 +1,16 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.JSInterop
|
||||
@using BlazorAppRadzenGoogleMaps
|
||||
@using BlazorAppRadzenGoogleMaps.Components
|
||||
|
||||
@using MapsterMapper
|
||||
@using Radzen
|
||||
@using Radzen.Blazor
|
||||
|
||||
@inject IMapper Mapper
|
||||
@@ -0,0 +1,20 @@
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.Data;
|
||||
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<BlogPost> BlogPosts => Set<BlogPost>();
|
||||
public DbSet<MapMarker> MapMarkers => Set<MapMarker>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.Data;
|
||||
|
||||
public class SeedData
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public SeedData(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task CreateInitialData()
|
||||
{
|
||||
var posts = GetAllBlogPosts();
|
||||
await _context.BlogPosts.AddRangeAsync(posts);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var mapMarkers = GetAllMapMarkers();
|
||||
await _context.MapMarkers.AddRangeAsync(mapMarkers);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerable<MapMarker> GetAllMapMarkers()
|
||||
{
|
||||
List<MapMarker> mapMarkers = new() {
|
||||
new(){ Id = 1, Title = "Ankara", Lat = 39.931348444036296, Lng = 32.86293982331063 },
|
||||
new(){ Id = 2, Title = "London", Lat = 51.5074, Lng = 0.1278 },
|
||||
new(){ Id = 3, Title = "Paris", Lat = 48.8566, Lng = 2.3522 },
|
||||
new(){ Id = 4, Title = "Madrid", Lat = 40.4168, Lng = -3.7038 },
|
||||
};
|
||||
return mapMarkers;
|
||||
}
|
||||
|
||||
private static IEnumerable<BlogPost> GetAllBlogPosts()
|
||||
{
|
||||
List<BlogPost> posts = new();
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
BlogPost post = new() { Id = i + 1, Title = titles[i], Content = contents[i % 10] };
|
||||
posts.Add(post);
|
||||
}
|
||||
|
||||
return posts;
|
||||
}
|
||||
|
||||
private static readonly string[] titles = {
|
||||
"Introduction to Object-Oriented Programming",
|
||||
"Mastering Data Structures and Algorithms",
|
||||
"Building Web Applications with ASP.NET",
|
||||
"Creating Mobile Apps with Xamarin",
|
||||
"Exploring Artificial Intelligence and Machine Learning",
|
||||
"Understanding Functional Programming Concepts",
|
||||
"Developing Games with Unity",
|
||||
"Securing Web Applications from Cyber Attacks",
|
||||
"Optimizing Code Performance for Better Efficiency",
|
||||
"Implementing Design Patterns in Software Development",
|
||||
"Testing and Debugging Strategies for Reliable Software",
|
||||
"Working with Databases and SQL",
|
||||
"Building Responsive User Interfaces with HTML and CSS",
|
||||
"Exploring Cloud Computing and Serverless Architecture",
|
||||
"Developing Cross-Platform Applications with React Native",
|
||||
"Introduction to Internet of Things (IoT)",
|
||||
"Creating Scalable Microservices with Docker and Kubernetes",
|
||||
"Understanding Network Protocols and TCP/IP",
|
||||
"Building RESTful APIs with Node.js and Express",
|
||||
"Exploring Big Data Analytics and Apache Hadoop",
|
||||
"Mastering Version Control with Git and GitHub",
|
||||
"Developing Desktop Applications with WPF",
|
||||
"Securing Mobile Applications from Malicious Attacks",
|
||||
"Optimizing Database Performance with Indexing",
|
||||
"Implementing Continuous Integration and Deployment",
|
||||
"Testing Mobile Apps on Different Platforms",
|
||||
"Working with NoSQL Databases like MongoDB",
|
||||
"Building Progressive Web Apps with React",
|
||||
"Exploring Quantum Computing and Quantum Algorithms",
|
||||
"Introduction to Cybersecurity and Ethical Hacking",
|
||||
"Creating Chatbots with Natural Language Processing",
|
||||
"Understanding Software Development Life Cycle",
|
||||
"Developing Augmented Reality (AR) Applications",
|
||||
"Securing Web APIs with OAuth and JWT",
|
||||
"Optimizing Front-End Performance for Better User Experience",
|
||||
"Implementing Machine Learning Models with TensorFlow",
|
||||
"Testing Web Applications for Cross-Browser Compatibility",
|
||||
"Working with Blockchain Technology and Smart Contracts",
|
||||
"Building Real-Time Applications with SignalR",
|
||||
"Exploring Cryptography and Encryption Techniques",
|
||||
"Introduction to Agile Software Development",
|
||||
"Creating Voice User Interfaces with Amazon Alexa",
|
||||
"Understanding Web Accessibility and Inclusive Design",
|
||||
"Developing Natural Language Processing Applications",
|
||||
"Securing Cloud Infrastructure and Services",
|
||||
"Optimizing Backend Performance for Scalability",
|
||||
"Implementing Continuous Monitoring and Alerting",
|
||||
"Testing APIs with Postman and Swagger",
|
||||
"Working with Data Visualization Libraries like D3.js",
|
||||
"Building E-commerce Applications with Shopify",
|
||||
"Exploring Robotic Process Automation (RPA)",
|
||||
"Introduction to DevOps and CI/CD Pipelines"
|
||||
};
|
||||
|
||||
private static readonly string[] contents = new string[]
|
||||
{
|
||||
"Lorem ipsum dolor sit amet, consectetur t.",
|
||||
"Sed ut perspiciatis unde omnis iste natuccusantium doloremque laudantium.",
|
||||
"Nemo enim ipsam voluptatem quia voluptas aut fugit.",
|
||||
"Quis autem vel eum iure reprehenderit quesse quam nihil molestiae consequatur.",
|
||||
"At vero eos et accusamus et iusto odio d.",
|
||||
"Similique sunt in culpa qui officia de.",
|
||||
"Et harum quidem rerum facilis est et expio.",
|
||||
"Nam libero tempore, cum soluta nobis est.",
|
||||
"Omnis voluptas assumenda est, omnis dolo",
|
||||
"Temporibus autem quibusdam et aut offic"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace BlazorAppRadzenGoogleMaps.Models;
|
||||
|
||||
public class BlogPost
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace BlazorAppRadzenGoogleMaps.Models;
|
||||
|
||||
public class MapMarker
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public double Lat { get; set; }
|
||||
public double Lng { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using BlazorAppRadzenGoogleMaps.Components;
|
||||
using BlazorAppRadzenGoogleMaps.Data;
|
||||
using BlazorAppRadzenGoogleMaps.Services;
|
||||
using BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Radzen;
|
||||
using System.Reflection;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseInMemoryDatabase("ConnectionInMemory")
|
||||
);
|
||||
builder.Services.AddScoped<SeedData>();
|
||||
builder.Services.AddScoped<BlogPostService>();
|
||||
builder.Services.AddScoped<MapMarkerService>();
|
||||
|
||||
// Radzen Services
|
||||
builder.Services.AddScoped<DialogService>();
|
||||
builder.Services.AddScoped<NotificationService>();
|
||||
builder.Services.AddScoped<TooltipService>();
|
||||
builder.Services.AddScoped<ContextMenuService>();
|
||||
|
||||
// Add mapster mapper
|
||||
builder.Services.AddMapster();
|
||||
|
||||
builder.Services.CreateDatabase().GetAwaiter().GetResult();
|
||||
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseAntiforgery();
|
||||
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static async Task CreateDatabase(this IServiceCollection services)
|
||||
{
|
||||
using (IServiceScope tmp = services.BuildServiceProvider().CreateScope())
|
||||
{
|
||||
await using var _context = tmp.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
var seedData = tmp.ServiceProvider.GetRequiredService<SeedData>();
|
||||
await seedData.CreateInitialData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapsterConfiguration
|
||||
{
|
||||
public static void AddMapster(this IServiceCollection services)
|
||||
{
|
||||
var typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
Assembly applicationAssembly = typeof(BaseViewModel<,>).Assembly;
|
||||
typeAdapterConfig.Scan(applicationAssembly);
|
||||
|
||||
var mapperConfig = new Mapper(typeAdapterConfig);
|
||||
services.AddSingleton<IMapper>(mapperConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using BlazorAppRadzenGoogleMaps.Data;
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Radzen;
|
||||
using System.Linq.Dynamic.Core;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.Services;
|
||||
|
||||
public class BlogPostService
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public BlogPostService(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task<BlogPost?> GetbyId(int id)
|
||||
{
|
||||
return _context.BlogPosts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<BlogPost> Result, int TotalCount)> GetBlogPostsAsync(string? filter = default, int? top = default, int? skip = default, string? orderby = default, string? expand = default, string? select = default, bool? count = default)
|
||||
{
|
||||
var query = _context.BlogPosts.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
query = query.Where(filter);
|
||||
|
||||
if (!string.IsNullOrEmpty(orderby))
|
||||
query = query.OrderBy(orderby);
|
||||
|
||||
int totalCount = 0;
|
||||
if (count == true)
|
||||
totalCount = query.Count();
|
||||
|
||||
IEnumerable<BlogPost>? result;
|
||||
if (skip == null || top == null)
|
||||
result = await query.ToListAsync();
|
||||
else
|
||||
result = await query.Skip(skip.Value).Take(top.Value).ToListAsync();
|
||||
|
||||
return (result, totalCount);
|
||||
}
|
||||
|
||||
public async Task<bool> AddBlogPostAsync(BlogPost blogPost)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _context.BlogPosts.AddAsync(blogPost);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateBlogPostAsync(int id, BlogPost blogPost)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oldBlogPost = _context.BlogPosts.FirstOrDefault(x => x.Id == id);
|
||||
if (oldBlogPost == null) return false;
|
||||
|
||||
oldBlogPost.Title = blogPost.Title;
|
||||
oldBlogPost.Content = blogPost.Content;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeletebyIdAsync(int id)
|
||||
{
|
||||
var blogPost = await _context.BlogPosts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (blogPost == null)
|
||||
return false;
|
||||
|
||||
_context.BlogPosts.Remove(blogPost);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using BlazorAppRadzenGoogleMaps.Data;
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Radzen;
|
||||
using System.Linq.Dynamic.Core;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.Services;
|
||||
|
||||
public class MapMarkerService
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public MapMarkerService(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public Task<MapMarker?> GetbyId(int id)
|
||||
{
|
||||
return _context.MapMarkers.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<MapMarker> Result, int TotalCount)> GetMapMarkersAsync(string? filter = default, int? top = default, int? skip = default, string? orderby = default, string? expand = default, string? select = default, bool? count = default)
|
||||
{
|
||||
var query = _context.MapMarkers.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
query = query.Where(filter);
|
||||
|
||||
if (!string.IsNullOrEmpty(orderby))
|
||||
query = query.OrderBy(orderby);
|
||||
|
||||
int totalCount = 0;
|
||||
if (count == true)
|
||||
totalCount = query.Count();
|
||||
|
||||
IEnumerable<MapMarker>? result;
|
||||
if (skip == null || top == null)
|
||||
result = await query.ToListAsync();
|
||||
else
|
||||
result = await query.Skip(skip.Value).Take(top.Value).ToListAsync();
|
||||
|
||||
return (result, totalCount);
|
||||
}
|
||||
|
||||
public async Task<bool> AddMapMarkerAsync(MapMarker mapMarker)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _context.MapMarkers.AddAsync(mapMarker);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateMapMarkerAsync(int id, MapMarker mapMarker)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oldMapMarker = _context.MapMarkers.FirstOrDefault(x => x.Id == id);
|
||||
if (oldMapMarker == null) return false;
|
||||
|
||||
oldMapMarker.Title = mapMarker.Title;
|
||||
oldMapMarker.Lat = mapMarker.Lat;
|
||||
oldMapMarker.Lng = mapMarker.Lng;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> DeletebyIdAsync(int id)
|
||||
{
|
||||
var mapMarker = await _context.MapMarkers.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (mapMarker == null)
|
||||
return false;
|
||||
|
||||
_context.MapMarkers.Remove(mapMarker);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Mapster;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Model <-> ViewModel Mapping
|
||||
/// </summary>
|
||||
/// <typeparam name="TViewModel">ViewModel</typeparam>
|
||||
/// <typeparam name="TModel">Model</typeparam>
|
||||
public abstract class BaseViewModel<TViewModel, TModel> : IRegister
|
||||
where TViewModel : class, new()
|
||||
where TModel : class, new()
|
||||
{
|
||||
|
||||
public TModel ToModel()
|
||||
{
|
||||
return this.Adapt<TModel>();
|
||||
}
|
||||
|
||||
public TModel ToModel(TModel model)
|
||||
{
|
||||
return (this as TViewModel).Adapt(model);
|
||||
}
|
||||
|
||||
public static TViewModel FromModel(TModel model)
|
||||
{
|
||||
return model.Adapt<TViewModel>();
|
||||
}
|
||||
|
||||
private TypeAdapterConfig Config { get; set; }
|
||||
|
||||
public virtual void AddCustomMappings() { }
|
||||
|
||||
|
||||
protected TypeAdapterSetter<TViewModel, TModel> SetCustomMappings()
|
||||
=> Config.ForType<TViewModel, TModel>();
|
||||
|
||||
protected TypeAdapterSetter<TModel, TViewModel> SetCustomMappingsInverse()
|
||||
=> Config.ForType<TModel, TViewModel>();
|
||||
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
Config = config;
|
||||
AddCustomMappings();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
|
||||
public class BlogPostViewModel : BaseViewModel<BlogPostViewModel, BlogPost>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Title can not be empty")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Content can not be empty")]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
public string TitleShort { get; set; } = string.Empty;
|
||||
public string ContentShort { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using BlazorAppRadzenGoogleMaps.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BlazorAppRadzenGoogleMaps.ViewModels;
|
||||
|
||||
public class MapMarkerViewModel : BaseViewModel<MapMarkerViewModel, MapMarker>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Title can not be empty")]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[Required(AllowEmptyStrings = false, ErrorMessage = "Title can not be empty")]
|
||||
|
||||
[Range(0, double.MaxValue, MinimumIsExclusive = true, ErrorMessage = "Lat for {0} must be between {1} and {2}.")]
|
||||
public double Lat { get; set; }
|
||||
|
||||
[Range(0, double.MaxValue, MinimumIsExclusive = true, ErrorMessage = "Lng for {0} must be between {1} and {2}.")]
|
||||
public double Lng { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
7
src/BlazorAppRadzenGoogleMaps/BlazorAppRadzenGoogleMaps/wwwroot/bootstrap/bootstrap.min.css
vendored
Normal file
7
src/BlazorAppRadzenGoogleMaps/BlazorAppRadzenGoogleMaps/wwwroot/bootstrap/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user