Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
@model CustomerListModel
@{
//page title
ViewBag.Title = Loc["Admin.Customers.Customers"];
}
<form asp-area="@Constants.AreaAdmin" asp-controller="Customer" asp-action="List" method="post">
@* The product list's shape: Add new as the one primary action, the exports in the overflow
menu, the e-mail search always visible with the rest behind Filters, and Delete selected
in the bulk bar that appears once customers are ticked. The ids the scripts look up are
unchanged. *@
<admin-page title="@Loc["Admin.Customers.Customers"]" icon="bi-people">
<page-actions>
<admin-action-menu text="@Loc["Admin.Common.Export"]">
<admin-action submit="true" name="exportexcel-all"
url="@Url.Action("ExportExcelAll", new { area = Constants.AreaAdmin })"
icon="bi-download" text="@Loc["Admin.Common.ExportToExcel.All"]"/>
<admin-action id="exportexcel-selected" icon="bi-download"
text="@Loc["Admin.Common.ExportToExcel.Selected"]"/>
</admin-action-menu>
<vc:admin-widget widget-zone="customer_list_buttons" additional-data="null"/>
<a href="@Url.Action("Create", new { area = Constants.AreaAdmin })" class="btn btn-primary">
<i class="bi bi-plus-lg"></i> @Loc["Admin.Common.AddNew"]
</a>
</page-actions>
<admin-filters id="customer-filters" submit-id="search-customers" secondary-submit="true">
<filters-search>
<admin-input asp-for="SearchEmail"/>
</filters-search>
@if (Model.UsernamesEnabled)
{
<admin-field asp-for="SearchUsername"/>
}
<admin-field asp-for="SearchFirstName"/>
<admin-field asp-for="SearchLastName"/>
@if (Model.CompanyEnabled)
{
<admin-field asp-for="SearchCompany"/>
}
<admin-field asp-for="SearchCustomerGroupIds">
<admin-input asp-for="SearchCustomerGroupIds" asp-template="MultiSelect" asp-selectitem="Model.AvailableCustomerGroups"/>
</admin-field>
<admin-field asp-for="SearchCustomerTagIds">
<admin-input asp-for="SearchCustomerTagIds" asp-template="MultiSelect" asp-selectitem="Model.AvailableCustomerTags"/>
</admin-field>
@if (Model.PhoneEnabled)
{
<admin-field asp-for="SearchPhone"/>
}
@if (Model.ZipPostalCodeEnabled)
{
<admin-field asp-for="SearchZipPostalCode"/>
}
</admin-filters>
<admin-card flush>
<admin-bulkbar grid-id="customers-grid">
<button type="button" name="delete-selected" id="delete-selected" class="btn btn-outline-danger btn-sm">
<i class="bi bi-trash"></i> @Loc["Admin.Common.Delete.Selected"]
</button>
</admin-bulkbar>
<admin-grid id="customers-grid"
read-url="@Url.Action("CustomerList", "Customer", new { area = Constants.AreaAdmin })"
additional-data="additionalData"
selectable="Checkbox"
on-change="onCustomersSelectionChange">
<grid-column field="Email" title="@Loc["Admin.Customers.Customers.Fields.Email"]" width="200">
<cell-template>
<a class="text-decoration-none" href="Edit/{{ Id }}">{{ Email }}</a>
</cell-template>
</grid-column>
@if (Model.UsernamesEnabled)
{
<grid-column field="Username" title="@Loc["Admin.Customers.Customers.Fields.Username"]" width="200"/>
}
<grid-column field="FullName" title="@Loc["Admin.Customers.Customers.Fields.FullName"]" width="200"/>
<grid-column field="CustomerGroupNames" title="@Loc["Admin.Customers.Customers.Fields.CustomerGroups"]" width="200"/>
@if (Model.CompanyEnabled)
{
<grid-column field="Company" title="@Loc["Admin.Customers.Customers.Fields.Company"]" width="200" min-screen-width="770"/>
}
@if (Model.PhoneEnabled)
{
<grid-column field="Phone" title="@Loc["Admin.Customers.Customers.Fields.Phone"]" width="200" min-screen-width="770"/>
}
@if (Model.ZipPostalCodeEnabled)
{
<grid-column field="ZipPostalCode" title="@Loc["Admin.Customers.Customers.Fields.ZipPostalCode"]" width="200" min-screen-width="770"/>
}
<grid-column field="Active" title="@Loc["Admin.Customers.Customers.Fields.Active"]" width="100" align="Center">
<cell-template>
<i data-if="Active" class="bi bi-check-lg text-success" aria-hidden="true"></i>
<i data-else class="bi bi-x-lg text-danger" aria-hidden="true"></i>
</cell-template>
</grid-column>
<grid-column field="CreatedOn" title="@Loc["Admin.Customers.Customers.Fields.CreatedOn"]" width="200" format="{0:G}" min-screen-width="770"/>
<grid-column field="LastActivityDate" title="@Loc["Admin.Customers.Customers.Fields.LastActivityDate"]" width="200" format="{0:G}"/>
</admin-grid>
</admin-card>
</admin-page>
<script>
$(document).ready(function () {
$('.extend-collapse').hide();
$('.filter-extend-button').click(function () {
$('.extend-collapse').toggle("slow");
$('.filter-text-close').toggle();
});
});
</script>
<script>
var selectedIds = [];
function onCustomersSelectionChange(e) {
selectedIds = e.selectedIds;
}
$(document).ready(function () {
//search button
$('#search-customers').click(function () {
var grid = GrandAdmin.grids.get('#customers-grid');
grid.dataSource.page(1); //new search. Set page size to 1
//grid.dataSource.read(); we already loaded the grid above using "page" function
GrandAdmin.grids.get('#customers-grid').clearSelection();
return false;
});
$("#@Html.IdFor(model => model.SearchCustomerTagIds)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
@* the list widget types in its own input, so Enter is caught there too *@
var tagSelect = document.getElementById("@Html.IdFor(model => model.SearchCustomerTagIds)").grandSelect;
if (tagSelect) {
tagSelect.control_input.addEventListener('keydown', function (e) {
if (e.keyCode == 13) {
e.preventDefault();
$("#search-customers").click();
return false;
}
});
}
$("#@Html.IdFor(model => model.SearchEmail)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchUsername)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchFirstName)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchLastName)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchCompany)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchPhone)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
$("#@Html.IdFor(model => model.SearchZipPostalCode)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-customers").click();
return false;
}
});
//delete selected
$('#delete-selected').click(function(e) {
//a modal of the panel, not the browser's confirm()
GrandAdmin.modal.confirm('@Loc["Admin.Common.AreYouSure"]', {
title: '@Loc["Admin.Common.Delete.Selected"]',
confirmText: '@Loc["Admin.Common.Delete"]',
cancelText: '@Loc["Admin.Common.Cancel"]'
}).then(function (confirmed) {
if (!confirmed) return;
var postData = {
selectedIds: selectedIds
};
addAntiForgeryToken(postData);
$.ajax({
cache: false,
type: "POST",
url: "@(Url.Action("DeleteSelected", "Customer", new { area = Constants.AreaAdmin }))",
data: postData,
complete: function (data) {
//reload grid
var grid = GrandAdmin.grids.get('#customers-grid');
grid.clearSelection();
grid.dataSource.read();
},
error: function (xhr, ajaxOptions, thrownError) {
GrandAdmin.modal.confirm(thrownError, { cancelText: '@Loc["Admin.Common.Cancel"]' });
},
traditional: true
});
});
return false;
});
});
function additionalData() {
var customerGroupIds = [];
if($('#@Html.IdFor(model => model.SearchCustomerGroupIds)').val()!=null){
customerGroupIds = $('#@Html.IdFor(model => model.SearchCustomerGroupIds)').val();
}
var customerTagIds = [];
if($('#@Html.IdFor(model => model.SearchCustomerTagIds)').val()!=null){
customerTagIds = $('#@Html.IdFor(model => model.SearchCustomerTagIds)').val();
}
var data = {
SearchCustomerGroupIds: customerGroupIds,
SearchCustomerTagIds: customerTagIds,
SearchEmail: $('#@Html.IdFor(model => model.SearchEmail)').val(),
SearchUsername: $('#@Html.IdFor(model => model.SearchUsername)').val(),
SearchFirstName: $('#@Html.IdFor(model => model.SearchFirstName)').val(),
SearchLastName: $('#@Html.IdFor(model => model.SearchLastName)').val(),
SearchCompany: $('#@Html.IdFor(model => model.SearchCompany)').val(),
SearchPhone: $('#@Html.IdFor(model => model.SearchPhone)').val(),
SearchZipPostalCode: $('#@Html.IdFor(model => model.SearchZipPostalCode)').val()
};
addAntiForgeryToken(data);
return data;
}
</script>
</form>
<script>
$(document).ready(function () {
$('#exportxml-selected').click(function (e) {
e.preventDefault();
var ids = selectedIds.join(",");
$('#export-xml-selected-form #selectedIds').val(ids);
$('#export-xml-selected-form').submit();
return false;
});
});
</script>
<form asp-area="@Constants.AreaAdmin" asp-controller="Customer" asp-action="ExportExcelSelected" method="post" id="export-excel-selected-form">
<input type="hidden" id="selectedIds" name="selectedIds" value=""/>
</form>
<script>
$(document).ready(function () {
$('#exportexcel-selected').click(function (e) {
e.preventDefault();
var ids = selectedIds.join(",");
$('#export-excel-selected-form #selectedIds').val(ids);
$('#export-excel-selected-form').submit();
return false;
});
});
</script>