mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add code to delete document companies.
This commit is contained in:
@@ -1,33 +0,0 @@
|
|||||||
@model Marechai.ViewModels.DocumentCompanyViewModel
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete";
|
|
||||||
}
|
|
||||||
<h1>Delete</h1>
|
|
||||||
<h3>Are you sure you want to delete this?</h3>
|
|
||||||
<div>
|
|
||||||
<h4>Document company</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="row">
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Name)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Name)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Company)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
<a asp-action="Details" asp-route-id="@Model.CompanyId" asp-controller="Companies">
|
|
||||||
@Html.DisplayFor(modelItem => Model.Company)</a>
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
<form asp-action="Delete">
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<input class="btn btn-danger" type="submit" value="Delete" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -77,21 +77,26 @@
|
|||||||
<span class="btn btn-secondary">
|
<span class="btn btn-secondary">
|
||||||
@L["Edit"]
|
@L["Edit"]
|
||||||
</span>
|
</span>
|
||||||
<span class="btn btn-danger">
|
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
|
||||||
@L["Delete"]
|
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@code
|
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||||
{
|
<ModalBackdrop/>
|
||||||
List<DocumentCompanyViewModel> _companies;
|
<ModalContent Centered="true">
|
||||||
|
<ModalHeader>
|
||||||
protected override async Task OnInitializedAsync()
|
<ModalTitle>@L["Delete company"]</ModalTitle>
|
||||||
{
|
<CloseButton Clicked="@HideModal"/>
|
||||||
_companies = await Service.GetAsync();
|
</ModalHeader>
|
||||||
}
|
<ModalBody>
|
||||||
}
|
<Text>@string.Format(@L["Are you sure you want to delete the company {0}?"], _currentCompany?.Name)</Text>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
|
||||||
|
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
|||||||
53
Marechai/Pages/Admin/DocumentCompanies.razor.cs
Normal file
53
Marechai/Pages/Admin/DocumentCompanies.razor.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Blazorise;
|
||||||
|
using Marechai.ViewModels;
|
||||||
|
|
||||||
|
namespace Marechai.Pages.Admin
|
||||||
|
{
|
||||||
|
public partial class DocumentCompanies
|
||||||
|
{
|
||||||
|
List<DocumentCompanyViewModel> _companies;
|
||||||
|
|
||||||
|
DocumentCompanyViewModel _currentCompany;
|
||||||
|
bool _deleteInProgress;
|
||||||
|
Modal _frmDelete;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync() => _companies = await Service.GetAsync();
|
||||||
|
|
||||||
|
void ShowModal(int itemId)
|
||||||
|
{
|
||||||
|
_currentCompany = _companies.FirstOrDefault(n => n.Id == itemId);
|
||||||
|
_frmDelete.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HideModal() => _frmDelete.Hide();
|
||||||
|
|
||||||
|
async void ConfirmDelete()
|
||||||
|
{
|
||||||
|
if(_currentCompany is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_deleteInProgress = true;
|
||||||
|
_companies = null;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await Service.DeleteAsync(_currentCompany.Id);
|
||||||
|
_companies = await Service.GetAsync();
|
||||||
|
|
||||||
|
_deleteInProgress = false;
|
||||||
|
_frmDelete.Hide();
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
// Tell we finished loading
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModalClosing(ModalClosingEventArgs obj) => _currentCompany = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,4 +150,16 @@
|
|||||||
<value>Eliminar</value>
|
<value>Eliminar</value>
|
||||||
<comment>Delete</comment>
|
<comment>Delete</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Delete company" xml:space="preserve">
|
||||||
|
<value>Eliminar compañía</value>
|
||||||
|
<comment>Delete company</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Are you sure you want to delete the company {0}?" xml:space="preserve">
|
||||||
|
<value>¿Está seguro de que desea borrar la compañía {0}?</value>
|
||||||
|
<comment>{0} company name</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Cancel" xml:space="preserve">
|
||||||
|
<value>Cancelar</value>
|
||||||
|
<comment>Cancel</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -21,5 +21,17 @@ namespace Marechai.Services
|
|||||||
Company = d.Company.Name,
|
Company = d.Company.Name,
|
||||||
CompanyId = d.CompanyId
|
CompanyId = d.CompanyId
|
||||||
}).ToListAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
|
public async Task DeleteAsync(int id)
|
||||||
|
{
|
||||||
|
DocumentCompany item = await _context.DocumentCompanies.FindAsync(id);
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_context.DocumentCompanies.Remove(item);
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user