improvements, etc

This commit is contained in:
Loretta 2025-10-11 12:52:55 +02:00
parent da241818d7
commit 08b5d2984a
6 changed files with 47 additions and 44 deletions

View File

@ -1,4 +1,5 @@
using AyCode.Services.SignalRs;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.SignalRs;
using Microsoft.AspNetCore.Mvc;
@ -14,7 +15,7 @@ using Nop.Web.Framework.Mvc.Filters;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
{
public class CustomOrderService(IOrderService orderService, IOrderModelFactory orderModelFactory) : ICustomOrderControllerServer
public class CustomOrderSignalREndpoint(IOrderService orderService, IOrderModelFactory orderModelFactory) : ICustomOrderSignalREndpointServer
{
private readonly IOrderService _orderService = orderService;
private readonly CustomOrderModelFactory _orderModelFactory = orderModelFactory as CustomOrderModelFactory;
@ -46,19 +47,19 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[Area(AreaNames.ADMIN)]
[AuthorizeAdmin]
public class CustomOrderController : BaseAdminController, ICustomOrderControllerServer
public class CustomOrderController : BaseAdminController, ICustomOrderSignalREndpointServer
{
private readonly IOrderService _orderService;
private readonly CustomOrderModelFactory _orderModelFactory;
private readonly ICustomOrderControllerServer _customOrderService;
private readonly ICustomOrderSignalREndpointServer _customOrderSignalREndpoint;
private readonly IPermissionService _permissionService;
// ... other dependencies
public CustomOrderController(IOrderService orderService, IOrderModelFactory orderModelFactory, ICustomOrderControllerServer customOrderService, IPermissionService permissionService)
public CustomOrderController(IOrderService orderService, IOrderModelFactory orderModelFactory, ICustomOrderSignalREndpointServer customOrderSignalREndpoint, IPermissionService permissionService)
{
_orderService = orderService;
_orderModelFactory = orderModelFactory as CustomOrderModelFactory;
_customOrderService = customOrderService;
_customOrderSignalREndpoint = customOrderSignalREndpoint;
_permissionService = permissionService;
// ... initialize other deps
}

View File

@ -61,28 +61,35 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
return;
var form = httpContextAccessor.HttpContext?.Request?.Form;
if (form == null || !form.Any())
if (form == null || form.Count == 0)
return;
//TODO: nameof(IMeasurable) - J.
var isMeasurable = form["IsMeasurable"].ToString().Contains("true");
// Save IsMeasurable
if (form.ContainsKey("IsMeasurable"))
{
await genericAttributeService.SaveAttributeAsync(product, "IsMeasurable", isMeasurable);
//Akkor ez kell? - Á.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, isMeasurable, false);
//Igen, csak true kell a végére és mehet egy lépésben a NetWeight és az IsMeasurable - J.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, netWeight, 0, isMeasurable, true);
}
// Save NetWeight
if (form.ContainsKey("NetWeight"))
if (form.ContainsKey("NetWeight")) //TODO: nameof(IMeasuringNetWeight) - J.
{
var netWeightStr = form["NetWeight"].ToString();
if (!string.IsNullOrWhiteSpace(netWeightStr) && decimal.TryParse(netWeightStr, out var netWeight))
if (!string.IsNullOrWhiteSpace(netWeightStr) && double.TryParse(netWeightStr, out var netWeight))
{
await genericAttributeService.SaveAttributeAsync(product, "NetWeight", netWeight);
//Akkor ez kell? - Á.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, , false);
//Igen, csak true kell a végére és mehet egy lépésben a NetWeight és az IsMeasurable - J.
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, netWeight, 0, isMeasurable, true);
}
}
@ -93,6 +100,8 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
if (!string.IsNullOrWhiteSpace(incomingQtyStr) && int.TryParse(incomingQtyStr, out var incomingQuantity))
{
await genericAttributeService.SaveAttributeAsync(product, "IncomingQuantity", incomingQuantity);
//await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, "IncomingQuantity", incomingQuantity);
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Infrastructure;
using AyCode.Core.Extensions;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Nop.Core;
@ -175,12 +176,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
var orderListModelExtended = new OrderListModelExtended();
var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered);
CopyModelHelper.CopyPublicProperties(orderListModel, orderListModelExtended);
PropertyHelper.CopyPublicProperties(orderListModel, orderListModelExtended);
foreach (var orderModel in orderListModel.Data)
{
var orderModelExtended = new OrderModelExtended();
CopyModelHelper.CopyPublicProperties(orderModel, orderModelExtended);
PropertyHelper.CopyPublicProperties(orderModel, orderModelExtended);
orderModelExtended.IsMeasurable = await ShouldMarkAsNeedsMeasurementAsync(orderModel);

View File

@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Nop.Plugin.Misc.FruitBankPlugin.Helpers
{
public static class CopyModelHelper
{
public static TDestination CopyPublicProperties<TSource, TDestination>(TSource src, TDestination dest)
{
if (src == null || dest == null) return dest;
var srcProps = typeof(TSource)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead);
foreach (var sp in srcProps)
{
var dp = typeof(TDestination).GetProperty(sp.Name, BindingFlags.Public | BindingFlags.Instance);
if (dp == null || !dp.CanWrite) continue;
dp.SetValue(dest, sp.GetValue(src));
}
return dest;
}
}
}

View File

@ -29,6 +29,7 @@ using Nop.Web.Areas.Admin.Models.Catalog;
using Nop.Web.Areas.Admin.Models.Orders;
using FruitBank.Common.Server.Interfaces;
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;
@ -67,6 +68,7 @@ public class PluginNopStartup : INopStartup
services.AddScoped<FruitBankDbContext>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
services.AddScoped<IPriceCalculationService, CustomPriceCalculationService>();

View File

@ -121,6 +121,20 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
}
}
public Task InsertOrUpdateGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType value)
=> InsertOrUpdateGenericAttributeAsync<TEntity, TPropType>(entityId, key, value, storeContext.GetCurrentStore().Id);
public async Task InsertOrUpdateGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType value, int storeId)
{
var ga = await GetGenericAttributeAsync<TEntity>(entityId, key, storeId);
if (ga == null) await InsertGenericAttributeAsync<TEntity, TPropType>(entityId, key, value, storeId);
else await UpdateGenericAttributeAsync(ga, value);
}
public Task InsertGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType value)
=> InsertGenericAttributeAsync<TEntity, TPropType>(entityId, key, value, storeContext.GetCurrentStore().Id);
public async Task InsertGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType value, int storeId)
{
var genericAttribute = new GenericAttribute
@ -135,6 +149,9 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
await genericAttributeService.InsertAttributeAsync(genericAttribute);
}
public Task UpdateGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType value)
=> UpdateGenericAttributeAsync<TEntity, TPropType>(entityId, key, value, storeContext.GetCurrentStore().Id);
public async Task UpdateGenericAttributeAsync<TEntity, TPropType>(int entityId, string key, TPropType newValue, int storeId)
{
var ga = await GetGenericAttributeAsync<TEntity>(entityId, key, storeId);
@ -147,6 +164,9 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
await genericAttributeService.UpdateAttributeAsync(genericAttribute);
}
public Task DeleteGenericAttributeAsync<TEntity>(int entityId, string key)
=> DeleteGenericAttributeAsync<TEntity>(entityId, key, storeContext.GetCurrentStore().Id);
public async Task DeleteGenericAttributeAsync<TEntity>(int entityId, string key, int storeId)
{
var ga = await GetGenericAttributeAsync<TEntity>(entityId, key, storeId);