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
feat(arch001): add Addresses region
KrzysztofPajake61419752bea
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseOrderManagementControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseOrderManagementControllerTests.csindex a9bd177e8..a555a8883 100644--- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseOrderManagementControllerTests.cs+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseOrderManagementControllerTests.cs@@ -262,4 +262,16 @@ public class BaseOrderManagementControllerTestsAssert.AreEqual("Edit", redirect?.ActionName);Assert.AreEqual("o1", redirect?.RouteValues["id"]);}++ [TestMethod]+ public async Task AddressEditGet_ScopeDenies_RedirectsToList()+ {+ var order = new Order { Id = "o1", BillingAddress = new Grand.Domain.Common.Address { Id = "a1" } };+ _orderServiceMock.Setup(s => s.GetOrderById("o1")).ReturnsAsync(order);+ _scopeMock.Setup(s => s.HasAccess(order)).ReturnsAsync(false);++ var result = await _controller.AddressEdit("a1", "o1", true);++ Assert.AreEqual("List", (result as RedirectToActionResult)?.ActionName);+ }}diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseOrderManagementController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseOrderManagementController.csindex 85a685123..970ef4b77 100644--- a/src/Web/Grand.Web.AdminShared/Controllers/BaseOrderManagementController.cs+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseOrderManagementController.cs@@ -6,6 +6,7 @@ using Grand.Domain.Orders;using Grand.Domain.Permissions;using Grand.Infrastructure;using Grand.Mediator;+using Grand.Web.AdminShared.Extensions;using Grand.Web.AdminShared.Interfaces;using Grand.Web.AdminShared.Models.Orders;using Grand.Web.Common.Security.Authorization;@@ -453,4 +454,65 @@ public abstract class BaseOrderManagementController(}#endregion++ #region Addresses++ [PermissionAuthorizeAction(PermissionActionName.Preview)]+ public async Task<IActionResult> AddressEdit(string addressId, string orderId, bool billingAddress)+ {+ var (order, denied) = await LoadAuthorizedOrder(orderId);+ if (denied != null) return denied;++ var address = new Grand.Domain.Common.Address();+ switch (billingAddress)+ {+ case true when order.BillingAddress != null:+ if (order.BillingAddress.Id == addressId) address = order.BillingAddress;+ break;+ case false when order.ShippingAddress != null:+ if (order.ShippingAddress.Id == addressId) address = order.ShippingAddress;+ break;+ }++ if (address == null)+ throw new ArgumentException("No address found with the specified id", nameof(addressId));++ var model = await orderViewModelService.PrepareOrderAddressModel(order, address);+ model.BillingAddress = billingAddress;+ return View(model);+ }++ [PermissionAuthorizeAction(PermissionActionName.Edit)]+ [HttpPost]+ public async Task<IActionResult> AddressEdit(OrderAddressModel model,+ [FromServices] Grand.Business.Core.Interfaces.Common.Addresses.IAddressAttributeService addressAttributeService,+ [FromServices] Grand.Business.Core.Interfaces.Common.Addresses.IAddressAttributeParser addressAttributeParser)+ {+ var (order, denied) = await LoadAuthorizedOrder(model.OrderId);+ if (denied != null) return denied;++ var address = new Grand.Domain.Common.Address();+ switch (model.BillingAddress)+ {+ case true when order.BillingAddress != null:+ if (order.BillingAddress.Id == model.Address.Id) address = order.BillingAddress;+ break;+ case false when order.ShippingAddress != null:+ if (order.ShippingAddress.Id == model.Address.Id) address = order.ShippingAddress;+ break;+ }++ if (ModelState.IsValid)+ {+ var customAttributes = await model.Address.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);+ await orderViewModelService.UpdateOrderAddress(order, address, model, customAttributes);+ return RedirectToAction("AddressEdit",+ new { addressId = model.Address.Id, orderId = model.OrderId, model.BillingAddress });+ }++ model = await orderViewModelService.PrepareOrderAddressModel(order, address);+ return View(model);+ }++ #endregion}