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
Admin Panel - Replacing IFormCollection with strongly typed objects (#409)
Krzysztof Pajakb192365855df
diff --git a/src/Core/Grand.Infrastructure/TypeConverters/WebTypeConverter.cs b/src/Core/Grand.Infrastructure/TypeConverters/WebTypeConverter.csindex 2636e6750..43c4c4559 100644--- a/src/Core/Grand.Infrastructure/TypeConverters/WebTypeConverter.cs+++ b/src/Core/Grand.Infrastructure/TypeConverters/WebTypeConverter.cs@@ -10,9 +10,6 @@ namespace Grand.Infrastructure.TypeConverters{public void Register(){- TypeDescriptor.AddAttributes(typeof(List<int>), new TypeConverterAttribute(typeof(GenericListTypeConverter<int>)));- TypeDescriptor.AddAttributes(typeof(List<double>), new TypeConverterAttribute(typeof(GenericListTypeConverter<double>)));- TypeDescriptor.AddAttributes(typeof(List<string>), new TypeConverterAttribute(typeof(GenericListTypeConverter<string>)));TypeDescriptor.AddAttributes(typeof(bool), new TypeConverterAttribute(typeof(BoolTypeConverter)));//dictionariesdiff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ActivityLog/ListTypes.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ActivityLog/ListTypes.cshtmlindex 311e7182b..c2fdadcaf 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ActivityLog/ListTypes.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ActivityLog/ListTypes.cshtml@@ -90,7 +90,7 @@headerTemplate: "@Loc["Admin.Settings.ActivityLog.ActivityLogType.Fields.Enabled"] <label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input id='mastercheckbox' type='checkbox' /> <div class='control__indicator'></div></label>",headerAttributes: { style: "text-align:center" },attributes: { style: "text-align:center" },- template: "<label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input name='checkbox_activity_types' value='#=Id#' type='checkbox' class='checkboxGroups' # if(Enabled) {# checked='checked' #} # /> <div class='control__indicator'></div></label>",+ template: "<label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input name='ActivityTypes' value='#=Id#' type='checkbox' class='checkboxGroups' # if(Enabled) {# checked='checked' #} # /> <div class='control__indicator'></div></label>",width: 100}]diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/CustomerAttributes.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/CustomerAttributes.cshtmlindex 60124a495..ad8c19a02 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/CustomerAttributes.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/CustomerAttributes.cshtml@@ -1,7 +1,7 @@@model IList<CustomerModel.CustomerAttributeModel>@foreach (var attribute in Model){- var controlId = $"customer_attribute_{attribute.Id}";+ var controlId = $"attributes[{attribute.Id}]";var textPrompt = attribute.Name;<div class="form-horizontal"><div class="form-body">diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/AddProductToOrderDetails.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/AddProductToOrderDetails.cshtmlindex a00519c1d..5af884118 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/AddProductToOrderDetails.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/AddProductToOrderDetails.cshtml@@ -4,8 +4,6 @@}<form asp-area="@Constants.AreaAdmin" asp-controller="Order" asp-action="AddProductToOrderDetails" asp-route-orderId="@Model.OrderId"asp-route-productId="@Model.ProductId" enctype="multipart/form-data" method="post" id="product-details-form">--<div asp-validation-summary="All"></div><vc:admin-widget widget-zone="order_add_products_details_top" additional-data="Model" /><div class="row">diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/OrderDetails.Products.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/OrderDetails.Products.cshtmlindex 2a6ccaa89..4a9720600 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/OrderDetails.Products.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/OrderDetails.Products.cshtml@@ -1,5 +1,6 @@@model OrderModel@using Grand.Domain.Tax;+<vc:admin-widget widget-zone="order_details_products_top" additional-data="Model" /><div class="table-responsive order-table"><table class="table table-bordered table-striped table-hover">@@ -90,8 +91,10 @@</tr></thead><tbody>- @foreach (var item in Model.Items)+ @for (int j = 0; j < Model.Items.Count; j++){+ var item = Model.Items[j];+ <input asp-for="@Model.Items[j].Id" type="hidden" /><tr><td><img src="@item.PictureThumbnailUrl" alt="" title="" />@@ -166,13 +169,14 @@{<div>@string.Format(Loc["Admin.Orders.Products.Download.DownloadCount"], item.DownloadCount)- <input type="submit" asp-action="ResetDownloadCount" name="btnResetDownloadCount@(item.Id)" value="@Loc["Admin.Orders.Products.Download.ResetDownloadCount"]" title="@Loc["Admin.Orders.Products.Download.ResetDownloadCount.Title"]" id="btnResetDownloadCount@(item.Id)" class="k-button" />+ <input type="submit" asp-action="ResetDownloadCount" asp-route-orderItemId="@(item.Id)"+ name="btnResetDownloadCount@(item.Id)" value="@Loc["Admin.Orders.Products.Download.ResetDownloadCount"]" title="@Loc["Admin.Orders.Products.Download.ResetDownloadCount.Title"]" id="btnResetDownloadCount@(item.Id)" class="k-button" /><hr /></div>if (item.DownloadActivationType == DownloadActivationType.Manually){<div>- <input type="submit" name="btnPvActivateDownload@(item.Id)" @(item.IsDownloadActivated ? " value=" + Loc["Admin.Orders.Products.Download.Deactivate"] : " value=" + Loc["Admin.Orders.Products.Download.Activate"]) id="btnPvActivateDownload@(item.Id)" class="k-button" asp-action="ActivateDownloadItem" />+ <input type="submit" name="btnPvActivateDownload@(item.Id)" @(item.IsDownloadActivated ? " value=" + Loc["Admin.Orders.Products.Download.Deactivate"] : " value=" + Loc["Admin.Orders.Products.Download.Activate"]) id="btnPvActivateDownload@(item.Id)" class="k-button" asp-action="ActivateDownloadItem" asp-route-orderItemId="@(item.Id)" /><hr /></div>}@@ -235,7 +239,10 @@@Loc["Admin.Orders.Products.Edit.ExclTax"]</td><td>+ @*<input name="pvUnitPriceExclTax@(item.Id)" type="text" value="@item.UnitPriceExclTaxValue" id="pvUnitPriceExclTax@(item.Id)" class="adminInput" style="width:80px;" />+ *@+ <input asp-for="@Model.Items[j].UnitPriceExclTaxValue" class="adminInput" style="width:40px;" /></td></tr></table>@@ -247,7 +254,10 @@<table class="order-edit"><tr><td colspan="2">+ @*<input name="pvQuantity@(item.Id)" type="text" value="@item.Quantity" id="pvQuantity@(item.Id)" class="adminInput" style="width:40px;" />+ *@+ <input asp-for="@Model.Items[j].Quantity" class="adminInput" style="width:40px;" /></td></tr></table>@@ -313,9 +323,9 @@<td align="center"><div class="btn-group"><button type="submit" name="btnEditOrderItem@(item.Id)" id="btnEditOrderItem@(item.Id)" onclick="toggleOrderItemEdit@(item.Id)(true);return false; " class="k-button" title="@Loc["Admin.Common.Edit"]"><span class="k-icon k-i-edit"></span></button>- <button type="submit" name="btnDeleteOrderItem@(item.Id)" asp-action="DeleteOrderItem" id="btnDeleteOrderItem@(item.Id)" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Delete"]"><span class="k-icon k-i-delete"></span></button>- <button type="submit" name="btnCancelOrderItem@(item.Id)" asp-action="CancelOrderItem" id="btnCancelOrderItem@(item.Id)" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Cancel"]"><span class="k-icon k-i-cancel"></span></button>- <button type="submit" name="btnSaveOrderItem@(item.Id)" asp-action="SaveOrderItem" id="btnSaveOrderItem@(item.Id)" style="display:none;" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Save"]"><span class="k-icon k-i-save"></span></button>+ <button type="submit" name="btnDeleteOrderItem@(item.Id)" asp-action="DeleteOrderItem" asp-route-orderItemId="@(item.Id)" id="btnDeleteOrderItem@(item.Id)" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Delete"]"><span class="k-icon k-i-delete"></span></button>+ <button type="submit" name="btnCancelOrderItem@(item.Id)" asp-action="CancelOrderItem" asp-route-orderItemId="@(item.Id)" id="btnCancelOrderItem@(item.Id)" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Cancel"]"><span class="k-icon k-i-cancel"></span></button>+ <button type="submit" name="btnSaveOrderItem@(item.Id)" asp-action="SaveOrderItem" asp-route-orderItemId="@(item.Id)" id="btnSaveOrderItem@(item.Id)" style="display:none;" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]'); " class="k-button" title="@Loc["Admin.Common.Save"]"><span class="k-icon k-i-save"></span></button><button type="submit" name="btnCancel@(item.Id)" id="btnCancel@(item.Id)" onclick="toggleOrderItemEdit@(item.Id) (false);return false; " class="k-button"><span class="k-icon k-i-cancel" title="@Loc["Admin.Common.Cancel"]"></span></button></div></td>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/ProductAddAttributes.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/ProductAddAttributes.cshtmlindex b85fbab0a..cfdbcb9a5 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/ProductAddAttributes.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Order/Partials/ProductAddAttributes.cshtml@@ -5,7 +5,7 @@{<div class="form-group">@{- var controlId = $"product_attribute_{attribute.Id}";+ var controlId = $"attributes[{attribute.Id}]";var textPrompt = !string.IsNullOrEmpty(attribute.TextPrompt) ? attribute.TextPrompt : attribute.Name;}<label class="control-label col-md-3">diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabCountry.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabCountry.cshtmlindex 46a7fe556..5d4188854 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabCountry.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabCountry.cshtml@@ -61,7 +61,7 @@var systemNameWithoutDot = pm.SystemName.Replace(".", "");<td style="text-align:center">- <label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input class="restrict_@(systemNameWithoutDot)" type="checkbox" value="@(c.Id)" name="restrict_@(pm.SystemName)" @(resticted ? " checked=checked" : null) /> <div class="control__indicator"></div></label>+ <label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input class="restrict_@(systemNameWithoutDot)" type="checkbox" value="@(c.Id)" name="restrict_@(systemNameWithoutDot)" @(resticted ? " checked=checked" : null) /> <div class="control__indicator"></div></label></td>}</tr>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabShipping.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabShipping.cshtmlindex ec339eec8..33f07edf1 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabShipping.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Payment/Partials/MethodRestrictions.TabShipping.cshtml@@ -60,7 +60,7 @@var resticted = Model.RestictedShipping.ContainsKey(pm.SystemName) && Model.RestictedShipping[pm.SystemName][c.Name];var systemNameWithoutDot = pm.SystemName.Replace(".", "");<td style="text-align:center">- <label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input class="restrictship_@(systemNameWithoutDot)" type="checkbox" value="@(c.Name)" name="restrictship_@(pm.SystemName)" @(resticted ? " checked=checked" : null) /> <div class="control__indicator"></div></label>+ <label class='mt-checkbox mt-checkbox-outline control control-checkbox'><input class="restrictship_@(systemNameWithoutDot)" type="checkbox" value="@(c.Name)" name="restrictship_@(systemNameWithoutDot)" @(resticted ? " checked=checked" : null) /> <div class="control__indicator"></div></label></td>}</tr>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Plugin/List.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Plugin/List.cshtmlindex 1a4bcb454..c621b94f2 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Plugin/List.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Plugin/List.cshtml@@ -156,7 +156,7 @@$("#" + keyId + "").append("<li id='" + item.SystemName + "' class='item-installed-" + item.Installed + "'>" +"<div class='logo'><img src='" + item.LogoUrl + "'></img></div>" +"<div class='content'><div class='title'>" + item.FriendlyName + "<span class='install-" + item.Installed + "'>@Loc["Admin.Plugins.Fields.Installed"]</span></div><ul class='info'><li class='version'><span>@Loc["Admin.Plugins.Fields.Version"]:</span>" + item.Version + "</li><li class='version'><span>@Loc["Admin.Plugins.Fields.Author"]:</span>" + item.Author + "</li><li class='version'><span>@Loc["Admin.Plugins.Fields.SystemName"]:</span>" + item.SystemName + "</li></div></div>" +- "<div class='buttons'><a class='k-button button-" + item.ConfigurationUrl + "' href='" + item.ConfigurationUrl + "'>@Loc["Admin.Plugins.Fields.Configure"]</a><input type='submit' formaction='@installurl' name='install-plugin-link-" + item.SystemName + "' class='btn green install-plugin-link button-installed-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Install"]' /><input type='submit' formaction='@uninstallurl' name='uninstall-plugin-link-" + item.SystemName + "' class='btn red uninstall-plugin-link button-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Uninstall"]' /><input type='submit' formaction='@remove' name='remove-plugin-link-" + item.SystemName + "' class='btn btn-danger button-installed-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Remove"]' /></div>"+ "<div class='buttons'><a class='k-button button-" + item.ConfigurationUrl + "' href='" + item.ConfigurationUrl + "'>@Loc["Admin.Plugins.Fields.Configure"]</a><input type='submit' formaction='@(installurl)?SystemName=" + item.SystemName + "' name='install-plugin-link-" + item.SystemName + "' class='btn green install-plugin-link button-installed-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Install"]' /><input type='submit' formaction='@(uninstallurl)?SystemName=" + item.SystemName + "' name='uninstall-plugin-link-" + item.SystemName + "' class='btn red uninstall-plugin-link button-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Uninstall"]' /><input type='submit' formaction='@(remove)?SystemName=" + item.SystemName + "' name='remove-plugin-link-" + item.SystemName + "' class='btn btn-danger button-installed-" + item.Installed + "' value='@Loc["Admin.Plugins.Fields.Remove"]' /></div>"+"</li>");}});diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/ProductAttributes.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/ProductAttributes.cshtmlindex 77fd4b6bd..4deb538f0 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/ProductAttributes.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/ProductAttributes.cshtml@@ -4,7 +4,7 @@<div class="form-group">@foreach (var attribute in Model){- var controlId = $"product_attribute_{attribute.Id}";+ var controlId = $"attributes[{attribute.Id}]";var textPrompt = !string.IsNullOrEmpty(attribute.TextPrompt) ? attribute.TextPrompt : attribute.Name;<div class="form-group"><div class="col-md-3 col-sm-3">diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/ProductAttributeConditionPopup.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/ProductAttributeConditionPopup.cshtmlindex 3cb4e548c..10117fc34 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/ProductAttributeConditionPopup.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/ProductAttributeConditionPopup.cshtml@@ -72,7 +72,7 @@<div class="col-md-9 col-sm-9">@foreach (var attribute in Model.ProductAttributes){- var controlId = $"product_attribute_{attribute.Id}";+ var controlId = $"attributes[{attribute.Id}]";<div id="@($"pnl_attribute_values_{attribute.Id}")">@switch (attribute.AttributeControlType){diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/AddressAttributes.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/AddressAttributes.cshtmlindex b39144d11..d709f37b7 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/AddressAttributes.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Partials/AddressAttributes.cshtml@@ -1,7 +1,7 @@@model IList<AddressModel.AddressAttributeModel>@foreach (var attribute in Model){- var controlId = $"address_attribute_{attribute.Id}";+ var controlId = $"attributes[{attribute.Id}]";var textPrompt = attribute.Name;<div class="form-group">diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtmlindex bd54e8e6b..f9b4347ff 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml@@ -8,7 +8,7 @@asp-route-orderId="@Context.Request.Query["orderId"]"><div asp-validation-summary="All"></div>-+ <input type="hidden" asp-for="@Model.OrderId"/><div class="col-md-12"><div class="x_panel light form-fit"><div class="x_title">@@ -22,9 +22,13 @@</div><div class="actions"><div class="btn-group btn-group-devided">- <button class="btn btn-success" type="submit" id="shipment-save" name="save"><i class="fa fa-check"></i> @Loc["Admin.Common.Save"] </button>- <button class="btn btn-success" type="submit" id="shipment-save-continue" name="save-continue"><i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"] </button>- <vc:admin-widget widget-zone="order_shipment_add_buttons" additional-data="null" />+ <button class="btn btn-success" type="submit" id="shipment-save" name="save">+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]+ </button>+ <button class="btn btn-success" type="submit" id="shipment-save-continue" name="save-continue">+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]+ </button>+ <vc:admin-widget widget-zone="order_shipment_add_buttons" additional-data="null"/></div></div></div>@@ -32,15 +36,15 @@<div class="form-horizontal"><div class="form-body"><div class="form-group">- <admin-label asp-for="TrackingNumber" />+ <admin-label asp-for="TrackingNumber"/><div class="col-md-9 col-sm-9">- <admin-input asp-for="TrackingNumber" />+ <admin-input asp-for="TrackingNumber"/></div></div><div class="form-group">- <admin-label asp-for="AdminComment" />+ <admin-label asp-for="AdminComment"/><div class="col-md-9 col-sm-9">- <admin-input asp-for="AdminComment" />+ <admin-input asp-for="AdminComment"/></div></div></div>@@ -50,125 +54,130 @@</div>-- <h4><strong>@Loc["Admin.Orders.Shipments.Products"]</strong></h4>+ <h4>+ <strong>@Loc["Admin.Orders.Shipments.Products"]</strong>+ </h4><div class="table-responsive visible-xs-block visible-sm-block visible-md-block visible-lg-block"><table class="table table-bordered table-striped table-hover"><thead>- <tr>- <th>- @Loc["Admin.Orders.Shipments.Products.ProductName"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.SKU"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.Warehouse"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.ItemWeight"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.ItemDimensions"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.QtyOrdered"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.QtyShipped"]- </th>- <th>- @Loc["Admin.Orders.Shipments.Products.QtyToShip"]- </th>- </tr>+ <tr>+ <th>+ @Loc["Admin.Orders.Shipments.Products.ProductName"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.SKU"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.Warehouse"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.ItemWeight"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.ItemDimensions"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.QtyOrdered"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.QtyShipped"]+ </th>+ <th>+ @Loc["Admin.Orders.Shipments.Products.QtyToShip"]+ </th>+ </tr></thead><tbody>- @foreach (var item in Model.Items)- {- <tr>- <td>- <div style="padding-left:10px;padding-right:10px;">- <em><a href="@Url.Action("Edit", "Product", new {id = item.ProductId, area = Constants.AreaAdmin})">@item.ProductName</a></em>- @if (!string.IsNullOrEmpty(item.AttributeInfo))- {- <p>- @Html.Raw(item.AttributeInfo)- </p>- }- @if (item.ShipSeparately)+ @for (int j = 0; j < Model.Items.Count; j++)+ {+ var item = Model.Items[j];+ <input asp-for="@Model.Items[j].OrderItemId" type="hidden"/>+ <tr>+ <td>+ <div style="padding-left:10px;padding-right:10px;">+ <em>+ <a href="@Url.Action("Edit", "Product", new { id = item.ProductId, area = Constants.AreaAdmin })">@item.ProductName</a>+ </em>+ @if (!string.IsNullOrEmpty(item.AttributeInfo))+ {+ <p>+ @Html.Raw(item.AttributeInfo)+ </p>+ }+ @if (item.ShipSeparately)+ {+ <p>+ <strong>@Loc["Admin.Orders.Shipments.Products.ShipSeparately.Warning"]</strong>+ @Loc["Admin.Orders.Shipments.Products.ShipSeparately"]+ </p>+ }+ </div>+ </td>+ <td>+ <div style="padding-left:10px;padding-right:10px;">+ @item.Sku+ </div>+ </td>+ <td>+ <div>+ @if (item.AllowToChooseWarehouse)+ {+ if (item.AvailableWarehouses.Count > 0){- <p>- <strong>@Loc["Admin.Orders.Shipments.Products.ShipSeparately.Warning"]</strong>- @Loc["Admin.Orders.Shipments.Products.ShipSeparately"]- </p>+ <select asp-for="@Model.Items[j].WarehouseId">+ @foreach (var warehouse in item.AvailableWarehouses)+ {+ var selected = warehouse.WarehouseId == item.WarehouseId;+ <option value="@(warehouse.WarehouseId)" data-stock-qty="@(warehouse.StockQuantity)"+ data-reserved-qty="@(warehouse.ReservedQuantity)"+ selected="@selected">+ @Loc["Admin.Orders.Shipments.Products.Warehouse.ChooseQty", warehouse.WarehouseName, warehouse.StockQuantity, warehouse.ReservedQuantity]+ </option>+ }+ </select>}- </div>- </td>- <td>- <div style="padding-left:10px;padding-right:10px;">- @item.Sku- </div>- </td>- <td>- <div>- @if (item.AllowToChooseWarehouse)+ else{- if (item.AvailableWarehouses.Count > 0)- {- <select name="warehouse_@(item.OrderItemId)" id="warehouse_@(item.OrderItemId)">- @foreach (var warehouse in item.AvailableWarehouses)- {- var selected = warehouse.WarehouseId == item.WarehouseId;- <option value="@(warehouse.WarehouseId)" data-stock-qty="@(warehouse.StockQuantity)"- data-reserved-qty="@(warehouse.ReservedQuantity)"- selected="@selected">- @Loc["Admin.Orders.Shipments.Products.Warehouse.ChooseQty", warehouse.WarehouseName, warehouse.StockQuantity, warehouse.ReservedQuantity]- </option>- }- </select>- }- else- {- <div>@Loc["Admin.Orders.Shipments.Products.Warehouse.NotAvailabe"]</div>- }+ <div>@Loc["Admin.Orders.Shipments.Products.Warehouse.NotAvailabe"]</div>}- else+ }+ else+ {+ //display warehouses+ for (var i = 0; i < item.AvailableWarehouses.Count; i++){- //display warehouses- for (var i = 0; i < item.AvailableWarehouses.Count; i++)+ var warehouse = item.AvailableWarehouses[i];+ @warehouse.WarehouseName+ if (i != item.AvailableWarehouses.Count - 1){- var warehouse = item.AvailableWarehouses[i];- @warehouse.WarehouseName- if (i != item.AvailableWarehouses.Count - 1)- {- <br />- }+ <br/>}}- </div>- </td>- <td>- @item.ItemWeight- </td>- <td>- @item.ItemDimensions- </td>- <td>- @item.QuantityOrdered- </td>- <td>- @item.QuantityInAllShipments- </td>- <td>- <input name="qtyToAdd@(item.OrderItemId)" type="number" value="@item.QuantityToAdd"- id="qtyToAdd@(item.OrderItemId)" class="form-control" style="width:100px;" max="@item.QuantityToAdd" />- </td>- </tr>- }+ }+ </div>+ </td>+ <td>+ @item.ItemWeight+ </td>+ <td>+ @item.ItemDimensions+ </td>+ <td>+ @item.QuantityOrdered+ </td>+ <td>+ @item.QuantityInAllShipments+ </td>+ <td>+ <input asp-for="@Model.Items[j].QuantityToAdd" type="number" value="@item.QuantityToAdd"+ class="form-control" style="width:100px;" max="@item.QuantityToAdd"/>+ </td>+ </tr>+ }</tbody></table></div>-</form>+</form>\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/Partials/Info.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/Partials/Info.cshtmlindex 9d970d340..75bb8658b 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/Partials/Info.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/Partials/Info.cshtml@@ -102,7 +102,7 @@</div></div>-<table class="table table-bordered table-striped table-hover">+<table class="table table-striped table-hover"><tr><td><strong>@Loc["Admin.Orders.Shipments.Products"]</strong>diff --git a/src/Web/Grand.Web.Admin/Controllers/ActivityLogController.cs b/src/Web/Grand.Web.Admin/Controllers/ActivityLogController.csindex 046878c81..725a5ac7c 100644--- a/src/Web/Grand.Web.Admin/Controllers/ActivityLogController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ActivityLogController.cs@@ -4,8 +4,8 @@ using Grand.Business.Core.Utilities.Common.Security;using Grand.Web.Common.DataSource;using Grand.Web.Common.Security.Authorization;using Grand.Web.Admin.Interfaces;+using Grand.Web.Admin.Models.ActivityLog;using Grand.Web.Admin.Models.Logging;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Admin.Controllers@@ -43,11 +43,9 @@ namespace Grand.Web.Admin.Controllers[HttpPost][PermissionAuthorizeAction(PermissionActionName.Edit)]- public async Task<IActionResult> SaveTypes(IFormCollection form)+ public async Task<IActionResult> SaveTypes(ActivityTypeModel model){- var formKey = "checkbox_activity_types";- var checkedActivityTypes = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x).ToList();-+ var checkedActivityTypes = model.ActivityTypes.ToList();await _activityLogViewModelService.SaveTypes(checkedActivityTypes);Success(_translationService.GetResource("Admin.Settings.ActivityLog.ActivityLogType.Updated"));diff --git a/src/Web/Grand.Web.Admin/Controllers/CurrencyController.cs b/src/Web/Grand.Web.Admin/Controllers/CurrencyController.csindex baf109d1d..59ac30d63 100644--- a/src/Web/Grand.Web.Admin/Controllers/CurrencyController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/CurrencyController.cs@@ -107,10 +107,10 @@ namespace Grand.Web.Admin.Controllers[HttpPost][PermissionAuthorizeAction(PermissionActionName.Edit)]- public async Task<IActionResult> List(IFormCollection formValues)+ public async Task<IActionResult> List(ExchangeRateModel model){- _currencySettings.ActiveExchangeRateProviderSystemName = formValues["exchangeRateProvider"];- _currencySettings.AutoUpdateEnabled = !formValues["autoUpdateEnabled"].Equals("false");+ _currencySettings.ActiveExchangeRateProviderSystemName = model.ExchangeRateProvider;+ _currencySettings.AutoUpdateEnabled = model.AutoUpdateEnabled;await _settingService.SaveSetting(_currencySettings);return RedirectToAction("List", "Currency");}diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.csindex cb30b2dbe..68f98b862 100644--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs@@ -24,9 +24,9 @@ using Grand.Web.Admin.Models.Orders;using Grand.Web.Common.DataSource;using Grand.Web.Common.Filters;using Grand.Web.Common.Security.Authorization;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;using Grand.Business.Core.Interfaces.ExportImport;+using Grand.Web.Common.Models;namespace Grand.Web.Admin.Controllers{@@ -104,10 +104,10 @@ namespace Grand.Web.Admin.Controllers#endregion- protected virtual async Task<IList<CustomAttribute>> ParseCustomCustomerAttributes(IFormCollection form)+ protected virtual async Task<IList<CustomAttribute>> ParseCustomCustomerAttributes(IList<CustomAttributeModel> model){- if (form == null)- throw new ArgumentNullException(nameof(form));+ if (model == null)+ throw new ArgumentNullException(nameof(model));var customAttributes = new List<CustomAttribute>();var customerAttributes = await _customerAttributeService.GetAllCustomerAttributes();@@ -119,7 +119,7 @@ namespace Grand.Web.Admin.Controllerscase AttributeControlType.DropdownList:case AttributeControlType.RadioList:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,@@ -129,10 +129,10 @@ namespace Grand.Web.Admin.Controllersbreak;case AttributeControlType.Checkboxes:{- form.TryGetValue(controlId, out var cblAttributes);+ var cblAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){- foreach (var item in cblAttributes)+ foreach (var item in cblAttributes.Split(',')){if (!string.IsNullOrEmpty(item))customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,@@ -158,7 +158,7 @@ namespace Grand.Web.Admin.Controllerscase AttributeControlType.TextBox:case AttributeControlType.MultilineTextbox:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){var enteredText = ctrlAttributes.ToString().Trim();@@ -223,7 +223,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]- public async Task<IActionResult> Create(CustomerModel model, bool continueEditing, IFormCollection form)+ public async Task<IActionResult> Create(CustomerModel model, bool continueEditing){if (!string.IsNullOrWhiteSpace(model.Email)){@@ -264,7 +264,7 @@ namespace Grand.Web.Admin.Controllersif (ModelState.IsValid){- model.Attributes = await ParseCustomCustomerAttributes(form);+ model.Attributes = await ParseCustomCustomerAttributes(model.SelectedAttributes);var customer = await _customerViewModelService.InsertCustomerModel(model);//password@@ -318,7 +318,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]- public async Task<IActionResult> Edit(CustomerModel model, bool continueEditing, IFormCollection form)+ public async Task<IActionResult> Edit(CustomerModel model, bool continueEditing){var customer = await _customerService.GetCustomerById(model.Id);if (customer == null || customer.Deleted || await CheckSalesManager(customer))@@ -358,7 +358,7 @@ namespace Grand.Web.Admin.Controllers{try{- model.Attributes = await ParseCustomCustomerAttributes(form);+ model.Attributes = await ParseCustomCustomerAttributes(model.SelectedAttributes);customer = await _customerViewModelService.UpdateCustomerModel(customer, model);//change passwordif (!string.IsNullOrWhiteSpace(model.Password))@@ -676,7 +676,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> AddressCreate(CustomerAddressModel model, IFormCollection form)+ public async Task<IActionResult> AddressCreate(CustomerAddressModel model){var customer = await _customerService.GetCustomerById(model.CustomerId);if (customer == null || customer.Deleted || await CheckSalesManager(customer))@@ -684,7 +684,7 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//custom address attributes- var customAttributes = await form.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);+ var customAttributes = await model.Address.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarnings(customAttributes);foreach (var error in customAttributeWarnings){@@ -724,7 +724,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> AddressEdit(CustomerAddressModel model, IFormCollection form)+ public async Task<IActionResult> AddressEdit(CustomerAddressModel model){var customer = await _customerService.GetCustomerById(model.CustomerId);if (customer == null || customer.Deleted || await CheckSalesManager(customer))@@ -737,7 +737,7 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("Edit", new { id = customer.Id });//custom address attributes- var customAttributes = await form.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);+ var customAttributes = await model.Address.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarnings(customAttributes);foreach (var error in customAttributeWarnings){diff --git a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.csindex 05c4e10dc..312fd91e5 100644--- a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs@@ -12,7 +12,6 @@ using Grand.Web.Admin.Models.Orders;using Grand.Web.Common.DataSource;using Grand.Web.Common.Filters;using Grand.Web.Common.Security.Authorization;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Admin.Controllers@@ -150,7 +149,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]- public async Task<IActionResult> Edit(MerchandiseReturnModel model, bool continueEditing, IFormCollection form,+ public async Task<IActionResult> Edit(MerchandiseReturnModel model, bool continueEditing,[FromServices] IAddressAttributeService addressAttributeService,[FromServices] IAddressAttributeParser addressAttributeParser,[FromServices] OrderSettings orderSettings@@ -173,7 +172,7 @@ namespace Grand.Web.Admin.Controllersvar customAddressAttributes = new List<CustomAttribute>();if (orderSettings.MerchandiseReturns_AllowToSpecifyPickupAddress){- customAddressAttributes = await form.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);+ customAddressAttributes = await model.PickupAddress.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);var customAddressAttributeWarnings = await addressAttributeParser.GetAttributeWarnings(customAddressAttributes);foreach (var error in customAddressAttributeWarnings){diff --git a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs b/src/Web/Grand.Web.Admin/Controllers/OrderController.csindex 4515a6836..bd0b451f8 100644--- a/src/Web/Grand.Web.Admin/Controllers/OrderController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/OrderController.cs@@ -663,7 +663,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> SaveOrderItem(string id, IFormCollection form)+ public async Task<IActionResult> SaveOrderItem(string id, OrderItemsModel model){var order = await _orderService.GetOrderById(id);if (order == null || await CheckSalesManager(order))@@ -684,39 +684,29 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("Edit", "Order", new { id });}- //get order item identifier- var orderItemId = "";- foreach (var formValue in form.Keys)- if (formValue.StartsWith("btnSaveOrderItem", StringComparison.OrdinalIgnoreCase))- orderItemId = formValue["btnSaveOrderItem".Length..];-- var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);+ var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == model.OrderItemId);if (orderItem == null)throw new ArgumentException("No order item found with the specified id");- if (!double.TryParse(form["pvUnitPriceExclTax" + orderItemId], out var unitPriceExclTax))- unitPriceExclTax = orderItem.UnitPriceExclTax;- if (!int.TryParse(form["pvQuantity" + orderItemId], out var quantity))- quantity = orderItem.Quantity;-- if (quantity == 0 || (orderItem.OpenQty != orderItem.Quantity && orderItem.IsShipEnabled))+ var itemModel = model.Items.FirstOrDefault(x => x.Id == model.OrderItemId);+ if (itemModel.Quantity == 0 || (orderItem.OpenQty != orderItem.Quantity && orderItem.IsShipEnabled)){Error("You can't change quantity");return RedirectToAction("Edit", "Order", new { id });}- if (orderItem.Quantity == quantity && orderItem.UnitPriceExclTax == unitPriceExclTax)+ if (orderItem.Quantity == itemModel.Quantity && orderItem.UnitPriceExclTax == itemModel.UnitPriceExclTaxValue){Error("Nothing has been changed");return RedirectToAction("Edit", "Order", new { id });}- orderItem.Quantity = quantity;- orderItem.OpenQty = quantity;+ orderItem.Quantity = itemModel.Quantity;+ orderItem.OpenQty = itemModel.Quantity;- if (orderItem.UnitPriceExclTax != unitPriceExclTax)+ if (orderItem.UnitPriceExclTax != itemModel.UnitPriceExclTaxValue){- orderItem.UnitPriceExclTax = unitPriceExclTax;+ orderItem.UnitPriceExclTax = itemModel.UnitPriceExclTaxValue;orderItem.UnitPriceInclTax = Math.Round(orderItem.UnitPriceExclTax * orderItem.TaxRate / 100 + orderItem.UnitPriceExclTax, 2);orderItem.PriceInclTax = Math.Round(orderItem.UnitPriceInclTax * orderItem.Quantity, 2);orderItem.PriceExclTax = Math.Round(orderItem.UnitPriceExclTax * orderItem.Quantity, 2);@@ -743,7 +733,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> DeleteOrderItem(string id, IFormCollection form)+ public async Task<IActionResult> DeleteOrderItem(string id, string orderItemId){var order = await _orderService.GetOrderById(id);if (order == null || await CheckSalesManager(order))@@ -758,11 +748,6 @@ namespace Grand.Web.Admin.Controllers{return RedirectToAction("Edit", "Order", new { id });}- //get order item identifier- var orderItemId = "";- foreach (var formValue in form.Keys)- if (formValue.StartsWith("btnDeleteOrderItem", StringComparison.OrdinalIgnoreCase))- orderItemId = formValue["btnDeleteOrderItem".Length..];var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);if (orderItem == null)@@ -781,7 +766,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> CancelOrderItem(string id, IFormCollection form)+ public async Task<IActionResult> CancelOrderItem(string id, string orderItemId){var order = await _orderService.GetOrderById(id);if (order == null || await CheckSalesManager(order))@@ -796,11 +781,6 @@ namespace Grand.Web.Admin.Controllers{return RedirectToAction("Edit", "Order", new { id });}- //get order item identifier- var orderItemId = "";- foreach (var formValue in form.Keys)- if (formValue.StartsWith("btnCancelOrderItem", StringComparison.OrdinalIgnoreCase))- orderItemId = formValue["btnCancelOrderItem".Length..];var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);if (orderItem == null)@@ -821,7 +801,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> ResetDownloadCount(string id, IFormCollection form)+ public async Task<IActionResult> ResetDownloadCount(string id, string orderItemId){var order = await _orderService.GetOrderById(id);if (order == null || await CheckSalesManager(order))@@ -832,13 +812,7 @@ namespace Grand.Web.Admin.Controllers{return RedirectToAction("Edit", "Order", new { id });}-- //get order item identifier- var orderItemId = "";- foreach (var formValue in form.Keys)- if (formValue.StartsWith("btnResetDownloadCount", StringComparison.OrdinalIgnoreCase))- orderItemId = formValue["btnResetDownloadCount".Length..];-+var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);if (orderItem == null)throw new ArgumentException("No order item found with the specified id");@@ -862,7 +836,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> ActivateDownloadItem(string id, IFormCollection form)+ public async Task<IActionResult> ActivateDownloadItem(string id, string orderItemId){var order = await _orderService.GetOrderById(id);if (order == null || await CheckSalesManager(order))@@ -874,12 +848,6 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("Edit", "Order", new { id });}- //get order item identifier- var orderItemId = "";- foreach (var formValue in form.Keys)- if (formValue.StartsWith("btnPvActivateDownload", StringComparison.OrdinalIgnoreCase))- orderItemId = formValue["btnPvActivateDownload".Length..];-var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == orderItemId);if (orderItem == null)throw new ArgumentException("No order item found with the specified id");@@ -1088,13 +1056,13 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> AddProductToOrderDetails(string orderId, string productId, IFormCollection form)+ public async Task<IActionResult> AddProductToOrderDetails(AddProductToOrderModel model){//a vendor does not have access to this functionalityif (_workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer))- return RedirectToAction("Edit", "Order", new { id = orderId });+ return RedirectToAction("Edit", "Order", new { id = model.OrderId });- var order = await _orderService.GetOrderById(orderId);+ var order = await _orderService.GetOrderById(model.OrderId);if (order == null || await CheckSalesManager(order))return RedirectToAction("List");@@ -1103,15 +1071,15 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");}- var warnings = await _orderViewModelService.AddProductToOrderDetails(orderId, productId, form);+ var warnings = await _orderViewModelService.AddProductToOrderDetails(model);if (!warnings.Any())//redirect to order details page- return RedirectToAction("Edit", "Order", new { id = orderId });+ return RedirectToAction("Edit", "Order", new { id = model.OrderId });//errors- var model = await _orderViewModelService.PrepareAddProductToOrderModel(order, productId);- model.Warnings.AddRange(warnings);- return View(model);+ var result = await _orderViewModelService.PrepareAddProductToOrderModel(order, model.ProductId);+ result.Warnings.AddRange(warnings);+ return View(result);}#endregion@@ -1155,7 +1123,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> AddressEdit(OrderAddressModel model, IFormCollection form,+ public async Task<IActionResult> AddressEdit(OrderAddressModel model,[FromServices] IAddressAttributeService addressAttributeService,[FromServices] IAddressAttributeParser addressAttributeParser){@@ -1185,7 +1153,7 @@ namespace Grand.Web.Admin.Controllersthrow new ArgumentException("No address found with the specified id");//custom address attributes- var customAttributes = await form.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);+ var customAttributes = await model.Address.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);var customAttributeWarnings = await addressAttributeParser.GetAttributeWarnings(customAttributes);foreach (var error in customAttributeWarnings){diff --git a/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs b/src/Web/Grand.Web.Admin/Controllers/PaymentController.csindex d10920eb0..09cf74c09 100644--- a/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/PaymentController.cs@@ -189,7 +189,7 @@ namespace Grand.Web.Admin.Controllers[HttpPost, ActionName("MethodRestrictions")][RequestFormLimits(ValueCountLimit = 2048)]- public async Task<IActionResult> MethodRestrictionsSave(IFormCollection form)+ public async Task<IActionResult> MethodRestrictionsSave(IDictionary<string, string[]> model){var paymentMethods = _paymentService.LoadAllPaymentMethods();var countries = await _countryService.GetAllCountries(showHidden: true);@@ -197,35 +197,24 @@ namespace Grand.Web.Admin.Controllersforeach (var pm in paymentMethods){- var formKey = "restrict_" + pm.SystemName;- var countryIdsToRestrict = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()- .Select(x => x).ToList();-- var newCountryIds = new List<string>();- foreach (var c in countries)+ if (model.TryGetValue($"restrict_{pm.SystemName.Replace(".", "")}", out var countryIds)){- if (countryIdsToRestrict.Contains(c.Id))- {- newCountryIds.Add(c.Id);- }+ var countryIdsToRestrict = countryIds.ToList();+ var newCountryIds = (from c in countries where countryIdsToRestrict.Contains(c.Id) select c.Id).ToList();+ await _paymentService.SaveRestrictedCountryIds(pm, newCountryIds);}- await _paymentService.SaveRestrictedCountryIds(pm, newCountryIds);-- formKey = "restrictship_" + pm.SystemName;- var shipIdsToRestrict = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()- .Select(x => x).ToList();+ else+ await _paymentService.SaveRestrictedCountryIds(pm, new List<string>());- var newShipIds = new List<string>();- foreach (var s in shippings)+ if (model.TryGetValue($"restrictship_{pm.SystemName.Replace(".", "")}", out var shipIds)){- if (shipIdsToRestrict.Contains(s.Name))- {- newShipIds.Add(s.Name);- }+ var shipIdsToRestrict = shipIds.ToList();+ var newShipIds = (from s in shippings where shipIdsToRestrict.Contains(s.Name) select s.Name).ToList();+ await _paymentService.SaveRestrictedShippingIds(pm, newShipIds);}- await _paymentService.SaveRestrictedShippingIds(pm, newShipIds);+ else+ await _paymentService.SaveRestrictedShippingIds(pm, new List<string>());}-Success(_translationService.GetResource("Admin.Configuration.Payment.MethodRestrictions.Updated"));//selected tabawait SaveSelectedTabIndex();diff --git a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs b/src/Web/Grand.Web.Admin/Controllers/PermissionController.csindex b57c3d004..87b22df59 100644--- a/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/PermissionController.cs@@ -10,7 +10,6 @@ using Grand.Domain.Permissions;using Grand.Infrastructure;using Grand.Web.Admin.Models.Permissions;using MediatR;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Admin.Controllers@@ -67,39 +66,40 @@ namespace Grand.Web.Admin.ControllersActions = pr.Actions.Any()});}+foreach (var cr in customerGroups){model.AvailableCustomerGroups.Add(new CustomerGroupModel { Id = cr.Id, Name = cr.Name });}+foreach (var pr in permissionRecords)- foreach (var cr in customerGroups)- {- var allowed = pr.CustomerGroups.Count(x => x == cr.Id) > 0;- if (!model.Allowed.ContainsKey(pr.SystemName))- model.Allowed[pr.SystemName] = new Dictionary<string, bool>();- model.Allowed[pr.SystemName][cr.Id] = allowed;- }+ foreach (var cr in customerGroups)+ {+ var allowed = pr.CustomerGroups.Count(x => x == cr.Id) > 0;+ if (!model.Allowed.ContainsKey(pr.SystemName))+ model.Allowed[pr.SystemName] = new Dictionary<string, bool>();+ model.Allowed[pr.SystemName][cr.Id] = allowed;+ }return View(model);}[HttpPost, ActionName("Index")]- public async Task<IActionResult> PermissionsSave(IFormCollection form)+ public async Task<IActionResult> PermissionsSave(IDictionary<string, string[]> model){var permissionRecords = await _permissionService.GetAllPermissions();var customerGroups = await _groupService.GetAllCustomerGroups(showHidden: true);foreach (var cr in customerGroups){- var formKey = "allow_" + cr.Id;- var permissionRecordSystemNamesToRestrict = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();+ model.TryGetValue($"allow_{cr.Id}", out var permissionIds);+ var permissionRecordSystemNamesToRestrict =+ permissionIds != null ? permissionIds.ToList() : new List<string>();foreach (var pr in permissionRecords){-var allow = permissionRecordSystemNamesToRestrict.Contains(pr.SystemName);if (allow){-if (pr.CustomerGroups.FirstOrDefault(x => x == cr.Id) == null){pr.CustomerGroups.Add(cr.Id);@@ -116,6 +116,7 @@ namespace Grand.Web.Admin.Controllers}}}+Success(_translationService.GetResource("Admin.Configuration.Permissions.Updated"));return RedirectToAction("Index");@@ -151,41 +152,39 @@ namespace Grand.Web.Admin.Controllersreturn await PermissionsAction(systemName, customeGroupId);}- model.DeniedActions = (await _permissionService.GetPermissionActions(systemName, customeGroupId)).Select(x => x.Action).ToList();+ model.DeniedActions = (await _permissionService.GetPermissionActions(systemName, customeGroupId))+ .Select(x => x.Action).ToList();return View(model);}[HttpPost]- public async Task<IActionResult> PermissionsAction(IFormCollection form)+ public async Task<IActionResult> PermissionsAction(PermissionActionSaveModel model){- var systemname = form["SystemName"].ToString();- var customergroupId = form["CustomerGroupId"].ToString();-- var selected = form["SelectedActions"].ToList();-//remove denied actions- var deniedActions = await _permissionService.GetPermissionActions(systemname, customergroupId);+ var deniedActions = await _permissionService.GetPermissionActions(model.SystemName, model.CustomerGroupId);foreach (var action in deniedActions){await _permissionService.DeletePermissionAction(action);}//insert denied actions- var permissionRecord = await _permissionService.GetPermissionBySystemName(systemname);- var insertActions = permissionRecord.Actions.Except(selected);+ var permissionRecord = await _permissionService.GetPermissionBySystemName(model.SystemName);+ var insertActions = permissionRecord.Actions.Except(model.SelectedActions ?? new List<string>());foreach (var item in insertActions){await _permissionService.InsertPermissionAction(new PermissionAction {Action = item,- CustomerGroupId = customergroupId,- SystemName = systemname+ CustomerGroupId = model.CustomerGroupId,+ SystemName = model.SystemName});}+ViewBag.ClosePage = true;- return await PermissionsAction(systemname, customergroupId);+ return await PermissionsAction(model.SystemName, model.CustomerGroupId);}+#endregion}-}+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs b/src/Web/Grand.Web.Admin/Controllers/PluginController.csindex 93405578e..3a4cb3e0f 100644--- a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/PluginController.cs@@ -158,16 +158,10 @@ namespace Grand.Web.Admin.Controllers}[HttpPost]- public async Task<IActionResult> Install(IFormCollection form)+ public async Task<IActionResult> Install(string systemName){try{- //get plugin system name- string systemName = null;- foreach (var formValue in form.Keys)- if (formValue.StartsWith("install-plugin-link-", StringComparison.OrdinalIgnoreCase))- systemName = formValue["install-plugin-link-".Length..];-var pluginInfo = PluginManager.ReferencedPlugins.FirstOrDefault(x => x.SystemName == systemName);if (pluginInfo == null)//No plugin found with the specified id@@ -202,16 +196,10 @@ namespace Grand.Web.Admin.Controllers}[HttpPost]- public async Task<IActionResult> Uninstall(IFormCollection form)+ public async Task<IActionResult> Uninstall(string systemName){try{- //get plugin system name- string systemName = null;- foreach (var formValue in form.Keys)- if (formValue.StartsWith("uninstall-plugin-link-", StringComparison.OrdinalIgnoreCase))- systemName = formValue["uninstall-plugin-link-".Length..];-var pluginInfo = PluginManager.ReferencedPlugins.FirstOrDefault(x => x.SystemName == systemName);if (pluginInfo == null)//No plugin found with the specified id@@ -241,7 +229,7 @@ namespace Grand.Web.Admin.Controllers}[HttpPost]- public IActionResult Remove(IFormCollection form)+ public IActionResult Remove(string systemName){if (_extConfig.DisableUploadExtensions){@@ -251,12 +239,6 @@ namespace Grand.Web.Admin.Controllerstry{- //get plugin system name- string systemName = null;- foreach (var formValue in form.Keys)- if (formValue.StartsWith("remove-plugin-link-", StringComparison.OrdinalIgnoreCase))- systemName = formValue["remove-plugin-link-".Length..];-var pluginInfo = PluginManager.ReferencedPlugins.FirstOrDefault(x => x.SystemName == systemName);if (pluginInfo == null)//No plugin found with the specified iddiff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.csindex a59479043..59d1eb6c5 100644--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs@@ -2065,7 +2065,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]- public async Task<IActionResult> ProductAttributeConditionPopup(ProductAttributeConditionModel model, IFormCollection form)+ public async Task<IActionResult> ProductAttributeConditionPopup(ProductAttributeConditionModel model){var product = await _productService.GetProductById(model.ProductId);if (product == null)@@ -2083,12 +2083,7 @@ namespace Grand.Web.Admin.Controllersif (!product.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId))return Content(_translationService.GetResource("Admin.Catalog.Products.Permisions"));- var formcollection = new Dictionary<string, string>();- foreach (var item in form)- {- formcollection.Add(item.Key, item.Value);- }- await _productViewModelService.UpdateProductAttributeConditionModel(product, productAttributeMapping, model, formcollection);+ await _productViewModelService.UpdateProductAttributeConditionModel(product, productAttributeMapping, model);return Content("");}@@ -2410,7 +2405,7 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost]public async Task<IActionResult> AttributeCombinationPopup(string productId,- ProductAttributeCombinationModel model, IFormCollection form)+ ProductAttributeCombinationModel model){var product = await _productService.GetProductById(productId);if (product == null)@@ -2424,13 +2419,8 @@ namespace Grand.Web.Admin.Controllersif (await _groupService.IsStaff(_workContext.CurrentCustomer))if (!product.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId))return Content(_translationService.GetResource("Admin.Catalog.Products.Permisions"));-- var formcollection = new Dictionary<string, string>();- foreach (var item in form)- {- formcollection.Add(item.Key, item.Value);- }- var warnings = await _productViewModelService.InsertOrUpdateProductAttributeCombinationPopup(product, model, formcollection);++ var warnings = await _productViewModelService.InsertOrUpdateProductAttributeCombinationPopup(product, model);if (!warnings.Any()){return Content("");diff --git a/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs b/src/Web/Grand.Web.Admin/Controllers/ShipmentController.csindex b7a5063fb..1628eba5f 100644--- a/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ShipmentController.cs@@ -25,6 +25,7 @@ namespace Grand.Web.Admin.Controllerspublic class ShipmentController : BaseAdminController{#region Fields+private readonly IShipmentViewModelService _shipmentViewModelService;private readonly IOrderService _orderService;private readonly ITranslationService _translationService;@@ -86,8 +87,8 @@ namespace Grand.Web.Admin.Controllers{items.Add(await _shipmentViewModelService.PrepareShipmentModel(item, false));}- var gridModel = new DataSourceResult- {++ var gridModel = new DataSourceResult {Data = items,Total = shipments.totalCount};@@ -103,10 +104,12 @@ namespace Grand.Web.Admin.Controllersthrow new ArgumentException("No order found with the specified id");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return Content("");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && order.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ order.StoreId != _workContext.CurrentCustomer.StaffStoreId){return Content("");}@@ -126,13 +129,13 @@ namespace Grand.Web.Admin.Controllerselse{var shipments = (await _shipmentService.GetShipmentsByOrder(orderId))- .OrderBy(s => s.CreatedOnUtc)- .ToList();+ .OrderBy(s => s.CreatedOnUtc)+ .ToList();foreach (var shipment in shipments)shipmentModels.Add(await _shipmentViewModelService.PrepareShipmentModel(shipment, false));}- var gridModel = new DataSourceResult- {++ var gridModel = new DataSourceResult {Data = shipmentModels,Total = shipmentModels.Count};@@ -152,18 +155,19 @@ namespace Grand.Web.Admin.Controllersthrow new ArgumentException("No order found with the specified id");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return Content("");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return Content("");}//shipmentsvar shipmentModel = await _shipmentViewModelService.PrepareShipmentModel(shipment, true);- var gridModel = new DataSourceResult- {+ var gridModel = new DataSourceResult {Data = shipmentModel.Items,Total = shipmentModel.Items.Count};@@ -180,10 +184,12 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && order.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ order.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -195,18 +201,20 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Edit)][HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]- public async Task<IActionResult> AddShipment(string orderId, IFormCollection form, bool continueEditing)+ public async Task<IActionResult> AddShipment(AddShipmentModel model, bool continueEditing){- var order = await _orderService.GetOrderById(orderId);+ var order = await _orderService.GetOrderById(model.OrderId);if (order == null)//No order found with the specified idreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToOrder(order) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && order.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ order.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -217,40 +225,45 @@ namespace Grand.Web.Admin.Controllers{orderItems = orderItems.Where(_workContext.HasAccessToOrderItem).ToList();}- var sh = await _shipmentViewModelService.PrepareShipment(order, orderItems.ToList(), form);++ var sh = await _shipmentViewModelService.PrepareShipment(order, orderItems.ToList(), model);+ if (sh.shipment == null)+ return RedirectToAction("AddShipment", new { orderId = model.OrderId });+Shipment shipment = sh.shipment;//check stockvar (valid, message) = await _shipmentViewModelService.ValidStockShipment(shipment);if (!valid){Error(message);- return RedirectToAction("AddShipment", new { orderId });+ return RedirectToAction("AddShipment", new { orderId = model.OrderId });}- //if we have at least one item in the shipment, then save it- if (shipment != null && shipment.ShipmentItems.Count > 0)++ //if we have at least one item in the shipment, then save it+ if (shipment.ShipmentItems.Count > 0){shipment.TotalWeight = sh.totalWeight;await _shipmentService.InsertShipment(shipment);//add a note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = $"A shipment #{shipment.ShipmentNumber} has been added",DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,OrderId = order.Id});- _ = _shipmentViewModelService.LogShipment(shipment.Id, $"A shipment #{shipment.ShipmentNumber} has been added");+ _ = _shipmentViewModelService.LogShipment(shipment.Id,+ $"A shipment #{shipment.ShipmentNumber} has been added");Success(_translationService.GetResource("Admin.Orders.Shipments.Added"));return continueEditing- ? RedirectToAction("ShipmentDetails", new { id = shipment.Id })- : RedirectToAction("List", new { id = shipment.Id });+ ? RedirectToAction("ShipmentDetails", new { id = shipment.Id })+ : RedirectToAction("List", new { id = shipment.Id });}Error(_translationService.GetResource("Admin.Orders.Shipments.NoProductsSelected"));- return RedirectToAction("AddShipment", new { orderId });+ return RedirectToAction("AddShipment", new { orderId = model.OrderId });}[PermissionAuthorizeAction(PermissionActionName.Preview)]@@ -261,7 +274,8 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -273,7 +287,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");var model = await _shipmentViewModelService.PrepareShipmentModel(shipment, true, true);@@ -289,7 +304,8 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -307,22 +323,23 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");//delete shipmentawait _shipmentService.DeleteShipment(shipment);//add a note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = $"A shipment #{shipment.ShipmentNumber} has been deleted",DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,OrderId = order.Id});- _ = _shipmentViewModelService.LogShipment(shipment.Id, $"A shipment #{shipment.ShipmentNumber} has been deleted");+ _ = _shipmentViewModelService.LogShipment(shipment.Id,+ $"A shipment #{shipment.ShipmentNumber} has been deleted");Success(_translationService.GetResource("Admin.Orders.Shipments.Deleted"));@@ -338,10 +355,12 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}+if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId){Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));@@ -354,7 +373,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");shipment.TrackingNumber = model.TrackingNumber;@@ -372,10 +392,12 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}+if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId){Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));@@ -388,7 +410,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");shipment.AdminComment = model.AdminComment;@@ -406,10 +429,12 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}+if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId){Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));@@ -422,7 +447,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");try@@ -447,10 +473,12 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}+if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId){Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));@@ -463,7 +491,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");try@@ -472,6 +501,7 @@ namespace Grand.Web.Admin.Controllers{throw new Exception("Enter shipped date");}+shipment.ShippedDateUtc = model.ShippedDate.ConvertToUtcTime(_dateTimeService);await _shipmentService.UpdateShipment(shipment);return RedirectToAction("ShipmentDetails", new { id = shipment.Id });@@ -493,10 +523,12 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}+if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId){Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));@@ -509,7 +541,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");try@@ -535,7 +568,8 @@ namespace Grand.Web.Admin.Controllers//No shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -552,7 +586,8 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");try@@ -561,6 +596,7 @@ namespace Grand.Web.Admin.Controllers{throw new Exception("Enter delivery date");}+shipment.DeliveryDateUtc = model.DeliveryDate.ConvertToUtcTime(_dateTimeService);await _shipmentService.UpdateShipment(shipment);return RedirectToAction("ShipmentDetails", new { id = shipment.Id });@@ -586,7 +622,8 @@ namespace Grand.Web.Admin.Controllersif (_workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("ShipmentDetails", new { id = shipment.Id });- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("ShipmentDetails", new { id = shipment.Id });}@@ -596,6 +633,7 @@ namespace Grand.Web.Admin.ControllersError(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));return RedirectToAction("ShipmentDetails", new { id = shipment.Id });}+shipment.UserFields = model.UserFields;await _shipmentService.UpdateShipment(shipment);@@ -613,7 +651,8 @@ namespace Grand.Web.Admin.Controllers//no shipment found with the specified idreturn RedirectToAction("List");- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return RedirectToAction("List");}@@ -624,11 +663,11 @@ namespace Grand.Web.Admin.Controllersreturn RedirectToAction("List");//a vendor should have access only to his products- if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))+ if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer))return RedirectToAction("List");- var shipments = new List<Shipment>- {+ var shipments = new List<Shipment> {shipment};@@ -638,6 +677,7 @@ namespace Grand.Web.Admin.Controllersawait _pdfService.PrintPackagingSlipsToPdf(stream, shipments, _workContext.WorkingLanguage.Id);bytes = stream.ToArray();}+return File(bytes, "application/pdf", $"packagingslip_{shipment.Id}.pdf");}@@ -649,6 +689,7 @@ namespace Grand.Web.Admin.Controllers{model.StoreId = _workContext.CurrentCustomer.StaffStoreId;}+if (_workContext.CurrentVendor != null){model.VendorId = _workContext.CurrentVendor.Id;@@ -667,9 +708,11 @@ namespace Grand.Web.Admin.Controllersbyte[] bytes;using (var stream = new MemoryStream()){- await _pdfService.PrintPackagingSlipsToPdf(stream, shipments.shipments.ToList(), _workContext.WorkingLanguage.Id);+ await _pdfService.PrintPackagingSlipsToPdf(stream, shipments.shipments.ToList(),+ _workContext.WorkingLanguage.Id);bytes = stream.ToArray();}+return File(bytes, "application/pdf", "packagingslips.pdf");}@@ -705,8 +748,10 @@ namespace Grand.Web.Admin.Controllers{storeId = _workContext.CurrentCustomer.StaffStoreId;}+shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();}+//ensure that we at least one shipment selectedif (shipments.Count == 0){@@ -720,6 +765,7 @@ namespace Grand.Web.Admin.Controllersawait _pdfService.PrintPackagingSlipsToPdf(stream, shipments_access, _workContext.WorkingLanguage.Id);bytes = stream.ToArray();}+return File(bytes, "application/pdf", "packagingslips.pdf");}@@ -733,6 +779,7 @@ namespace Grand.Web.Admin.Controllers{shipments.AddRange(await _shipmentService.GetShipmentsByIds(selectedIds.ToArray()));}+//a vendor should have access only to his productsif (_workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer)){@@ -750,6 +797,7 @@ namespace Grand.Web.Admin.Controllers{storeId = _workContext.CurrentCustomer.StaffStoreId;}+shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();}@@ -778,6 +826,7 @@ namespace Grand.Web.Admin.Controllers{shipments.AddRange(await _shipmentService.GetShipmentsByIds(selectedIds.ToArray()));}+//a vendor should have access only to his productsif (_workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer)){@@ -795,6 +844,7 @@ namespace Grand.Web.Admin.Controllers{storeId = _workContext.CurrentCustomer.StaffStoreId;}+shipments_access = shipments.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(storeId)).ToList();}@@ -826,14 +876,15 @@ namespace Grand.Web.Admin.Controllersif (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId)return Json(new DataSourceResult());- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return Content("");}+//shipment notesvar shipmentNoteModels = await _shipmentViewModelService.PrepareShipmentNotes(shipment);- var gridModel = new DataSourceResult- {+ var gridModel = new DataSourceResult {Data = shipmentNoteModels,Total = shipmentNoteModels.Count};@@ -841,7 +892,8 @@ namespace Grand.Web.Admin.Controllers}[PermissionAuthorizeAction(PermissionActionName.Edit)]- public async Task<IActionResult> ShipmentNoteAdd(string shipmentId, string downloadId, bool displayToCustomer, string message)+ public async Task<IActionResult> ShipmentNoteAdd(string shipmentId, string downloadId, bool displayToCustomer,+ string message){var shipment = await _shipmentService.GetShipmentById(shipmentId);if (shipment == null)@@ -850,10 +902,12 @@ namespace Grand.Web.Admin.Controllersif (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId)return Json(new { Result = false });- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return Json(new { Result = false });}+await _shipmentViewModelService.InsertShipmentNote(shipment, downloadId, displayToCustomer, message);return Json(new { Result = true });@@ -870,7 +924,8 @@ namespace Grand.Web.Admin.Controllersif (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId)return Json(new { Result = false });- if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)+ if (await _groupService.IsStaff(_workContext.CurrentCustomer) &&+ shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId){return Json(new { Result = false });}@@ -879,8 +934,9 @@ namespace Grand.Web.Admin.Controllersreturn new JsonResult("");}+#endregion#endregion}-}+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs b/src/Web/Grand.Web.Admin/Controllers/ShippingController.csindex deb976375..0c294b393 100644--- a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs@@ -14,13 +14,15 @@ using Grand.Domain.Shipping;using Grand.Infrastructure;using Grand.Web.Admin.Models.Directory;using Grand.Web.Admin.Models.Shipping;-using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Rendering;using Grand.Web.Admin.Models.Common;using Grand.Business.Core.Interfaces.Common.Logging;+using Grand.Domain;+using Grand.Domain.Customers;using Grand.Web.Admin.Extensions.Mapping;using Grand.Web.Admin.Extensions.Mapping.Settings;+using Microsoft.Extensions.Primitives;namespace Grand.Web.Admin.Controllers{@@ -40,7 +42,6 @@ namespace Grand.Web.Admin.Controllersprivate readonly ILanguageService _languageService;private readonly IStoreService _storeService;private readonly IGroupService _groupService;- private readonly IServiceProvider _serviceProvider;private readonly IWorkContext _workContext;#endregion@@ -58,7 +59,6 @@ namespace Grand.Web.Admin.ControllersILanguageService languageService,IStoreService storeService,IGroupService groupService,- IServiceProvider serviceProvider,IWorkContext workContext){_shippingService = shippingService;@@ -72,7 +72,6 @@ namespace Grand.Web.Admin.Controllers_languageService = languageService;_storeService = storeService;_groupService = groupService;- _serviceProvider = serviceProvider;_workContext = workContext;}@@ -716,75 +715,88 @@ namespace Grand.Web.Admin.Controllers[HttpPost, ActionName("Restrictions")][RequestFormLimits(ValueCountLimit = 2048)]- public async Task<IActionResult> RestrictionSave(IFormCollection form)+ public async Task<IActionResult> RestrictionSave(IDictionary<string, string[]> model){var countries = await _countryService.GetAllCountries(showHidden: true);var shippingMethods = await _shippingMethodService.GetAllShippingMethods();var customerGroups = await _groupService.GetAllCustomerGroups();-foreach (var shippingMethod in shippingMethods){- var formKey = "restrict_" + shippingMethod.Id;- var countryIdsToRestrict = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)- .Select(x => x)- .ToList();+ await SaveRestrictedCountries(model, shippingMethod, countries);+ await SaveRestrictedGroup(model, shippingMethod, customerGroups);+ }+ Success(_translationService.GetResource("Admin.Configuration.Shipping.Restrictions.Updated"));+ //selected tab+ await SaveSelectedTabIndex();- foreach (var country in countries)- {+ return RedirectToAction("Restrictions");+ }- var restrict = countryIdsToRestrict.Contains(country.Id);+ private async Task SaveRestrictedGroup(IDictionary<string, string[]> model, ShippingMethod shippingMethod, IPagedList<CustomerGroup> customerGroups)+ {+ if (model.TryGetValue($"restrictgroup_{shippingMethod.Id}", out var roleIds))+ {+ var roleIdsToRestrict = roleIds.ToList();+ foreach (var role in customerGroups)+ {+ var restrict = roleIdsToRestrict.Contains(role.Id);if (restrict){- if (shippingMethod.RestrictedCountries.FirstOrDefault(c => c.Id == country.Id) == null)+ if (shippingMethod.RestrictedGroups.FirstOrDefault(c => c == role.Id) == null){- shippingMethod.RestrictedCountries.Add(country);+ shippingMethod.RestrictedGroups.Add(role.Id);await _shippingMethodService.UpdateShippingMethod(shippingMethod);}}else{- if (shippingMethod.RestrictedCountries.FirstOrDefault(c => c.Id == country.Id) != null)+ if (shippingMethod.RestrictedGroups.FirstOrDefault(c => c == role.Id) != null){- shippingMethod.RestrictedCountries.Remove(shippingMethod.RestrictedCountries.FirstOrDefault(x => x.Id == country.Id));+ shippingMethod.RestrictedGroups.Remove(role.Id);await _shippingMethodService.UpdateShippingMethod(shippingMethod);}}}+ }+ else+ {+ shippingMethod.RestrictedGroups.Clear();+ await _shippingMethodService.UpdateShippingMethod(shippingMethod);+ }+ }- formKey = "restrictgroup_" + shippingMethod.Id;- var roleIdsToRestrict = form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)- .Select(x => x)- .ToList();--- foreach (var role in customerGroups)+ private async Task SaveRestrictedCountries(IDictionary<string, string[]> model, ShippingMethod shippingMethod, IList<Country> countries)+ {+ if (model.TryGetValue($"restrict_{shippingMethod.Id}", out var countryIds))+ {+ var countryIdsToRestrict = countryIds.ToList();+ foreach (var country in countries){-- var restrict = roleIdsToRestrict.Contains(role.Id);+ var restrict = countryIdsToRestrict.Contains(country.Id);if (restrict){- if (shippingMethod.RestrictedGroups.FirstOrDefault(c => c == role.Id) == null)+ if (shippingMethod.RestrictedCountries.FirstOrDefault(c => c.Id == country.Id) == null){- shippingMethod.RestrictedGroups.Add(role.Id);+ shippingMethod.RestrictedCountries.Add(country);await _shippingMethodService.UpdateShippingMethod(shippingMethod);}}else{- if (shippingMethod.RestrictedGroups.FirstOrDefault(c => c == role.Id) != null)+ if (shippingMethod.RestrictedCountries.FirstOrDefault(c => c.Id == country.Id) != null){- shippingMethod.RestrictedGroups.Remove(role.Id);+ shippingMethod.RestrictedCountries.Remove(+ shippingMethod.RestrictedCountries.FirstOrDefault(x => x.Id == country.Id));await _shippingMethodService.UpdateShippingMethod(shippingMethod);}}}}-- Success(_translationService.GetResource("Admin.Configuration.Shipping.Restrictions.Updated"));- //selected tab- await SaveSelectedTabIndex();-- return RedirectToAction("Restrictions");+ else+ {+ shippingMethod.RestrictedCountries.Clear();+ await _shippingMethodService.UpdateShippingMethod(shippingMethod);+ }}#endregiondiff --git a/src/Web/Grand.Web.Admin/Extensions/AttributeParserHelper.cs b/src/Web/Grand.Web.Admin/Extensions/AttributeParserHelper.csindex c1bbb1194..bce3f0fa5 100644--- a/src/Web/Grand.Web.Admin/Extensions/AttributeParserHelper.cs+++ b/src/Web/Grand.Web.Admin/Extensions/AttributeParserHelper.cs@@ -1,7 +1,7 @@using Grand.Business.Core.Interfaces.Common.Addresses;using Grand.Domain.Catalog;using Grand.Domain.Common;-using Microsoft.AspNetCore.Http;+using Grand.Web.Admin.Models.Common;namespace Grand.Web.Admin.Extensions{@@ -10,24 +10,23 @@ namespace Grand.Web.Admin.Extensions/// </summary>public static class AttributeParserHelper{- public static async Task<List<CustomAttribute>> ParseCustomAddressAttributes(this IFormCollection form,+ public static async Task<List<CustomAttribute>> ParseCustomAddressAttributes(this AddressModel address,IAddressAttributeParser addressAttributeParser,IAddressAttributeService addressAttributeService){- if (form == null)- throw new ArgumentNullException(nameof(form));+ if (address == null)+ throw new ArgumentNullException(nameof(address));var customAttributes = new List<CustomAttribute>();var attributes = await addressAttributeService.GetAllAddressAttributes();foreach (var attribute in attributes){- var controlId = $"address_attribute_{attribute.Id}";switch (attribute.AttributeControlType){case AttributeControlType.DropdownList:case AttributeControlType.RadioList:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = address.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = addressAttributeParser.AddAddressAttribute(customAttributes,@@ -37,16 +36,17 @@ namespace Grand.Web.Admin.Extensionsbreak;case AttributeControlType.Checkboxes:{- form.TryGetValue(controlId, out var cblAttributes);+ var cblAttributes = address.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){- foreach (var item in cblAttributes.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))+ foreach (var item in cblAttributes.Split(',')){if (!string.IsNullOrEmpty(item))customAttributes = addressAttributeParser.AddAddressAttribute(customAttributes,attribute, item).ToList();}}+}break;case AttributeControlType.ReadonlyCheckboxes:@@ -66,10 +66,10 @@ namespace Grand.Web.Admin.Extensionscase AttributeControlType.TextBox:case AttributeControlType.MultilineTextbox:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = address.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){- var enteredText = ctrlAttributes.ToString().Trim();+ var enteredText = ctrlAttributes.Trim();customAttributes = addressAttributeParser.AddAddressAttribute(customAttributes,attribute, enteredText).ToList();}@@ -77,8 +77,8 @@ namespace Grand.Web.Admin.Extensionsbreak;case AttributeControlType.Datepicker:case AttributeControlType.ColorSquares:- case AttributeControlType.FileUpload:case AttributeControlType.ImageSquares:+ case AttributeControlType.FileUpload://not supported address attributesdefault:break;diff --git a/src/Web/Grand.Web.Admin/Interfaces/IOrderViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IOrderViewModelService.csindex 2bb3b5112..5e5f971e0 100644--- a/src/Web/Grand.Web.Admin/Interfaces/IOrderViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Interfaces/IOrderViewModelService.cs@@ -18,7 +18,7 @@ namespace Grand.Web.Admin.InterfacesTask InsertOrderNote(Order order, string downloadId, bool displayToCustomer, string message);Task DeleteOrderNote(Order order, string id);Task<Address> UpdateOrderAddress(Order order, Address address, OrderAddressModel model, List<CustomAttribute> customAttributes);- Task<IList<string>> AddProductToOrderDetails(string orderId, string productId, IFormCollection form);+ Task<IList<string>> AddProductToOrderDetails(AddProductToOrderModel model);Task<IList<Order>> PrepareOrders(OrderListModel model);Task SaveOrderTags(Order order, string tags);diff --git a/src/Web/Grand.Web.Admin/Interfaces/IProductViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IProductViewModelService.csindex ddcbeae08..084679107 100644--- a/src/Web/Grand.Web.Admin/Interfaces/IProductViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Interfaces/IProductViewModelService.cs@@ -69,7 +69,7 @@ namespace Grand.Web.Admin.InterfacesTask<ProductModel.ProductAttributeMappingModel> PrepareProductAttributeMappingModel(ProductAttributeMapping productAttributeMapping);Task UpdateProductAttributeValidationRulesModel(ProductAttributeMapping productAttributeMapping, ProductModel.ProductAttributeMappingModel model);Task<ProductAttributeConditionModel> PrepareProductAttributeConditionModel(Product product, ProductAttributeMapping productAttributeMapping);- Task UpdateProductAttributeConditionModel(Product product, ProductAttributeMapping productAttributeMapping, ProductAttributeConditionModel model, Dictionary<string, string> form);+ Task UpdateProductAttributeConditionModel(Product product, ProductAttributeMapping productAttributeMapping, ProductAttributeConditionModel model);Task<ProductModel.ProductAttributeValueModel> PrepareProductAttributeValueModel(Product product, ProductAttributeMapping productAttributeMapping);Task<IList<ProductModel.ProductAttributeValueModel>> PrepareProductAttributeValueModels(Product product, ProductAttributeMapping productAttributeMapping);Task<ProductModel.ProductAttributeValueModel> PrepareProductAttributeValueModel(ProductAttributeMapping pa, ProductAttributeValue pav);@@ -78,8 +78,7 @@ namespace Grand.Web.Admin.InterfacesTask<ProductModel.ProductAttributeValueModel.AssociateProductToAttributeValueModel> PrepareAssociateProductToAttributeValueModel();Task<IList<ProductModel.ProductAttributeCombinationModel>> PrepareProductAttributeCombinationModel(Product product);Task<ProductAttributeCombinationModel> PrepareProductAttributeCombinationModel(Product product, string combinationId);- //tier prices for combination- Task<IList<string>> InsertOrUpdateProductAttributeCombinationPopup(Product product, ProductAttributeCombinationModel model, Dictionary<string, string> form);+ Task<IList<string>> InsertOrUpdateProductAttributeCombinationPopup(Product product, ProductAttributeCombinationModel model);Task GenerateAllAttributeCombinations(Product product);Task ClearAllAttributeCombinations(Product product);diff --git a/src/Web/Grand.Web.Admin/Interfaces/IShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Interfaces/IShipmentViewModelService.csindex 4ffb24234..71084e6e1 100644--- a/src/Web/Grand.Web.Admin/Interfaces/IShipmentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Interfaces/IShipmentViewModelService.cs@@ -17,7 +17,7 @@ namespace Grand.Web.Admin.InterfacesTask DeleteShipmentNote(Shipment shipment, string id);Task<ShipmentListModel> PrepareShipmentListModel();Task<ShipmentModel> PrepareShipmentModel(Order order);- Task<(Shipment shipment, double? totalWeight)> PrepareShipment(Order order, IEnumerable<OrderItem> orderItems, IFormCollection form);+ Task<(Shipment shipment, double? totalWeight)> PrepareShipment(Order order, IEnumerable<OrderItem> orderItems, AddShipmentModel model);Task<(bool valid, string message)> ValidStockShipment(Shipment shipment);Task<(IEnumerable<Shipment> shipments, int totalCount)> PrepareShipments(ShipmentListModel model, int pageIndex, int pageSize);}diff --git a/src/Web/Grand.Web.Admin/Models/ActivityLog/ActivityTypeModel.cs b/src/Web/Grand.Web.Admin/Models/ActivityLog/ActivityTypeModel.csnew file mode 100644index 000000000..a7f9d8a92--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/ActivityLog/ActivityTypeModel.cs@@ -0,0 +1,6 @@+namespace Grand.Web.Admin.Models.ActivityLog;++public record ActivityTypeModel+{+ public List<string> ActivityTypes { get; set; }+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.csindex f736163e3..e2eeefe75 100644--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs@@ -1,6 +1,9 @@using Grand.Domain.Catalog;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;+using Microsoft.AspNetCore.Mvc;using System.ComponentModel.DataAnnotations;namespace Grand.Web.Admin.Models.Catalog@@ -54,6 +57,9 @@ namespace Grand.Web.Admin.Models.Catalogpublic IList<ProductAttributeModel> ProductAttributes { get; set; }+ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }+public IList<string> Warnings { get; set; }public string ProductId { get; set; }diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeConditionModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeConditionModel.csindex ce4610993..c2fb95e4c 100644--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeConditionModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeConditionModel.cs@@ -1,6 +1,9 @@using Grand.Domain.Catalog;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;+using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Admin.Models.Catalog{@@ -18,6 +21,8 @@ namespace Grand.Web.Admin.Models.Catalogpublic string SelectedProductAttributeId { get; set; }public IList<ProductAttributeModel> ProductAttributes { get; set; }+ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }public string ProductAttributeMappingId { get; set; }public string ProductId { get; set; }diff --git a/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs b/src/Web/Grand.Web.Admin/Models/Common/AddressModel.csindex 3f2c7360f..07eb77f33 100644--- a/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs@@ -2,6 +2,9 @@using Grand.Domain.Common;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;+using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Rendering;namespace Grand.Web.Admin.Models.Common@@ -75,7 +78,9 @@ namespace Grand.Web.Admin.Models.Commonpublic string FormattedCustomAddressAttributes { get; set; }public IList<AddressAttributeModel> CustomAddressAttributes { get; set; }-+ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }+public IList<SelectListItem> AvailableCountries { get; set; }public IList<SelectListItem> AvailableStates { get; set; }diff --git a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.csindex 4d2042a20..29585e5ce 100644--- a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;using Grand.Web.Common.Models;using Grand.Domain.Common;+using Grand.Web.Common.Binders;+using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Admin.Models.Customers{@@ -128,6 +130,9 @@ namespace Grand.Web.Admin.Models.Customerspublic string Fax { get; set; }public List<CustomerAttributeModel> CustomerAttributes { get; set; }++ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }[GrandResourceDisplayName("Admin.Customers.Customers.Fields.AdminComment")]public string AdminComment { get; set; }diff --git a/src/Web/Grand.Web.Admin/Models/Directory/ExchangeRateModel.cs b/src/Web/Grand.Web.Admin/Models/Directory/ExchangeRateModel.csnew file mode 100644index 000000000..f0494744e--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Directory/ExchangeRateModel.cs@@ -0,0 +1,3 @@+namespace Grand.Web.Admin.Models.Directory;++public record ExchangeRateModel(string ExchangeRateProvider, bool AutoUpdateEnabled);diff --git a/src/Web/Grand.Web.Admin/Models/Orders/AddProductToOrderModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/AddProductToOrderModel.csnew file mode 100644index 000000000..03bf40f77--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Orders/AddProductToOrderModel.cs@@ -0,0 +1,16 @@+using Grand.Web.Common.Binders;+using Grand.Web.Common.Models;+using Microsoft.AspNetCore.Mvc;++namespace Grand.Web.Admin.Models.Orders;++public record AddProductToOrderModel(string OrderId, string ProductId, double UnitPriceInclTax, double UnitPriceExclTax,+ int Quantity, int TaxRate)+{+ public GiftvoucherModel Giftvoucher { get; set; }++ [ModelBinder(BinderType = typeof(CustomAttributesBinder))]+ public IList<CustomAttributeModel> SelectedAttributes { get; set; }+}++public record GiftvoucherModel(string RecipientName, string RecipientEmail, string SenderName, string SenderEmail, string Message);diff --git a/src/Web/Grand.Web.Admin/Models/Orders/AddShipmentModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/AddShipmentModel.csnew file mode 100644index 000000000..db92e9b33--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Orders/AddShipmentModel.cs@@ -0,0 +1,22 @@+namespace Grand.Web.Admin.Models.Orders;++public class AddShipmentModel+{+ public AddShipmentModel()+ {+ Items = new List<ShipmentItemModel>();+ }++ public string OrderId { get; set; }+ public string TrackingNumber { get; set; }+ public string AdminComment { get; set; }++ public IList<ShipmentItemModel> Items { get; set; }++ public class ShipmentItemModel+ {+ public string OrderItemId { get; set; }+ public int QuantityToAdd { get; set; }+ public string WarehouseId { get; set; }+ }+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Models/Orders/MerchandiseReturnModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/MerchandiseReturnModel.csindex c6eaad7a2..d8c6c6872 100644--- a/src/Web/Grand.Web.Admin/Models/Orders/MerchandiseReturnModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Orders/MerchandiseReturnModel.cs@@ -71,7 +71,7 @@ namespace Grand.Web.Admin.Models.Orders[GrandResourceDisplayName("Admin.Orders.MerchandiseReturns.MerchandiseReturnNotes.Fields.Download")][UIHint("Download")]public string AddMerchandiseReturnNoteDownloadId { get; set; }-+public class MerchandiseReturnItemModel : BaseEntityModel{public string ProductId { get; set; }diff --git a/src/Web/Grand.Web.Admin/Models/Orders/OrderItemsModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/OrderItemsModel.csnew file mode 100644index 000000000..5a9cb3df7--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Orders/OrderItemsModel.cs@@ -0,0 +1,5 @@+namespace Grand.Web.Admin.Models.Orders;++public record OrderItemsModel(IList<OrderItemModel> Items, string OrderItemId);++public record OrderItemModel(string Id, double UnitPriceExclTaxValue, int Quantity);\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Models/Permissions/PermissionActionSaveModel.cs b/src/Web/Grand.Web.Admin/Models/Permissions/PermissionActionSaveModel.csnew file mode 100644index 000000000..ffa5fe8aa--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Permissions/PermissionActionSaveModel.cs@@ -0,0 +1,3 @@+namespace Grand.Web.Admin.Models.Permissions;++public record PermissionActionSaveModel(string SystemName, string CustomerGroupId, IList<string> SelectedActions);\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.csindex 02699f27d..b9e519b2b 100644--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs@@ -78,6 +78,7 @@ namespace Grand.Web.Admin.Servicesprivate readonly IOrderTagService _orderTagService;private readonly IOrderStatusService _orderStatusService;private readonly IMediator _mediator;+#endregion#region Ctor@@ -173,6 +174,7 @@ namespace Grand.Web.Admin.Servicesresult.Add(val1.Trim());}}+return result;}@@ -187,11 +189,12 @@ namespace Grand.Web.Admin.Services{//order statusesvar statuses = await _orderStatusService.GetAll();- var model = new OrderListModel- {- AvailableOrderStatuses = statuses.Select(x => new SelectListItem { Value = x.StatusId.ToString(), Text = x.Name }).ToList()+ var model = new OrderListModel {+ AvailableOrderStatuses = statuses+ .Select(x => new SelectListItem { Value = x.StatusId.ToString(), Text = x.Name }).ToList()};- model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailableOrderStatuses.Insert(0,+ new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });if (orderStatusId.HasValue){//pre-select value?@@ -201,51 +204,63 @@ namespace Grand.Web.Admin.Services}//payment statuses- model.AvailablePaymentStatuses = PaymentStatus.Pending.ToSelectList(_translationService, _workContext, false).ToList();- model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailablePaymentStatuses =+ PaymentStatus.Pending.ToSelectList(_translationService, _workContext, false).ToList();+ model.AvailablePaymentStatuses.Insert(0,+ new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });if (paymentStatusId.HasValue){//pre-select value?- var item = model.AvailablePaymentStatuses.FirstOrDefault(x => x.Value == paymentStatusId.Value.ToString());+ var item = model.AvailablePaymentStatuses.FirstOrDefault(x =>+ x.Value == paymentStatusId.Value.ToString());if (item != null)item.Selected = true;}//order's tags- model.AvailableOrderTags.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailableOrderTags.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });foreach (var s in await _orderTagService.GetAllOrderTags()){model.AvailableOrderTags.Add(new SelectListItem { Text = s.Name, Value = s.Id });}//shipping statuses- model.AvailableShippingStatuses = ShippingStatus.Pending.ToSelectList(_translationService, _workContext, false).ToList();- model.AvailableShippingStatuses.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailableShippingStatuses =+ ShippingStatus.Pending.ToSelectList(_translationService, _workContext, false).ToList();+ model.AvailableShippingStatuses.Insert(0,+ new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });if (shippingStatusId.HasValue){//pre-select value?- var item = model.AvailableShippingStatuses.FirstOrDefault(x => x.Value == shippingStatusId.Value.ToString());+ var item = model.AvailableShippingStatuses.FirstOrDefault(x =>+ x.Value == shippingStatusId.Value.ToString());if (item != null)item.Selected = true;}//stores- model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });- foreach (var s in (await _storeService.GetAllStores()).Where(x => x.Id == storeId || string.IsNullOrWhiteSpace(storeId)))+ model.AvailableStores.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ foreach (var s in (await _storeService.GetAllStores()).Where(x =>+ x.Id == storeId || string.IsNullOrWhiteSpace(storeId)))model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id });//vendors- model.AvailableVendors.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailableVendors.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });foreach (var v in await _vendorService.GetAllVendors(showHidden: true))model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id });//warehouses- model.AvailableWarehouses.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailableWarehouses.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });foreach (var w in await _warehouseService.GetAllWarehouses())model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id });//payment methods- model.AvailablePaymentMethods.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });+ model.AvailablePaymentMethods.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });foreach (var pm in _paymentService.LoadAllPaymentMethods())model.AvailablePaymentMethods.Add(new SelectListItem { Text = pm.FriendlyName, Value = pm.SystemName });@@ -254,10 +269,13 @@ namespace Grand.Web.Admin.Services{model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id });}- model.AvailableCountries.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });++ model.AvailableCountries.Insert(0,+ new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " });//a vendor should have access only to orders with his products- model.IsLoggedInAsVendor = _workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer);+ model.IsLoggedInAsVendor = _workContext.CurrentVendor != null &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer);if (startDate.HasValue)model.StartDate = startDate.Value;@@ -266,17 +284,22 @@ namespace Grand.Web.Admin.Servicesreturn model;}- public virtual async Task<(IEnumerable<OrderModel> orderModels, int totalCount)> PrepareOrderModel(OrderListModel model, int pageIndex, int pageSize)++ public virtual async Task<(IEnumerable<OrderModel> orderModels, int totalCount)> PrepareOrderModel(+ OrderListModel model, int pageIndex, int pageSize){- DateTime? startDateValue = model.StartDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);+ DateTime? startDateValue = model.StartDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);- DateTime? endDateValue = model.EndDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);+ DateTime? endDateValue = model.EndDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);int? orderStatus = model.OrderStatusId > 0 ? model.OrderStatusId : null;PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;- ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)model.ShippingStatusId : null;+ ShippingStatus? shippingStatus =+ model.ShippingStatusId > 0 ? (ShippingStatus?)model.ShippingStatusId : null;var filterByProductId = "";@@ -309,7 +332,7 @@ namespace Grand.Web.Admin.ServicespageSize: pageSize,orderTagId: model.OrderTag);-+var primaryStoreCurrency = await _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);if (primaryStoreCurrency == null)throw new Exception("Cannot load primary store currency");@@ -319,9 +342,9 @@ namespace Grand.Web.Admin.Servicesforeach (var x in orders){var store = await _storeService.GetStoreById(x.StoreId);- var orderTotal = await _priceFormatter.FormatPrice(x.OrderTotal, x.CustomerCurrencyCode, false, _workContext.WorkingLanguage);- items.Add(new OrderModel- {+ var orderTotal = await _priceFormatter.FormatPrice(x.OrderTotal, x.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage);+ items.Add(new OrderModel {Id = x.Id,OrderNumber = x.OrderNumber,Code = x.Code,@@ -338,6 +361,7 @@ namespace Grand.Web.Admin.ServicesCreatedOn = _dateTimeService.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc)});}+return (items, orders.TotalCount);}@@ -357,7 +381,8 @@ namespace Grand.Web.Admin.Servicesmodel.OrderGuid = order.OrderGuid;var status = await _orderStatusService.GetAll();- model.OrderStatuses = status.Select(x => new SelectListItem { Value = x.StatusId.ToString(), Text = x.Name }).ToList();+ model.OrderStatuses =+ status.Select(x => new SelectListItem { Value = x.StatusId.ToString(), Text = x.Name }).ToList();model.OrderStatus = status.FirstOrDefault(x => x.StatusId == order.OrderStatusId)?.Name;var store = await _storeService.GetStoreById(order.StoreId);@@ -367,7 +392,9 @@ namespace Grand.Web.Admin.Servicesvar customer = await _customerService.GetCustomerById(order.CustomerId);if (customer != null)- model.CustomerInfo = !string.IsNullOrEmpty(customer.Email) ? customer.Email : _translationService.GetResource("Admin.Customers.Guest");+ model.CustomerInfo = !string.IsNullOrEmpty(customer.Email)+ ? customer.Email+ : _translationService.GetResource("Admin.Customers.Guest");model.CustomerIp = order.CustomerIp;model.UrlReferrer = order.UrlReferrer;@@ -396,7 +423,8 @@ namespace Grand.Web.Admin.Services}//a vendor should have access only to his products- model.IsLoggedInAsVendor = _workContext.CurrentVendor != null && !await _groupService.IsStaff(_workContext.CurrentCustomer);+ model.IsLoggedInAsVendor = _workContext.CurrentVendor != null &&+ !await _groupService.IsStaff(_workContext.CurrentCustomer);//order's tagsif (order.OrderTags.Any())@@ -408,12 +436,14 @@ namespace Grand.Web.Admin.Servicesif (tag != null)tagsName.Add(tag.Name);}+model.OrderTags = string.Join(",", tagsName);}#region Order totals- var primaryStoreCurrency = await _currencyService.GetCurrencyByCode(order.PrimaryCurrencyCode) ?? await _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);+ var primaryStoreCurrency = await _currencyService.GetCurrencyByCode(order.PrimaryCurrencyCode) ??+ await _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);if (primaryStoreCurrency == null)throw new Exception("Cannot load primary store currency");@@ -423,13 +453,17 @@ namespace Grand.Web.Admin.Servicesthrow new Exception("Cannot load order currency");//subtotal- model.OrderSubtotalInclTax = _priceFormatter.FormatPrice(order.OrderSubtotalInclTax, orderCurrency, _workContext.WorkingLanguage, true);- model.OrderSubtotalExclTax = _priceFormatter.FormatPrice(order.OrderSubtotalExclTax, orderCurrency, _workContext.WorkingLanguage, false);+ model.OrderSubtotalInclTax = _priceFormatter.FormatPrice(order.OrderSubtotalInclTax, orderCurrency,+ _workContext.WorkingLanguage, true);+ model.OrderSubtotalExclTax = _priceFormatter.FormatPrice(order.OrderSubtotalExclTax, orderCurrency,+ _workContext.WorkingLanguage, false);model.OrderSubtotalInclTaxValue = order.OrderSubtotalInclTax;model.OrderSubtotalExclTaxValue = order.OrderSubtotalExclTax;//discount (applied to order subtotal)- var orderSubtotalDiscountInclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax, orderCurrency, _workContext.WorkingLanguage, true);- var orderSubtotalDiscountExclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax, orderCurrency, _workContext.WorkingLanguage, false);+ var orderSubtotalDiscountInclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax,+ orderCurrency, _workContext.WorkingLanguage, true);+ var orderSubtotalDiscountExclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax,+ orderCurrency, _workContext.WorkingLanguage, false);if (order.OrderSubTotalDiscountInclTax > 0)model.OrderSubTotalDiscountInclTax = orderSubtotalDiscountInclTaxStr;if (order.OrderSubTotalDiscountExclTax > 0)@@ -438,32 +472,39 @@ namespace Grand.Web.Admin.Servicesmodel.OrderSubTotalDiscountExclTaxValue = order.OrderSubTotalDiscountExclTax;//shipping- model.OrderShippingInclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax, orderCurrency, _workContext.WorkingLanguage, true);- model.OrderShippingExclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax, orderCurrency, _workContext.WorkingLanguage, false);+ model.OrderShippingInclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax, orderCurrency,+ _workContext.WorkingLanguage, true);+ model.OrderShippingExclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax, orderCurrency,+ _workContext.WorkingLanguage, false);model.OrderShippingInclTaxValue = order.OrderShippingInclTax;model.OrderShippingExclTaxValue = order.OrderShippingExclTax;//payment method additional feeif (order.PaymentMethodAdditionalFeeInclTax > 0){- model.PaymentMethodAdditionalFeeInclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTax, orderCurrency, _workContext.WorkingLanguage, true);- model.PaymentMethodAdditionalFeeExclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTax, orderCurrency, _workContext.WorkingLanguage, false);+ model.PaymentMethodAdditionalFeeInclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(+ order.PaymentMethodAdditionalFeeInclTax, orderCurrency, _workContext.WorkingLanguage, true);+ model.PaymentMethodAdditionalFeeExclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(+ order.PaymentMethodAdditionalFeeExclTax, orderCurrency, _workContext.WorkingLanguage, false);}+model.PaymentMethodAdditionalFeeInclTaxValue = order.PaymentMethodAdditionalFeeInclTax;model.PaymentMethodAdditionalFeeExclTaxValue = order.PaymentMethodAdditionalFeeExclTax;//tax- model.Tax = await _priceFormatter.FormatPrice(order.OrderTax, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.Tax = await _priceFormatter.FormatPrice(order.OrderTax, order.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage);var displayTaxRates = _taxSettings.DisplayTaxRates && order.OrderTaxes.Any();var displayTax = !displayTaxRates;foreach (var tr in order.OrderTaxes){- model.TaxRates.Add(new OrderModel.TaxRate- {+ model.TaxRates.Add(new OrderModel.TaxRate {Rate = _priceFormatter.FormatTaxRate(tr.Percent),- Value = await _priceFormatter.FormatPrice(tr.Amount, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage)+ Value = await _priceFormatter.FormatPrice(tr.Amount, order.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage)});}+model.DisplayTaxRates = displayTaxRates;model.DisplayTax = displayTax;model.TaxValue = order.OrderTax;@@ -471,7 +512,8 @@ namespace Grand.Web.Admin.Services//discountif (order.OrderDiscount > 0)- model.OrderTotalDiscount = await _priceFormatter.FormatPrice(-order.OrderDiscount, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.OrderTotalDiscount = await _priceFormatter.FormatPrice(-order.OrderDiscount,+ order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);model.OrderTotalDiscountValue = order.OrderDiscount;//gift vouchers@@ -480,10 +522,10 @@ namespace Grand.Web.Admin.Servicesvar giftVoucher = await _giftVoucherService.GetGiftVoucherById(gcuh.GiftVoucherId);if (giftVoucher != null){- model.GiftVouchers.Add(new OrderModel.GiftVoucher- {+ model.GiftVouchers.Add(new OrderModel.GiftVoucher {CouponCode = giftVoucher.Code,- Amount = await _priceFormatter.FormatPrice(-gcuh.UsedValue, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage)+ Amount = await _priceFormatter.FormatPrice(-gcuh.UsedValue, order.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage)});}}@@ -492,22 +534,27 @@ namespace Grand.Web.Admin.Servicesif (order.RedeemedLoyaltyPoints > 0){model.RedeemedLoyaltyPoints = order.RedeemedLoyaltyPoints;- model.RedeemedLoyaltyPointsAmount = await _priceFormatter.FormatPrice(-order.RedeemedLoyaltyPointsAmount, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.RedeemedLoyaltyPointsAmount = await _priceFormatter.FormatPrice(+ -order.RedeemedLoyaltyPointsAmount, order.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage);}//total- model.OrderTotal = await _priceFormatter.FormatPrice(order.OrderTotal, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.OrderTotal = await _priceFormatter.FormatPrice(order.OrderTotal, order.CustomerCurrencyCode, false,+ _workContext.WorkingLanguage);model.OrderTotalValue = order.OrderTotal;model.CurrencyRate = order.CurrencyRate;model.CurrencyCode = order.CustomerCurrencyCode;//refunded amountif (order.RefundedAmount > 0)- model.RefundedAmount = await _priceFormatter.FormatPrice(order.RefundedAmount, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.RefundedAmount = await _priceFormatter.FormatPrice(order.RefundedAmount,+ order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);var suggestedRefundedAmount = order.OrderItems.Sum(x => x.CancelAmount);if (suggestedRefundedAmount > 0)- model.SuggestedRefundedAmount = await _priceFormatter.FormatPrice(suggestedRefundedAmount, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);+ model.SuggestedRefundedAmount = await _priceFormatter.FormatPrice(suggestedRefundedAmount,+ order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);//used discountsvar duh = await _discountService.GetAllDiscountUsageHistory(orderId: order.Id);@@ -516,8 +563,7 @@ namespace Grand.Web.Admin.Servicesvar discount = await _discountService.GetDiscountById(d.DiscountId);if (discount != null){- model.UsedDiscounts.Add(new OrderModel.UsedDiscountModel- {+ model.UsedDiscounts.Add(new OrderModel.UsedDiscountModel {DiscountId = d.DiscountId,DiscountName = discount.Name});@@ -530,38 +576,53 @@ namespace Grand.Web.Admin.Servicesvar productCost = order.OrderItems.Sum(orderItem => orderItem.OriginalProductCost * orderItem.Quantity);if (order.CurrencyRate > 0){- var profit = Convert.ToDouble(order.OrderTotal / order.CurrencyRate - order.OrderShippingExclTax / order.CurrencyRate - order.OrderTax / order.CurrencyRate - productCost);- model.Profit = await _priceFormatter.FormatPrice(profit, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage);+ var profit = Convert.ToDouble(order.OrderTotal / order.CurrencyRate -+ order.OrderShippingExclTax / order.CurrencyRate -+ order.OrderTax / order.CurrencyRate - productCost);+ model.Profit = await _priceFormatter.FormatPrice(profit, order.PrimaryCurrencyCode, false,+ _workContext.WorkingLanguage);}}if (order.PrimaryCurrencyCode != order.CustomerCurrencyCode){- model.OrderTotal += $" ({await _priceFormatter.FormatPrice(order.OrderTotal / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";- model.OrderSubtotalInclTax += $" ({await _priceFormatter.FormatPrice(order.OrderSubtotalInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";- model.OrderSubtotalExclTax += $" ({await _priceFormatter.FormatPrice(order.OrderSubtotalExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";+ model.OrderTotal +=+ $" ({await _priceFormatter.FormatPrice(order.OrderTotal / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";+ model.OrderSubtotalInclTax +=+ $" ({await _priceFormatter.FormatPrice(order.OrderSubtotalInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";+ model.OrderSubtotalExclTax +=+ $" ({await _priceFormatter.FormatPrice(order.OrderSubtotalExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";//discount (applied to order subtotal)if (order.OrderSubTotalDiscountInclTax > 0)- model.OrderSubTotalDiscountInclTax += $" ({await _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";+ model.OrderSubTotalDiscountInclTax +=+ $" ({await _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";if (order.OrderSubTotalDiscountExclTax > 0)- model.OrderSubTotalDiscountExclTax += $" ({await _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";+ model.OrderSubTotalDiscountExclTax +=+ $" ({await _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";//shipping- model.OrderShippingInclTax += $" ({await _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";- model.OrderShippingExclTax += $" ({await _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";+ model.OrderShippingInclTax +=+ $" ({await _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";+ model.OrderShippingExclTax +=+ $" ({await _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";//payment method additional feeif (order.PaymentMethodAdditionalFeeInclTax > 0){- model.PaymentMethodAdditionalFeeInclTax += $" ({await _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";- model.PaymentMethodAdditionalFeeExclTax += $" ({await _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";+ model.PaymentMethodAdditionalFeeInclTax +=+ $" ({await _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, true)})";+ model.PaymentMethodAdditionalFeeExclTax +=+ $" ({await _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTax / order.CurrencyRate, order.PrimaryCurrencyCode, _workContext.WorkingLanguage, false)})";}- model.Tax += $" ({await _priceFormatter.FormatPrice(order.OrderTax / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";++ model.Tax +=+ $" ({await _priceFormatter.FormatPrice(order.OrderTax / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";//refunded amountif (order.RefundedAmount > 0)- model.RefundedAmount += $" ({await _priceFormatter.FormatPrice(order.RefundedAmount / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";+ model.RefundedAmount +=+ $" ({await _priceFormatter.FormatPrice(order.RefundedAmount / order.CurrencyRate, order.PrimaryCurrencyCode, false, _workContext.WorkingLanguage)})";}#endregion@@ -585,7 +646,9 @@ namespace Grand.Web.Admin.Services#region Billing & shipping infomodel.BillingAddress = await order.BillingAddress.ToModel(_countryService);- model.BillingAddress.FormattedCustomAddressAttributes = await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage, order.BillingAddress.Attributes);+ model.BillingAddress.FormattedCustomAddressAttributes =+ await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage,+ order.BillingAddress.Attributes);model.BillingAddress.NameEnabled = _addressSettings.NameEnabled;model.BillingAddress.FirstNameEnabled = true;model.BillingAddress.FirstNameRequired = true;@@ -624,7 +687,9 @@ namespace Grand.Web.Admin.Servicesif (order.ShippingAddress != null){model.ShippingAddress = await order.ShippingAddress.ToModel(_countryService);- model.ShippingAddress.FormattedCustomAddressAttributes = await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage, order.ShippingAddress.Attributes);+ model.ShippingAddress.FormattedCustomAddressAttributes =+ await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage,+ order.ShippingAddress.Attributes);model.ShippingAddress.NameEnabled = _addressSettings.NameEnabled;model.ShippingAddress.FirstNameEnabled = true;model.ShippingAddress.FirstNameRequired = true;@@ -666,6 +731,7 @@ namespace Grand.Web.Admin.Servicesmodel.PickupAddress.CountryName = country.Name;}}+model.ShippingMethod = order.ShippingMethod;model.ShippingAdditionDescription = order.ShippingOptionAttributeDescription;model.CanAddNewShipments = false;@@ -681,7 +747,6 @@ namespace Grand.Web.Admin.Servicesmodel.CanAddNewShipments = true;}-}#endregion@@ -698,18 +763,17 @@ namespace Grand.Web.Admin.Services.Where(orderItem => orderItem.VendorId == _workContext.CurrentVendor.Id).ToList();}+foreach (var orderItem in products){var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId);if (product != null){-if (product.IsDownload)hasDownloadableItems = true;- var orderItemModel = new OrderModel.OrderItemModel- {+ var orderItemModel = new OrderModel.OrderItemModel {Id = orderItem.Id,ProductId = orderItem.ProductId,ProductName = product.Name,@@ -725,7 +789,8 @@ namespace Grand.Web.Admin.ServicesIsDownloadActivated = orderItem.IsDownloadActivated};//picture- var orderItemPicture = await product.GetProductPicture(orderItem.Attributes, _productService, _pictureService);+ var orderItemPicture =+ await product.GetProductPicture(orderItem.Attributes, _productService, _pictureService);orderItemModel.PictureThumbnailUrl = await _pictureService.GetPictureUrl(orderItemPicture, 75);//license file@@ -737,6 +802,7 @@ namespace Grand.Web.Admin.ServicesorderItemModel.LicenseDownloadGuid = licenseDownload.DownloadGuid;}}+//vendorvar vendor = await _vendorService.GetVendorById(orderItem.VendorId);orderItemModel.VendorName = vendor != null ? vendor.Name : "";@@ -744,70 +810,90 @@ namespace Grand.Web.Admin.Services//unit priceorderItemModel.UnitPriceInclTaxValue = orderItem.UnitPriceInclTax;orderItemModel.UnitPriceExclTaxValue = orderItem.UnitPriceExclTax;- orderItemModel.UnitPriceInclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceInclTax, orderCurrency, _workContext.WorkingLanguage, true, true);- orderItemModel.UnitPriceExclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceExclTax, orderCurrency, _workContext.WorkingLanguage, false, true);+ orderItemModel.UnitPriceInclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceInclTax,+ orderCurrency, _workContext.WorkingLanguage, true, true);+ orderItemModel.UnitPriceExclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceExclTax,+ orderCurrency, _workContext.WorkingLanguage, false, true);//discountsorderItemModel.DiscountInclTaxValue = orderItem.DiscountAmountInclTax;orderItemModel.DiscountExclTaxValue = orderItem.DiscountAmountExclTax;- orderItemModel.DiscountInclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax, orderCurrency, _workContext.WorkingLanguage, true, true);- orderItemModel.DiscountExclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax, orderCurrency, _workContext.WorkingLanguage, false, true);+ orderItemModel.DiscountInclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax,+ orderCurrency, _workContext.WorkingLanguage, true, true);+ orderItemModel.DiscountExclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax,+ orderCurrency, _workContext.WorkingLanguage, false, true);//subtotalorderItemModel.SubTotalInclTaxValue = orderItem.PriceInclTax;orderItemModel.SubTotalExclTaxValue = orderItem.PriceExclTax;- orderItemModel.SubTotalInclTax = _priceFormatter.FormatPrice(orderItem.PriceInclTax, orderCurrency, _workContext.WorkingLanguage, false, false);- orderItemModel.SubTotalExclTax = _priceFormatter.FormatPrice(orderItem.PriceExclTax, orderCurrency, _workContext.WorkingLanguage, false, true);+ orderItemModel.SubTotalInclTax = _priceFormatter.FormatPrice(orderItem.PriceInclTax, orderCurrency,+ _workContext.WorkingLanguage, false, false);+ orderItemModel.SubTotalExclTax = _priceFormatter.FormatPrice(orderItem.PriceExclTax, orderCurrency,+ _workContext.WorkingLanguage, false, true);if (order.PrimaryCurrencyCode != order.CustomerCurrencyCode){- orderItemModel.UnitPriceInclTax += $" ({_priceFormatter.FormatPrice(orderItem.UnitPriceInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, true, true)})";- orderItemModel.UnitPriceExclTax += $" ({_priceFormatter.FormatPrice(orderItem.UnitPriceExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";- orderItemModel.DiscountInclTax += $" ({_priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, true, true)})";- orderItemModel.DiscountExclTax += $" ({_priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";- orderItemModel.SubTotalInclTax += $" ({_priceFormatter.FormatPrice(orderItem.PriceInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, false)})";- orderItemModel.SubTotalExclTax += $" ({_priceFormatter.FormatPrice(orderItem.PriceExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";+ orderItemModel.UnitPriceInclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.UnitPriceInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, true, true)})";+ orderItemModel.UnitPriceExclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.UnitPriceExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";+ orderItemModel.DiscountInclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, true, true)})";+ orderItemModel.DiscountExclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";+ orderItemModel.SubTotalInclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.PriceInclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, false)})";+ orderItemModel.SubTotalExclTax +=+ $" ({_priceFormatter.FormatPrice(orderItem.PriceExclTax / order.CurrencyRate, primaryStoreCurrency, _workContext.WorkingLanguage, false, true)})";}// commissionorderItemModel.CommissionValue = orderItem.Commission;- orderItemModel.Commission = _priceFormatter.FormatPrice(orderItem.Commission, orderCurrency, _workContext.WorkingLanguage, false, false);+ orderItemModel.Commission = _priceFormatter.FormatPrice(orderItem.Commission, orderCurrency,+ _workContext.WorkingLanguage, false, false);orderItemModel.AttributeInfo = orderItem.AttributeDescription;if (product.IsRecurring)- orderItemModel.RecurringInfo = string.Format(_translationService.GetResource("Admin.Orders.Products.RecurringPeriod"),- product.RecurringCycleLength,- product.RecurringCyclePeriodId.GetTranslationEnum(_translationService, _workContext),- product.RecurringTotalCycles);+ orderItemModel.RecurringInfo = string.Format(+ _translationService.GetResource("Admin.Orders.Products.RecurringPeriod"),+ product.RecurringCycleLength,+ product.RecurringCyclePeriodId.GetTranslationEnum(_translationService, _workContext),+ product.RecurringTotalCycles);//merchandise returns- orderItemModel.MerchandiseReturnIds = (await _merchandiseReturnService.SearchMerchandiseReturns(orderItemId: orderItem.Id))+ orderItemModel.MerchandiseReturnIds =+ (await _merchandiseReturnService.SearchMerchandiseReturns(orderItemId: orderItem.Id)).Select(rr => rr.Id).ToList();//gift vouchers- orderItemModel.PurchasedGiftVoucherIds = (await _giftVoucherService.GetGiftVouchersByPurchasedWithOrderItemId(orderItem.Id))+ orderItemModel.PurchasedGiftVoucherIds =+ (await _giftVoucherService.GetGiftVouchersByPurchasedWithOrderItemId(orderItem.Id)).Select(gc => gc.Id).ToList();model.Items.Add(orderItemModel);}}+model.HasDownloadableProducts = hasDownloadableItems;+#endregion}public virtual async Task<OrderModel.AddOrderProductModel> PrepareAddOrderProductModel(Order order){- var model = new OrderModel.AddOrderProductModel- {+ var model = new OrderModel.AddOrderProductModel {OrderId = order.Id,OrderNumber = order.OrderNumber,//product types- AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(_translationService, _workContext, false).ToList()+ AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(_translationService, _workContext, false)+ .ToList()};- model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "0" });+ model.AvailableProductTypes.Insert(0,+ new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "0" });return await Task.FromResult(model);}- public virtual async Task<OrderModel.AddOrderProductModel.ProductDetailsModel> PrepareAddProductToOrderModel(Order order, string productId)+ public virtual async Task<OrderModel.AddOrderProductModel.ProductDetailsModel> PrepareAddProductToOrderModel(+ Order order, string productId){var product = await _productService.GetProductById(productId);if (product == null)@@ -816,13 +902,14 @@ namespace Grand.Web.Admin.Servicesvar customer = await _customerService.GetCustomerById(order.CustomerId);var currency = await _currencyService.GetCurrencyByCode(order.CustomerCurrencyCode);var presetQty = 1;- var presetPrice = (await _pricingService.GetFinalPrice(product, customer, currency, 0, true, presetQty)).finalPrice;+ var presetPrice = (await _pricingService.GetFinalPrice(product, customer, currency, 0, true, presetQty))+ .finalPrice;var productPrice = await _taxService.GetProductPrice(product, presetPrice, true, customer);var presetPriceInclTax = productPrice.productprice;- var presetPriceExclTax = (await _taxService.GetProductPrice(product, presetPrice, false, customer)).productprice;+ var presetPriceExclTax =+ (await _taxService.GetProductPrice(product, presetPrice, false, customer)).productprice;- var model = new OrderModel.AddOrderProductModel.ProductDetailsModel- {+ var model = new OrderModel.AddOrderProductModel.ProductDetailsModel {ProductId = product.Id,OrderId = order.Id,OrderNumber = order.OrderNumber,@@ -838,9 +925,9 @@ namespace Grand.Web.Admin.Servicesvar attributes = product.ProductAttributeMappings;foreach (var attribute in attributes){- var productAttribute = await _productAttributeService.GetProductAttributeById(attribute.ProductAttributeId);- var attributeModel = new OrderModel.AddOrderProductModel.ProductAttributeModel- {+ var productAttribute =+ await _productAttributeService.GetProductAttributeById(attribute.ProductAttributeId);+ var attributeModel = new OrderModel.AddOrderProductModel.ProductAttributeModel {Id = attribute.Id,ProductAttributeId = attribute.ProductAttributeId,Name = productAttribute.Name,@@ -855,8 +942,7 @@ namespace Grand.Web.Admin.Servicesvar attributeValues = attribute.ProductAttributeValues;foreach (var attributeValue in attributeValues){- var attributeValueModel = new OrderModel.AddOrderProductModel.ProductAttributeValueModel- {+ var attributeValueModel = new OrderModel.AddOrderProductModel.ProductAttributeValueModel {Id = attributeValue.Id,Name = attributeValue.Name,IsPreSelected = attributeValue.IsPreSelected@@ -867,18 +953,20 @@ namespace Grand.Web.Admin.Servicesmodel.ProductAttributes.Add(attributeModel);}+//gift vouchermodel.GiftVoucher.IsGiftVoucher = product.IsGiftVoucher;if (model.GiftVoucher.IsGiftVoucher){model.GiftVoucher.GiftVoucherType = product.GiftVoucherTypeId;}+return model;}+public virtual async Task<OrderAddressModel> PrepareOrderAddressModel(Order order, Address address){- var model = new OrderAddressModel- {+ var model = new OrderAddressModel {OrderId = order.Id,Address = await address.ToModel(_countryService)};@@ -912,19 +1000,25 @@ namespace Grand.Web.Admin.Servicesmodel.Address.AddressTypeEnabled = _addressSettings.AddressTypeEnabled;//countries- model.Address.AvailableCountries.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });+ model.Address.AvailableCountries.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });foreach (var c in await _countryService.GetAllCountries(showHidden: true))- model.Address.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id, Selected = c.Id == address.CountryId });+ model.Address.AvailableCountries.Add(new SelectListItem+ { Text = c.Name, Value = c.Id, Selected = c.Id == address.CountryId });//states- var states = !string.IsNullOrEmpty(address.CountryId) ? (await _countryService.GetCountryById(address.CountryId))?.StateProvinces : new List<StateProvince>();+ var states = !string.IsNullOrEmpty(address.CountryId)+ ? (await _countryService.GetCountryById(address.CountryId))?.StateProvinces+ : new List<StateProvince>();if (states?.Count > 0){foreach (var s in states)- model.Address.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id, Selected = s.Id == address.StateProvinceId });+ model.Address.AvailableStates.Add(new SelectListItem+ { Text = s.Name, Value = s.Id, Selected = s.Id == address.StateProvinceId });}//customer attribute services- await model.Address.PrepareCustomAddressAttributes(address, _addressAttributeService, _addressAttributeParser);+ await model.Address.PrepareCustomAddressAttributes(address, _addressAttributeService,+ _addressAttributeParser);return model;}@@ -934,11 +1028,10 @@ namespace Grand.Web.Admin.Services//order notesvar orderNoteModels = new List<OrderModel.OrderNote>();foreach (var orderNote in (await _orderService.GetOrderNotes(order.Id))- .OrderByDescending(on => on.CreatedOnUtc))+ .OrderByDescending(on => on.CreatedOnUtc)){var download = await _downloadService.GetDownloadById(orderNote.DownloadId);- orderNoteModels.Add(new OrderModel.OrderNote- {+ orderNoteModels.Add(new OrderModel.OrderNote {Id = orderNote.Id,OrderId = order.Id,DownloadId = string.IsNullOrEmpty(orderNote.DownloadId) ? "" : orderNote.DownloadId,@@ -949,13 +1042,14 @@ namespace Grand.Web.Admin.ServicesCreatedByCustomer = orderNote.CreatedByCustomer});}+return orderNoteModels;}- public virtual async Task InsertOrderNote(Order order, string downloadId, bool displayToCustomer, string message)+ public virtual async Task InsertOrderNote(Order order, string downloadId, bool displayToCustomer,+ string message){- var orderNote = new OrderNote- {+ var orderNote = new OrderNote {DisplayToCustomer = displayToCustomer,Note = message,DownloadId = downloadId,@@ -998,15 +1092,16 @@ namespace Grand.Web.Admin.Services_translationService.GetResource("ActivityLog.EditOrder"), orderId);return Task.CompletedTask;}- public virtual async Task<Address> UpdateOrderAddress(Order order, Address address, OrderAddressModel model, List<CustomAttribute> customAttributes)++ public virtual async Task<Address> UpdateOrderAddress(Order order, Address address, OrderAddressModel model,+ List<CustomAttribute> customAttributes){address = model.Address.ToEntity(address);address.Attributes = customAttributes;await _orderService.UpdateOrder(order);//add a note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = "Address has been edited",DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -1015,21 +1110,13 @@ namespace Grand.Web.Admin.Services_ = LogEditOrder(order.Id);return address;}- public virtual async Task<IList<string>> AddProductToOrderDetails(string orderId, string productId, IFormCollection form)++ public virtual async Task<IList<string>> AddProductToOrderDetails(AddProductToOrderModel model){- var order = await _orderService.GetOrderById(orderId);- var product = await _productService.GetProductById(productId);+ var order = await _orderService.GetOrderById(model.OrderId);+ var product = await _productService.GetProductById(model.ProductId);var customer = await _customerService.GetCustomerById(order.CustomerId);- //save order item-- //basic properties- double.TryParse(form["UnitPriceInclTax"], out var unitPriceInclTax);- double.TryParse(form["UnitPriceExclTax"], out var unitPriceExclTax);- int.TryParse(form["Quantity"], out var quantity);- int.TryParse(form["TaxRate"], out var taxRate);- //attributes- //warningsvar warnings = new List<string>();var customattributes = new List<CustomAttribute>();@@ -1038,100 +1125,85 @@ namespace Grand.Web.Admin.Servicesvar attributes = product.ProductAttributeMappings;foreach (var attribute in attributes){- var controlId = $"product_attribute_{attribute.Id}";switch (attribute.AttributeControlTypeId){case AttributeControlType.DropdownList:case AttributeControlType.RadioList:case AttributeControlType.ColorSquares:case AttributeControlType.ImageSquares:+ {+ var ctrlAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (!string.IsNullOrEmpty(ctrlAttributes)){- form.TryGetValue(controlId, out var ctrlAttributes);- if (!string.IsNullOrEmpty(ctrlAttributes))- {- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, ctrlAttributes).ToList();- }+ customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,+ attribute, ctrlAttributes).ToList();}+ }break;case AttributeControlType.Checkboxes:+ {+ var cblAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (!string.IsNullOrEmpty(cblAttributes)){- form.TryGetValue(controlId, out var ctrlAttributes);- if (!string.IsNullOrEmpty(ctrlAttributes))+ foreach (var item in cblAttributes.ToString()+ .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)){- foreach (var item in ctrlAttributes.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))- {- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, item).ToList();- }+ customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(+ customattributes,+ attribute, item).ToList();}}+ }break;case AttributeControlType.ReadonlyCheckboxes:+ {+ //load read-only (already server-side selected) values+ var attributeValues = attribute.ProductAttributeValues;+ foreach (var selectedAttributeId in attributeValues+ .Where(v => v.IsPreSelected)+ .Select(v => v.Id)+ .ToList()){- //load read-only (already server-side selected) values- var attributeValues = attribute.ProductAttributeValues;- foreach (var selectedAttributeId in attributeValues- .Where(v => v.IsPreSelected)- .Select(v => v.Id)- .ToList())- {- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, selectedAttributeId).ToList();- }+ customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,+ attribute, selectedAttributeId).ToList();}+ }break;case AttributeControlType.TextBox:case AttributeControlType.MultilineTextbox:+ {+ var ctrlAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (!string.IsNullOrEmpty(ctrlAttributes)){- form.TryGetValue(controlId, out var ctrlAttributes);- if (!string.IsNullOrEmpty(ctrlAttributes))- {- var enteredText = ctrlAttributes.ToString().Trim();- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, enteredText).ToList();- }- }- break;- case AttributeControlType.Datepicker:- {- form.TryGetValue(controlId + "_day", out var day);- form.TryGetValue(controlId + "_month", out var month);- form.TryGetValue(controlId + "_year", out var year);- DateTime? selectedDate = null;- try- {- selectedDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));- }- catch { }- if (selectedDate.HasValue)- {- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, selectedDate.Value.ToString("D")).ToList();- }+ var enteredText = ctrlAttributes.ToString().Trim();+ customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,+ attribute, enteredText).ToList();}+ }break;case AttributeControlType.FileUpload:+ {+ var guid = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ Guid.TryParse(guid, out Guid downloadGuid);+ var download = await _downloadService.GetDownloadByGuid(downloadGuid);+ if (download != null){- form.TryGetValue(controlId, out var guid);- Guid.TryParse(guid, out Guid downloadGuid);- var download = await _downloadService.GetDownloadByGuid(downloadGuid);- if (download != null)- {- customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,- attribute, download.DownloadGuid.ToString()).ToList();- }+ customattributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customattributes,+ attribute, download.DownloadGuid.ToString()).ToList();}+ }break;}}+//validate conditional attributes (if specified)foreach (var attribute in attributes){var conditionMet = product.IsConditionMet(attribute, customattributes);if (conditionMet.HasValue && !conditionMet.Value){- customattributes = Domain.Catalog.ProductExtensions.RemoveProductAttribute(customattributes, attribute).ToList();+ customattributes = Domain.Catalog.ProductExtensions+ .RemoveProductAttribute(customattributes, attribute).ToList();}}@@ -1139,40 +1211,13 @@ namespace Grand.Web.Admin.Services#region Gift vouchers- var recipientName = "";- var recipientEmail = "";- var senderName = "";- var senderEmail = "";- var giftVoucherMessage = "";+ var recipientName = model.Giftvoucher?.RecipientName;+ var recipientEmail = model.Giftvoucher?.RecipientEmail;+ var senderName = model.Giftvoucher?.SenderName;+ var senderEmail = model.Giftvoucher?.SenderEmail;+ var giftVoucherMessage = model.Giftvoucher?.Message;if (product.IsGiftVoucher){- foreach (var formKey in form.Keys)- {- if (formKey.Equals("giftvoucher.RecipientName", StringComparison.OrdinalIgnoreCase))- {- recipientName = form[formKey];- continue;- }- if (formKey.Equals("giftvoucher.RecipientEmail", StringComparison.OrdinalIgnoreCase))- {- recipientEmail = form[formKey];- continue;- }- if (formKey.Equals("giftvoucher.SenderName", StringComparison.OrdinalIgnoreCase))- {- senderName = form[formKey];- continue;- }- if (formKey.Equals("giftvoucher.SenderEmail", StringComparison.OrdinalIgnoreCase))- {- senderEmail = form[formKey];- continue;- }- if (formKey.Equals("giftvoucher.Message", StringComparison.OrdinalIgnoreCase))- {- giftVoucherMessage = form[formKey];- }- }customattributes = GiftVoucherExtensions.AddGiftVoucherAttribute(customattributes,recipientName, recipientEmail, senderName, senderEmail, giftVoucherMessage).ToList();}@@ -1182,39 +1227,42 @@ namespace Grand.Web.Admin.Services//warningsvar shoppingCartItem = new ShoppingCartItem {ShoppingCartTypeId = ShoppingCartType.ShoppingCart,- Quantity = quantity,+ Quantity = model.Quantity,WarehouseId = product.WarehouseId,Attributes = customattributes};- warnings.AddRange(await _shoppingCartValidator.GetShoppingCartItemAttributeWarnings(customer, product, shoppingCartItem));- warnings.AddRange(await _shoppingCartValidator.GetShoppingCartItemGiftVoucherWarnings(customer, product, shoppingCartItem));+ warnings.AddRange(+ await _shoppingCartValidator.GetShoppingCartItemAttributeWarnings(customer, product, shoppingCartItem));+ warnings.AddRange(+ await _shoppingCartValidator.GetShoppingCartItemGiftVoucherWarnings(customer, product,+ shoppingCartItem));if (warnings.Count == 0){//no errorsvar productAttributeFormatter = _serviceProvider.GetRequiredService<IProductAttributeFormatter>();//attributes- var attributeDescription = await productAttributeFormatter.FormatAttributes(product, customattributes, customer);+ var attributeDescription =+ await productAttributeFormatter.FormatAttributes(product, customattributes, customer);//save item- var orderItem = new OrderItem- {+ var orderItem = new OrderItem {OrderItemGuid = Guid.NewGuid(),ProductId = product.Id,VendorId = product.VendorId,WarehouseId = product.WarehouseId,Sku = product.FormatSku(customattributes),SeId = order.SeId,- UnitPriceInclTax = unitPriceInclTax,- UnitPriceExclTax = unitPriceExclTax,- PriceInclTax = Math.Round(unitPriceInclTax * quantity, 2),- PriceExclTax = Math.Round(unitPriceExclTax * quantity, 2),- TaxRate = taxRate,+ UnitPriceInclTax = model.UnitPriceExclTax,+ UnitPriceExclTax = model.UnitPriceInclTax,+ PriceInclTax = Math.Round(model.UnitPriceInclTax * model.Quantity, 2),+ PriceExclTax = Math.Round(model.UnitPriceExclTax * model.Quantity, 2),+ TaxRate = model.TaxRate,OriginalProductCost = await _pricingService.GetProductCost(product, customattributes),AttributeDescription = attributeDescription,Attributes = customattributes,- Quantity = quantity,- OpenQty = quantity,+ Quantity = model.Quantity,+ OpenQty = model.Quantity,DiscountAmountInclTax = 0,DiscountAmountExclTax = 0,DownloadCount = 0,@@ -1224,25 +1272,29 @@ namespace Grand.Web.Admin.ServicesCreatedOnUtc = DateTime.UtcNow};- await _mediator.Send(new InsertOrderItemCommand { Order = order, OrderItem = orderItem, Product = product });+ await _mediator.Send(new InsertOrderItemCommand+ { Order = order, OrderItem = orderItem, Product = product });_ = LogEditOrder(order.Id);-}+return warnings;}public virtual async Task<IList<Order>> PrepareOrders(OrderListModel model){- DateTime? startDateValue = model.StartDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);+ DateTime? startDateValue = model.StartDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);- DateTime? endDateValue = model.EndDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);+ DateTime? endDateValue = model.EndDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);int? orderStatus = model.OrderStatusId > 0 ? model.OrderStatusId : null;PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)model.PaymentStatusId : null;- ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)model.ShippingStatusId : null;+ ShippingStatus? shippingStatus =+ model.ShippingStatusId > 0 ? (ShippingStatus?)model.ShippingStatusId : null;var filterByProductId = "";var product = await _productService.GetProductById(model.ProductId);@@ -1290,6 +1342,7 @@ namespace Grand.Web.Admin.Servicesif (tag != null)existingOrderTags.Add(tag.Name);}+var newOrderTags = ParseOrderTagsToList(orderTags);// compare@@ -1326,6 +1379,5 @@ namespace Grand.Web.Admin.Services}}}-}-}+}\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.csindex af2d2e6f2..9ab0c0e51 100644--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs@@ -2061,7 +2061,7 @@ namespace Grand.Web.Admin.Services}return model;}- public virtual async Task UpdateProductAttributeConditionModel(Product product, ProductAttributeMapping productAttributeMapping, ProductAttributeConditionModel model, Dictionary<string, string> form)+ public virtual async Task UpdateProductAttributeConditionModel(Product product, ProductAttributeMapping productAttributeMapping, ProductAttributeConditionModel model){var customAttributes = new List<CustomAttribute>();if (model.EnableCondition)@@ -2069,7 +2069,6 @@ namespace Grand.Web.Admin.Servicesvar attribute = product.ProductAttributeMappings.FirstOrDefault(x => x.Id == model.SelectedProductAttributeId);if (attribute != null){- var controlId = $"product_attribute_{attribute.Id}";switch (attribute.AttributeControlTypeId){case AttributeControlType.DropdownList:@@ -2077,7 +2076,7 @@ namespace Grand.Web.Admin.Servicescase AttributeControlType.ColorSquares:case AttributeControlType.ImageSquares:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customAttributes,@@ -2092,7 +2091,7 @@ namespace Grand.Web.Admin.Servicesbreak;case AttributeControlType.Checkboxes:{- form.TryGetValue(controlId, out var cblAttributes);+ var cblAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){var anyValueSelected = false;@@ -2347,7 +2346,7 @@ namespace Grand.Web.Admin.Services}return model;}- public virtual async Task<IList<string>> InsertOrUpdateProductAttributeCombinationPopup(Product product, ProductAttributeCombinationModel model, Dictionary<string, string> form)+ public virtual async Task<IList<string>> InsertOrUpdateProductAttributeCombinationPopup(Product product, ProductAttributeCombinationModel model){var customAttributes = new List<CustomAttribute>();var warnings = new List<string>();@@ -2403,7 +2402,6 @@ namespace Grand.Web.Admin.Services}foreach (var attribute in attributes){- var controlId = $"product_attribute_{attribute.Id}";switch (attribute.AttributeControlTypeId){case AttributeControlType.DropdownList:@@ -2411,7 +2409,7 @@ namespace Grand.Web.Admin.Servicescase AttributeControlType.ColorSquares:case AttributeControlType.ImageSquares:{- form.TryGetValue(controlId, out var ctrlAttributes);+ var ctrlAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(ctrlAttributes)){customAttributes = Domain.Catalog.ProductExtensions.AddProductAttribute(customAttributes,@@ -2421,7 +2419,7 @@ namespace Grand.Web.Admin.Servicesbreak;case AttributeControlType.Checkboxes:{- form.TryGetValue(controlId, out var cblAttributes);+ var cblAttributes = model.SelectedAttributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;if (!string.IsNullOrEmpty(cblAttributes)){foreach (var item in cblAttributes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))diff --git a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.csindex c53c486d6..34a3e8226 100644--- a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs@@ -81,7 +81,8 @@ namespace Grand.Web.Admin.Services_shippingProviderSettings = shippingProviderSettings;}- public virtual async Task<ShipmentModel> PrepareShipmentModel(Shipment shipment, bool prepareProducts, bool prepareShipmentEvent = false)+ public virtual async Task<ShipmentModel> PrepareShipmentModel(Shipment shipment, bool prepareProducts,+ bool prepareShipmentEvent = false){//measuresvar baseWeight = await _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId);@@ -98,10 +99,14 @@ namespace Grand.Web.Admin.ServicesOrderCode = order != null ? order.Code : "",TrackingNumber = shipment.TrackingNumber,TotalWeight = shipment.TotalWeight.HasValue ? $"{shipment.TotalWeight:F2} [{baseWeightIn}]" : "",- ShippedDate = shipment.ShippedDateUtc.HasValue ? _dateTimeService.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc) : new DateTime?(),+ ShippedDate = shipment.ShippedDateUtc.HasValue+ ? _dateTimeService.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc)+ : new DateTime?(),ShippedDateUtc = shipment.ShippedDateUtc,CanShip = !shipment.ShippedDateUtc.HasValue,- DeliveryDate = shipment.DeliveryDateUtc.HasValue ? _dateTimeService.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc) : new DateTime?(),+ DeliveryDate = shipment.DeliveryDateUtc.HasValue+ ? _dateTimeService.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc)+ : new DateTime?(),DeliveryDateUtc = shipment.DeliveryDateUtc,CanDeliver = shipment.ShippedDateUtc.HasValue && !shipment.DeliveryDateUtc.HasValue,AdminComment = shipment.AdminComment,@@ -112,7 +117,6 @@ namespace Grand.Web.Admin.Services{foreach (var shipmentItem in shipment.ShipmentItems){-var orderItem = order.OrderItems.FirstOrDefault(x => x.Id == shipmentItem.OrderItemId);if (orderItem == null)continue;@@ -139,7 +143,9 @@ namespace Grand.Web.Admin.ServicesAttributeInfo = orderItem.AttributeDescription,ShippedFromWarehouse = warehouse?.Name,ShipSeparately = product.ShipSeparately,- ItemWeight = orderItem.ItemWeight.HasValue ? $"{orderItem.ItemWeight:F2} [{baseWeightIn}]" : "",+ ItemWeight = orderItem.ItemWeight.HasValue+ ? $"{orderItem.ItemWeight:F2} [{baseWeightIn}]"+ : "",ItemDimensions =$"{product.Length:F2} x {product.Width:F2} x {product.Height:F2} [{baseDimensionIn}]",QuantityOrdered = qtyOrdered,@@ -155,7 +161,8 @@ namespace Grand.Web.Admin.Servicesif (prepareShipmentEvent && !string.IsNullOrEmpty(shipment.TrackingNumber)){- var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(order.ShippingRateProviderSystemName);+ var srcm = _shippingService.LoadShippingRateCalculationProviderBySystemName(+ order.ShippingRateProviderSystemName);if (srcm != null &&srcm.IsShippingRateMethodActive(_shippingProviderSettings)){@@ -171,9 +178,11 @@ namespace Grand.Web.Admin.Servicesforeach (var shipmentEvent in shipmentEvents){var shipmentStatusEventModel = new ShipmentModel.ShipmentStatusEventModel();- var shipmentEventCountry = await _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode);+ var shipmentEventCountry =+ await _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode);shipmentStatusEventModel.Country = shipmentEventCountry != null- ? shipmentEventCountry.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id)+ ? shipmentEventCountry.GetTranslation(x => x.Name,+ _workContext.WorkingLanguage.Id): shipmentEvent.CountryCode;shipmentStatusEventModel.Date = shipmentEvent.Date;shipmentStatusEventModel.EventName = shipmentEvent.EventName;@@ -228,6 +237,7 @@ namespace Grand.Web.Admin.Services}}}+return _qty.Count > 0 ? _qty.Min() : 0;}@@ -236,7 +246,7 @@ namespace Grand.Web.Admin.Services//shipment notesvar shipmentNoteModels = new List<ShipmentModel.ShipmentNote>();foreach (var shipmentNote in (await _shipmentService.GetShipmentNotes(shipment.Id))- .OrderByDescending(on => on.CreatedOnUtc))+ .OrderByDescending(on => on.CreatedOnUtc)){var download = await _downloadService.GetDownloadById(shipmentNote.DownloadId);shipmentNoteModels.Add(new ShipmentModel.ShipmentNote {@@ -250,10 +260,12 @@ namespace Grand.Web.Admin.ServicesCreatedByCustomer = shipmentNote.CreatedByCustomer});}+return shipmentNoteModels;}- public virtual async Task InsertShipmentNote(Shipment shipment, string downloadId, bool displayToCustomer, string message)+ public virtual async Task InsertShipmentNote(Shipment shipment, string downloadId, bool displayToCustomer,+ string message){var shipmentNote = new ShipmentNote {DisplayToCustomer = displayToCustomer,@@ -289,16 +301,21 @@ namespace Grand.Web.Admin.Servicespublic virtual Task LogShipment(string shipmentId, string message){_ = _customerActivityService.InsertActivity("EditShipment", shipmentId,- _workContext.CurrentCustomer, _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString(), message);+ _workContext.CurrentCustomer, _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString(),+ message);return Task.CompletedTask;}- public virtual async Task<(IEnumerable<Shipment> shipments, int totalCount)> PrepareShipments(ShipmentListModel model, int pageIndex, int pageSize)++ public virtual async Task<(IEnumerable<Shipment> shipments, int totalCount)> PrepareShipments(+ ShipmentListModel model, int pageIndex, int pageSize){- DateTime? startDateValue = model.StartDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);+ DateTime? startDateValue = model.StartDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);- DateTime? endDateValue = model.EndDate == null ? null- : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);+ DateTime? endDateValue = model.EndDate == null+ ? null+ : _dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone).AddDays(1);//load shipmentsvar shipments = await _shipmentService.GetAllShipments(@@ -317,6 +334,7 @@ namespace Grand.Web.Admin.Servicesreturn (shipments.ToList(), shipments.TotalCount);}+public virtual async Task<ShipmentListModel> PrepareShipmentListModel(){var model = new ShipmentListModel();@@ -328,12 +346,14 @@ namespace Grand.Web.Admin.Servicesmodel.AvailableStates.Add(new SelectListItem { Text = "*", Value = "" });//warehouses- model.AvailableWarehouses.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });+ model.AvailableWarehouses.Add(new SelectListItem+ { Text = _translationService.GetResource("Admin.Common.All"), Value = "" });foreach (var w in await _warehouseService.GetAllWarehouses())model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id });return model;}+public virtual async Task<ShipmentModel> PrepareShipmentModel(Order order){var model = new ShipmentModel {@@ -395,19 +415,19 @@ namespace Grand.Web.Admin.Services//multiple warehouses supportedshipmentItemModel.AllowToChooseWarehouse = true;foreach (var pwi in product.ProductWarehouseInventory- .OrderBy(w => w.WarehouseId).ToList())+ .OrderBy(w => w.WarehouseId).ToList()){-var warehouse = await _warehouseService.GetWarehouseById(pwi.WarehouseId);if (warehouse != null){- shipmentItemModel.AvailableWarehouses.Add(new ShipmentModel.ShipmentItemModel.WarehouseInfo {- WarehouseId = warehouse.Id,- WarehouseName = warehouse.Name,- WarehouseCode = warehouse.Code,- StockQuantity = pwi.StockQuantity,- ReservedQuantity = pwi.ReservedQuantity- });+ shipmentItemModel.AvailableWarehouses.Add(+ new ShipmentModel.ShipmentItemModel.WarehouseInfo {+ WarehouseId = warehouse.Id,+ WarehouseName = warehouse.Name,+ WarehouseCode = warehouse.Code,+ StockQuantity = pwi.StockQuantity,+ ReservedQuantity = pwi.ReservedQuantity+ });}}}@@ -437,19 +457,19 @@ namespace Grand.Web.Admin.Servicesif (comb != null){foreach (var pwi in comb.WarehouseInventory- .OrderBy(w => w.WarehouseId).ToList())+ .OrderBy(w => w.WarehouseId).ToList()){-var warehouse = await _warehouseService.GetWarehouseById(pwi.WarehouseId);if (warehouse != null){- shipmentItemModel.AvailableWarehouses.Add(new ShipmentModel.ShipmentItemModel.WarehouseInfo {- WarehouseId = warehouse.Id,- WarehouseName = warehouse.Name,- StockQuantity = pwi.StockQuantity,- WarehouseCode = warehouse.Code,- ReservedQuantity = pwi.ReservedQuantity- });+ shipmentItemModel.AvailableWarehouses.Add(+ new ShipmentModel.ShipmentItemModel.WarehouseInfo {+ WarehouseId = warehouse.Id,+ WarehouseName = warehouse.Name,+ StockQuantity = pwi.StockQuantity,+ WarehouseCode = warehouse.Code,+ ReservedQuantity = pwi.ReservedQuantity+ });}}}@@ -494,13 +514,14 @@ namespace Grand.Web.Admin.Servicesvar warehouses = await _warehouseService.GetAllWarehouses();foreach (var warehouse in warehouses){- shipmentItemModel.AvailableWarehouses.Add(new ShipmentModel.ShipmentItemModel.WarehouseInfo {- WarehouseId = warehouse.Id,- WarehouseName = warehouse.Name,- WarehouseCode = warehouse.Code,- StockQuantity = await GetStockQty(product, warehouse.Id),- ReservedQuantity = await GetReservedQty(product, warehouse.Id)- });+ shipmentItemModel.AvailableWarehouses.Add(+ new ShipmentModel.ShipmentItemModel.WarehouseInfo {+ WarehouseId = warehouse.Id,+ WarehouseName = warehouse.Name,+ WarehouseCode = warehouse.Code,+ StockQuantity = await GetStockQty(product, warehouse.Id),+ ReservedQuantity = await GetReservedQty(product, warehouse.Id)+ });}}}@@ -508,6 +529,7 @@ namespace Grand.Web.Admin.Servicesmodel.Items.Add(shipmentItemModel);}+return model;}@@ -518,27 +540,30 @@ namespace Grand.Web.Admin.Servicesvar product = await _productService.GetProductById(item.ProductId);if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStock){- var stock = _stockQuantityService.GetTotalStockQuantity(product, useReservedQuantity: false, warehouseId: item.WarehouseId);+ var stock = _stockQuantityService.GetTotalStockQuantity(product, useReservedQuantity: false,+ warehouseId: item.WarehouseId);if (stock - item.Quantity < 0)return (false, $"Out of stock for product {product.Name}");}+if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes){var combination = product.FindProductAttributeCombination(item.Attributes);if (combination == null)return (false, $"Can't find combination for product {product.Name}");- var stock = _stockQuantityService.GetTotalStockQuantityForCombination(product, combination, useReservedQuantity: false, warehouseId: item.WarehouseId);+ var stock = _stockQuantityService.GetTotalStockQuantityForCombination(product, combination,+ useReservedQuantity: false, warehouseId: item.WarehouseId);if (stock - item.Quantity < 0)return (false, $"Out of stock for product {product.Name}");}-}return (true, string.Empty);}- public virtual async Task<(Shipment shipment, double? totalWeight)> PrepareShipment(Order order, IEnumerable<OrderItem> orderItems, IFormCollection form)+ public virtual async Task<(Shipment shipment, double? totalWeight)> PrepareShipment(Order order,+ IEnumerable<OrderItem> orderItems, AddShipmentModel model){Shipment shipment = null;double? totalWeight = null;@@ -552,59 +577,45 @@ namespace Grand.Web.Admin.Servicesif (orderItem.OpenQty <= 0)continue;- var qtyToAdd = 0; //parse quantity- foreach (var formKey in form.Keys)- if (formKey.Equals($"qtyToAdd{orderItem.Id}", StringComparison.OrdinalIgnoreCase))- {- _ = int.TryParse(form[formKey], out qtyToAdd);- break;- }+ var shipmentItemModel = model.Items.FirstOrDefault(x => x.OrderItemId == orderItem.Id);+ if (shipmentItemModel == null)+ continue;var product = await _productService.GetProductById(orderItem.ProductId);var warehouseId = "";- if (product != null && (((product.ManageInventoryMethodId == ManageInventoryMethod.ManageStock || product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes) &&- product.UseMultipleWarehouses) || product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByBundleProducts))+ if (product != null && (((product.ManageInventoryMethodId == ManageInventoryMethod.ManageStock ||+ product.ManageInventoryMethodId ==+ ManageInventoryMethod.ManageStockByAttributes) &&+ product.UseMultipleWarehouses) || product.ManageInventoryMethodId ==+ ManageInventoryMethod.ManageStockByBundleProducts)){//multiple warehouses supported//warehouse is chosen by a store owner- foreach (var formKey in form.Keys)- if (formKey.Equals($"warehouse_{orderItem.Id}", StringComparison.OrdinalIgnoreCase))- {- warehouseId = form[formKey];- break;- }+ warehouseId = shipmentItemModel.WarehouseId;}else{//multiple warehouses are not supportedwarehouseId = orderItem.WarehouseId;}-- foreach (var formKey in form.Keys)- if (formKey.Equals($"qtyToAdd{orderItem.Id}", StringComparison.OrdinalIgnoreCase))- {- _ = int.TryParse(form[formKey], out qtyToAdd);- break;- }-//validate quantity- if (qtyToAdd <= 0)+ if (shipmentItemModel.QuantityToAdd <= 0)continue;- if (qtyToAdd > orderItem.OpenQty)- qtyToAdd = orderItem.OpenQty;+ if (shipmentItemModel.QuantityToAdd > orderItem.OpenQty)+ shipmentItemModel.QuantityToAdd = orderItem.OpenQty;//ok. we have at least one item. create a shipment (if it does not exist)- var orderItemTotalWeight = orderItem.ItemWeight * qtyToAdd;+ var orderItemTotalWeight = orderItem.ItemWeight * shipmentItemModel.QuantityToAdd;if (orderItemTotalWeight.HasValue){- if (!totalWeight.HasValue)- totalWeight = 0;+ totalWeight ??= 0;totalWeight += orderItemTotalWeight.Value;}+if (shipment == null){- var trackingNumber = form["TrackingNumber"];- var adminComment = form["AdminComment"];+ var trackingNumber = model.TrackingNumber;+ var adminComment = model.AdminComment;shipment = new Shipment {OrderId = order.Id,SeId = order.SeId,@@ -621,17 +632,19 @@ namespace Grand.Web.Admin.Servicesshipment.VendorId = _workContext.CurrentVendor.Id;}}+//create a shipment itemvar shipmentItem = new ShipmentItem {ProductId = orderItem.ProductId,OrderItemId = orderItem.Id,- Quantity = qtyToAdd,+ Quantity = shipmentItemModel.QuantityToAdd,WarehouseId = warehouseId,Attributes = orderItem.Attributes};shipment.ShipmentItems.Add(shipmentItem);}+return (shipment, totalWeight);}}-}+}\ No newline at end of file