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 BulkEditListModel
@{
//page title
ViewBag.Title = Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit"];
var area = ViewContext.RouteData.Values["area"]?.ToString();
}
@* The product list's shape: one search field with the rest of the criteria behind the Filters
toggle, and the batch grid in a flush card. The grid's Save changes commits the screen, so it is
the one primary and Search is an outline button. The ids the script looks up are unchanged.
The grid is the quick editor of a product: name, SKU, prices and stock edited in place, rows
added with the card's Add new (a simple product, named in the row), and the rest - mappings,
attributes, SEO - in the product screen the row's popup opens. *@
<form asp-area="@area" asp-controller="Product" asp-action="BulkEdit" method="post">
<admin-page title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit"]" icon="bi-boxes">
<page-actions>
<partial name="Partials/WidgetZone.BulkEditButtons"/>
</page-actions>
<admin-filters id="bulkedit-filters" submit-id="search-products" secondary-submit="true">
<filters-search>
<admin-input asp-for="SearchProductName"/>
</filters-search>
<admin-field asp-for="SearchCategoryId"/>
<admin-field asp-for="SearchBrandId"/>
<admin-field asp-for="SearchCollectionId"/>
<admin-field asp-for="SearchProductTypeId" asp-items="Model.AvailableProductTypes"/>
@if (area == "Admin")
{
<admin-field asp-for="SearchStoreId" asp-items="Model.AvailableStores"/>
}
</admin-filters>
<admin-card flush>
<admin-grid id="products-grid"
read-url="@Url.Action("BulkEditSelect", "Product", new { area = area })"
create-url="@Url.Action("BulkEditCreate", "Product", new { area = area })"
update-url="@Url.Action("BulkEditUpdate", "Product", new { area = area })"
destroy-url="@Url.Action("BulkEditDelete", "Product", new { area = area })"
additional-data="additionalData"
edit-mode="Batch"
batch-prefix="products"
confirm-destroy="true">
<grid-toolbar-create text="@Loc[$"{Scope.ResourceKeyPrefix}.Common.AddNew"]"/>
<grid-toolbar-save/>
<grid-toolbar-cancel/>
<grid-text name="edit" value="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Edit"]"/>
<grid-column field="Name" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.Name"]" width="220" editor="Text" required="true"/>
<grid-column field="Sku" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.Sku"]" width="110" editor="Text"/>
@*prices are posted with four decimals in the request culture, like the Kendo parameterMap*@
<grid-column field="Price" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.Price"]" width="100" align="Right" editor="Numeric" decimals="4" default-value="0"/>
<grid-column field="OldPrice" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.OldPrice"]" width="100" align="Right" editor="Numeric" decimals="4" default-value="0" min-screen-width="1400"/>
<grid-column field="StockQuantity" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.StockQuantity"]" width="90" align="Right" format="{0:0}" editor="Integer" default-value="0"/>
<grid-column field="ManageInventoryMethodId" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.ManageInventoryMethod"]" width="150"
editor="Select" options="EnumTranslationService.ToSelectList(ManageInventoryMethod.DontManageStock)" text-field="ManageInventoryMethod"
default-value="0" min-screen-width="1150"/>
<grid-column field="Published" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.BulkEdit.Fields.Published"]" width="90" align="Center" editor="Checkbox" default-value="true"/>
@* more fields in a popup, and the rest of the product on its own screen - in a tab of
its own, so the changes not saved here stay; a row not saved yet has neither *@
<grid-text name="details" value="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.EditProductDetails"]"/>
<grid-column field="Id" title="" width="96" align="Center">
<cell-template>
<div data-if="Id" class="d-inline-flex gap-1">
<button type="button" class="btn btn-sm btn-outline-secondary" data-grid-click="openBulkEditDetails"
title="{{ $texts.details }}" aria-label="{{ $texts.details }}"><i class="bi bi-sliders"></i></button>
<a class="btn btn-sm btn-outline-secondary" href="@Url.Action("Edit", "Product", new { area = area })/{{ Id }}" target="_blank"
title="{{ $texts.edit }}" aria-label="{{ $texts.edit }}"><i class="bi bi-box-arrow-up-right"></i></a>
</div>
</cell-template>
</grid-column>
<grid-commands destroy="true" title="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Delete"]" width="100"/>
</admin-grid>
</admin-card>
</admin-page>
<script>
$(document).ready(function () {
$('#search-products').click(function () {
var grid = GrandAdmin.grids.get('#products-grid');
grid.dataSource.page(1); //new search. Set page size to 1
//grid.dataSource.read(); we already loaded the grid above using "page" function
return false;
});
$("#@Html.IdFor(model => model.SearchProductName)").keydown(function (event) {
if (event.keyCode == 13) {
$("#search-products").click();
return false;
}
});
});
//the product screen with the quick-edit tabs, in a popup over the grid. Closing it
//reloads the grid to show what was saved there, so what was typed in the grid is
//saved first rather than lost; a save that fails (a required name left empty) keeps
//the popup closed and the grid as it is
async function openBulkEditDetails(item) {
var grid = GrandAdmin.grids.get('#products-grid');
if (grid.dataSource.hasChanges() && !(await grid.saveChanges()))
return;
$.magnificPopup.open({
items: { src: '@Url.Action("Edit", "Product", new { area = area })/' + encodeURIComponent(item.Id) + '?popup=true' },
type: 'iframe',
mainClass: 'grand-mfp-frame',
closeOnBgClick: false,
callbacks: {
close: function () {
grid.dataSource.read();
}
}
});
}
function additionalData() {
var data = {
SearchProductName: $('#@Html.IdFor(model => model.SearchProductName)').val(),
SearchCategoryId: $('#SearchCategoryId').val(),
SearchBrandId: $('#SearchBrandId').val(),
SearchCollectionId: $('#SearchCollectionId').val(),
SearchProductTypeId: $('#SearchProductTypeId').val(),
@if (area == "Admin")
{
<text>SearchStoreId: $('#SearchStoreId').val(),</text>
}
};
addAntiForgeryToken(data);
return data;
}
</script>
</form>