Contacts CRUD
parent
cfea0eb37a
commit
f9deadb7e0
@ -1,69 +0,0 @@
|
||||
@page "/contacts"
|
||||
@using Gremlin_BlazorServer.Data.DBClasses;
|
||||
@using Gremlin_BlazorServer.Models;
|
||||
@using Gremlin_BlazorServer.ViewModels;
|
||||
|
||||
<PageTitle>Contacts</PageTitle>
|
||||
|
||||
<h1>Contacts in Regulus</h1>
|
||||
|
||||
<p>Hier werden die Daten aus der MariaDB geladen und angezeigt.</p>
|
||||
|
||||
<div class="text-center bg-blue-100">
|
||||
<input class="border-4 w-1/3 rounded m-6 p-6 h-8
|
||||
border-blue-300" @bind-value="searchContact"
|
||||
@bind-value:event="oninput" placeholder="Search by LastName"
|
||||
@onchange="SearchContact_OnChange"/>
|
||||
</div>
|
||||
|
||||
@if (!filteredContacts.Any())
|
||||
{
|
||||
<p><em>No contacts found!</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p><em>@filteredContacts.Count contacts found!</em></p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ContactID</th>
|
||||
<th>AccountID</th>
|
||||
<th>FirstName</th>
|
||||
<th>LastName</th>
|
||||
<th>Gender</th>
|
||||
<th>EMail</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (ContactViewModel contact in filteredContacts)
|
||||
{
|
||||
<tr>
|
||||
<td>@contact.ContactId</td>
|
||||
<td>@contact.AccountId</td>
|
||||
<td>@contact.FirstName</td>
|
||||
<td>@contact.LastName</td>
|
||||
<td>@contact.Gender</td>
|
||||
<td>@contact.EMail</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
public string searchContact = "";
|
||||
private List<ContactViewModel> allContacts = new();
|
||||
private List<ContactViewModel> filteredContacts = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
allContacts = await ContactModel.GetContactViewModel();
|
||||
filteredContacts = allContacts;
|
||||
//allContacts = await DataAccessService.GetContactsFromDb("");
|
||||
}
|
||||
|
||||
private void SearchContact_OnChange()
|
||||
{
|
||||
filteredContacts = allContacts.Where(c => c.LastName.ToLower().Contains(searchContact.ToLower())).ToList();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
@page "/Contacts/Add"
|
||||
|
||||
@using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
@using Gremlin_BlazorServer.Services;
|
||||
|
||||
@inject ContactService contactService
|
||||
@inject NavigationManager navigationManager
|
||||
|
||||
<h2>Add Contact</h2>
|
||||
<hr />
|
||||
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="ContactId" class="control-label">ContactId</label>
|
||||
<input form="ContactId" class="form-control" @bind="@contact.ContactId" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="AccountId" class="control-label">AccountId</label>
|
||||
<input form="AccountId" class="form-control" @bind="@contact.AccountId" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="LastName" class="control-label">LastName</label>
|
||||
<input form="LastName" class="form-control" @bind="@contact.LastName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="FirstName" class="control-label">FirstName</label>
|
||||
<input form="FirstName" class="form-control" @bind="@contact.FirstName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="Gender" class="control-label">Gender</label>
|
||||
<input form="Gender" class="form-control" @bind="@contact.Gender" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="EMail" class="control-label">EMail</label>
|
||||
<input form="EMail" class="form-control" @bind="@contact.EMail" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="SAPContactNumber" class="control-label">SAPContactNumber</label>
|
||||
<input form="SAPContactNumber" class="form-control" @bind="@contact.SAPContactNumber" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<input type="button" class="btn btn-primary" @onclick="@CreateContact" value="Save"/>
|
||||
<input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
Contact contact = new Contact();
|
||||
|
||||
protected async void CreateContact()
|
||||
{
|
||||
contact.DataModificationByUser = "Gremlin_BlazorServer";
|
||||
//contact.DataStatus = "Active";
|
||||
|
||||
if (await contactService.InsertContactAsync(contact))
|
||||
{
|
||||
navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
}
|
||||
|
||||
void Cancel() => navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
@page "/Contacts/Delete/{ContactId}"
|
||||
|
||||
@using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
@using Gremlin_BlazorServer.Services;
|
||||
|
||||
@inject ContactService contactService
|
||||
@inject NavigationManager navigationManager
|
||||
|
||||
<h2>Delete Employee</h2>
|
||||
<hr />
|
||||
<h3>Are you sure want to delete this?</h3>
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class=" col-md-8">
|
||||
<div class="form-group">
|
||||
<label>ContactId:</label>
|
||||
<label>@contact.ContactId</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ContactId:</label>
|
||||
<label>@contact.ContactId</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>LastName:</label>
|
||||
<label>@contact.LastName</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>FirstName:</label>
|
||||
<label>@contact.FirstName</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Gender:</label>
|
||||
<label>@contact.Gender</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>EMail:</label>
|
||||
<label>@contact.EMail</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>SAPContactNumber:</label>
|
||||
<label>@contact.SAPContactNumber</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<input type="button" class="btn btn-danger" @onclick="@DeleteContact" value="Delete" />
|
||||
<input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string contactId { get; set; } = default!;
|
||||
Contact? contact = new Contact();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
contact = await Task.Run(() => contactService.GetContactAsync(Convert.ToUInt32(contactId)));
|
||||
}
|
||||
protected async void DeleteContact()
|
||||
{
|
||||
await contactService.DeleteContactAsync(contact);
|
||||
navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
void Cancel()
|
||||
{
|
||||
navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
@page "/Contacts/Edit/{ContactId}"
|
||||
|
||||
@using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
@using Gremlin_BlazorServer.Services;
|
||||
|
||||
@inject ContactService contactService
|
||||
@inject NavigationManager navigationManager
|
||||
|
||||
<h2>Edit Contact</h2>
|
||||
<hr />
|
||||
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="ContactId" class="control-label">ContactId</label>
|
||||
<input form="ContactId" class="form-control" @bind="@contact.ContactId" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="AccountId" class="control-label">AccountId</label>
|
||||
<input form="AccountId" class="form-control" @bind="@contact.AccountId" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="LastName" class="control-label">LastName</label>
|
||||
<input form="LastName" class="form-control" @bind="@contact.LastName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="FirstName" class="control-label">FirstName</label>
|
||||
<input form="FirstName" class="form-control" @bind="@contact.FirstName" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="Gender" class="control-label">Gender</label>
|
||||
<input form="Gender" class="form-control" @bind="@contact.Gender" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="EMail" class="control-label">EMail</label>
|
||||
<input form="EMail" class="form-control" @bind="@contact.EMail" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="SAPContactNumber" class="control-label">SAPContactNumber</label>
|
||||
<input form="SAPContactNumber" class="form-control" @bind="@contact.SAPContactNumber" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<input type="button" class="btn btn-primary" @onclick="@UpdateContact" value="Update" />
|
||||
<input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? contactId { get; set; }
|
||||
Contact? contact = new Contact();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
contact = await Task.Run(() => contactService.GetContactAsync(Convert.ToUInt32(contactId)));
|
||||
}
|
||||
|
||||
protected async void UpdateContact()
|
||||
{
|
||||
contact.DataModificationByUser = "Gremlin_BlazorServer";
|
||||
contact.DataModificationDate = DateTime.Now;
|
||||
contact.DataVersionNumber++;
|
||||
await contactService.UpdateContactAsync(contact);
|
||||
navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
|
||||
void Cancel() => navigationManager.NavigateTo("Contacts/Index");
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
@page "/Contacts/Index"
|
||||
|
||||
@using Gremlin_BlazorServer.Data.EntityClasses;
|
||||
@using Gremlin_BlazorServer.Services;
|
||||
|
||||
@inject ContactService ContactService
|
||||
|
||||
<h1>Contacts</h1>
|
||||
|
||||
<div class="text-center bg-blue-100">
|
||||
<input class="border-4 w-1/3 rounded m-6 p-6 h-8
|
||||
border-blue-300" @bind-value="searchContact"
|
||||
@bind-value:event="oninput" placeholder="Search by LastName"
|
||||
@onchange="SearchContact_OnChange"/>
|
||||
</div>
|
||||
|
||||
<NavLink class="nav-link" href="Contacts/Add">
|
||||
<span class="oi oi-plus" aria-hidden="true">Add New Contact</span>
|
||||
</NavLink>
|
||||
|
||||
|
||||
@if (allContacts is null)
|
||||
{
|
||||
<p><em>Loading... !</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Es wurden @filteredContacts.Count Contacts gefunden.</p>
|
||||
@if (allContacts != null)
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@nameof(Contact.ContactId)</th>
|
||||
<th>@nameof(Contact.AccountId)</th>
|
||||
<th>@nameof(Contact.LastName)</th>
|
||||
<th>@nameof(Contact.FirstName)</th>
|
||||
<th>@nameof(Contact.Gender)</th>
|
||||
<th>@nameof(Contact.EMail)</th>
|
||||
<th>@nameof(Contact.SAPContactNumber)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (Contact Contact in filteredContacts)
|
||||
{<tr>
|
||||
<td>@Contact.ContactId</td>
|
||||
<td>@Contact.AccountId</td>
|
||||
<td>@Contact.LastName</td>
|
||||
<td>@Contact.FirstName</td>
|
||||
<td>@Contact.Gender</td>
|
||||
<td>@Contact.EMail</td>
|
||||
<td>@Contact.SAPContactNumber</td>
|
||||
<td>
|
||||
<a class="nav-link" href="Contacts/Edit/@Contact.ContactId">
|
||||
<span class="oi oi-pencil" aria-hidden="true">Edit</span>
|
||||
</a>
|
||||
<a class="nav-link" href="Contacts/Delete/@Contact.ContactId">
|
||||
<span class="oi oi-trash" aria-hidden="true">Delete</span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
public string searchContact = "";
|
||||
List<Contact> allContacts = new();
|
||||
List<Contact> filteredContacts = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
allContacts = await Task.Run(() => ContactService.GetAllContactsAsync());
|
||||
filteredContacts = allContacts;
|
||||
}
|
||||
|
||||
private void SearchContact_OnChange()
|
||||
{
|
||||
filteredContacts = allContacts.Where(a => a.LastName.ToLower().Contains(searchContact.ToLower())).ToList();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue