Browse Source

Revert the Edit modal

pull/190/head
gdlcf88 4 years ago
parent
commit
91eda09c3e
  1. 52
      plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml
  2. 42
      plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs

52
plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml

@ -1,9 +1,8 @@
@page @page
@using EasyAbp.EShop.Plugins.Baskets
@using EasyAbp.EShop.Plugins.Baskets.Localization @using EasyAbp.EShop.Plugins.Baskets.Localization
@using EasyAbp.EShop.Plugins.Baskets.Permissions
@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.Abp.Settings @using Volo.Abp.Settings
@inject IHtmlLocalizer<BasketsResource> L @inject IHtmlLocalizer<BasketsResource> L
@ -29,11 +28,19 @@
$(document).ready(function() { $(document).ready(function() {
if (@(Model.ServerSide ? "true" : "false")) return; if (@(Model.ServerSide ? "true" : "false")) return;
var basketItems = JSON.parse(localStorage.getItem(localStorageItemKey)) || [];
var index = basketItems.findIndex(x => x.id === '@Model.Id');
function generateClientSideData(basketItems) { $('#ViewModel_Quantity').val(basketItems[index].quantity);
var basketItemService = easyAbp.eShop.plugins.baskets.basketItems.basketItem;
var $form = $("form");
basketItemService.generateClientSideData({ items: [ basketItems[index] ] }, { $form.off('submit');
$form.on('submit', function(e){
e.preventDefault();
var service = easyAbp.eShop.plugins.baskets.basketItems.basketItem;
basketItems[index].quantity = parseInt($form.serializeFormToObject().viewModel.quantity);
service.generateClientSideData({ items: [ basketItems[index] ] }, {
success: function (responseText, statusText, xhr, form) { success: function (responseText, statusText, xhr, form) {
localStorage.setItem(localStorageItemKey, JSON.stringify(basketItems)); localStorage.setItem(localStorageItemKey, JSON.stringify(basketItems));
$form.trigger('abp-ajax-success', $form.trigger('abp-ajax-success',
@ -45,39 +52,6 @@
}) })
} }
}); });
}
var basketItems = JSON.parse(localStorage.getItem(localStorageItemKey)) || [];
var index = basketItems.findIndex(x => x.id === '@Model.Id');
$('#ViewModel_Quantity').val(basketItems[index].quantity);
var $form = $("form");
$form.off('submit');
$form.on('submit', function(e){
e.preventDefault();
var orderService = easyAbp.eShop.orders.orders.order;
basketItems[index].quantity = parseInt($form.serializeFormToObject().viewModel.quantity);
if (abp.currentUser.isAuthenticated) {
orderService.checkCreate({
storeId: basketItems[index].storeId,
orderLines: [{
productId: basketItems[index].productId,
productSkuId: basketItems[index].productSkuId,
quantity: basketItems[index].quantity
}]
}, {
success: function (responseText, statusText, xhr, form) {
if (responseText.canCreate) {
generateClientSideData(basketItems);
} else {
abp.message.error(l('@BasketsErrorCodes.CheckCreateOrderFailed', responseText.reason));
}
}
});
} else {
generateClientSideData(basketItems);
}
}); });
}); });
</script> </script>

42
plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Web/Pages/EShop/Plugins/Baskets/BasketItems/BasketItem/EditModal.cshtml.cs

@ -1,16 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using EasyAbp.EShop.Orders.Orders;
using EasyAbp.EShop.Orders.Orders.Dtos;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using EasyAbp.EShop.Plugins.Baskets.BasketItems; using EasyAbp.EShop.Plugins.Baskets.BasketItems;
using EasyAbp.EShop.Plugins.Baskets.BasketItems.Dtos; using EasyAbp.EShop.Plugins.Baskets.BasketItems.Dtos;
using EasyAbp.EShop.Plugins.Baskets.Permissions; using EasyAbp.EShop.Plugins.Baskets.Permissions;
using EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem.ViewModels; using EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem.ViewModels;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Settings; using Volo.Abp.Settings;
namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketItems.BasketItem
@ -31,15 +27,11 @@ namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketIt
[BindProperty] [BindProperty]
public EditBasketItemViewModel ViewModel { get; set; } public EditBasketItemViewModel ViewModel { get; set; }
private readonly IOrderAppService _orderAppService; private readonly IBasketItemAppService _service;
private readonly IBasketItemAppService _basketItemAppService;
public EditModalModel( public EditModalModel(IBasketItemAppService service)
IOrderAppService orderAppService,
IBasketItemAppService basketItemAppService)
{ {
_orderAppService = orderAppService; _service = service;
_basketItemAppService = basketItemAppService;
} }
public virtual async Task OnGetAsync() public virtual async Task OnGetAsync()
@ -52,38 +44,14 @@ namespace EasyAbp.EShop.Plugins.Baskets.Web.Pages.EShop.Plugins.Baskets.BasketIt
return; return;
} }
var dto = await _basketItemAppService.GetAsync(Id); var dto = await _service.GetAsync(Id);
ViewModel = ObjectMapper.Map<BasketItemDto, EditBasketItemViewModel>(dto); ViewModel = ObjectMapper.Map<BasketItemDto, EditBasketItemViewModel>(dto);
} }
public virtual async Task<IActionResult> OnPostAsync() public virtual async Task<IActionResult> OnPostAsync()
{ {
var item = await _basketItemAppService.GetAsync(Id);
var dto = ObjectMapper.Map<EditBasketItemViewModel, UpdateBasketItemDto>(ViewModel); var dto = ObjectMapper.Map<EditBasketItemViewModel, UpdateBasketItemDto>(ViewModel);
await _service.UpdateAsync(Id, dto);
var checkCreateOrderResult = await _orderAppService.CheckCreateAsync(new CheckCreateOrderInput
{
StoreId = item.StoreId,
OrderLines = new List<CreateOrderLineDto>
{
new()
{
ProductId = item.ProductId,
ProductSkuId = item.ProductSkuId,
Quantity = ViewModel.Quantity
}
}
});
if (!checkCreateOrderResult.CanCreate)
{
throw new BusinessException(BasketsErrorCodes.CheckCreateOrderFailed)
.WithData("reason", checkCreateOrderResult.Reason);
}
await _basketItemAppService.UpdateAsync(Id, dto);
return NoContent(); return NoContent();
} }
} }

Loading…
Cancel
Save