Implement CheckAndUpdateProductManageInventoryMethodToManageStock to MgEventConsumer; improvements;
This commit is contained in:
parent
56927f50ea
commit
7fb047fd28
|
|
@ -3,7 +3,7 @@ using Nop.Core;
|
||||||
|
|
||||||
namespace Mango.Nop.Core.Entities;
|
namespace Mango.Nop.Core.Entities;
|
||||||
|
|
||||||
public class MgEntityBase : BaseEntity, IEntityInt
|
public abstract class MgEntityBase : BaseEntity, IEntityInt
|
||||||
{
|
{
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
|
|
@ -9,6 +10,8 @@ public interface IMgDbContextBase //: IAcDbContextBase
|
||||||
ILogger Logger { get; init; }
|
ILogger Logger { get; init; }
|
||||||
INopDataProvider DataProvider { get; init; }
|
INopDataProvider DataProvider { get; init; }
|
||||||
|
|
||||||
|
IRepository<Product> Products { get; set; }
|
||||||
|
|
||||||
bool Transaction(Func<TransactionScope, bool> callbackTransactionBody, bool throwException = false);
|
bool Transaction(Func<TransactionScope, bool> callbackTransactionBody, bool throwException = false);
|
||||||
bool TransactionSafe(Func<TransactionScope, bool> callbackTransactionBody, bool throwException = false);
|
bool TransactionSafe(Func<TransactionScope, bool> callbackTransactionBody, bool throwException = false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ using Nop.Data.DataProviders;
|
||||||
|
|
||||||
namespace Mango.Nop.Core.Repositories;
|
namespace Mango.Nop.Core.Repositories;
|
||||||
|
|
||||||
public class MgDalBase<TDbContext> : IMgDalBase<TDbContext> where TDbContext : IMgDbContextBase
|
public abstract class MgDalBase<TDbContext> : IMgDalBase<TDbContext> where TDbContext : IMgDbContextBase
|
||||||
{
|
{
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public TDbContext Context { get; }
|
public TDbContext Context { get; }
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using Mango.Nop.Core.Interfaces;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
using Mango.Nop.Services;
|
using Mango.Nop.Services;
|
||||||
using Nop.Core.Caching;
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
|
|
||||||
namespace Mango.Nop.Core.Repositories;
|
namespace Mango.Nop.Core.Repositories;
|
||||||
|
|
@ -23,14 +24,17 @@ public abstract class MgDbContextBase : IMgDbContextBase
|
||||||
public ILogger Logger { get; init; }
|
public ILogger Logger { get; init; }
|
||||||
public INopDataProvider DataProvider { get; init; }
|
public INopDataProvider DataProvider { get; init; }
|
||||||
|
|
||||||
|
public IRepository<Product> Products { get; set; }
|
||||||
//public IHttpContextAccessor HttpContextAccessor { get; init; }
|
//public IHttpContextAccessor HttpContextAccessor { get; init; }
|
||||||
|
|
||||||
public MgDbContextBase(INopDataProvider dataProvider, IMgLockService lockService, ILogger logger)
|
public MgDbContextBase(IRepository<Product> productRepository, INopDataProvider dataProvider, IMgLockService lockService, ILogger logger)
|
||||||
{
|
{
|
||||||
LockService = lockService;
|
LockService = lockService;
|
||||||
|
|
||||||
Logger = logger;// new Logger<MgDbContextBase>(logWriters.ToArray());
|
Logger = logger;// new Logger<MgDbContextBase>(logWriters.ToArray());
|
||||||
DataProvider = dataProvider;
|
DataProvider = dataProvider;
|
||||||
|
|
||||||
|
Products = productRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TransactionScope CreateTransactionScope(TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required)
|
private static TransactionScope CreateTransactionScope(TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using AyCode.Core.Loggers;
|
using AyCode.Core.Loggers;
|
||||||
|
using Mango.Nop.Core.Interfaces;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
|
using Mango.Nop.Core.Repositories;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Nop.Core.Domain.Catalog;
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Core.Domain.Customers;
|
using Nop.Core.Domain.Customers;
|
||||||
|
|
@ -13,7 +15,7 @@ namespace Mango.Nop.Services;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents plugin event consumer
|
/// Represents plugin event consumer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MgEventConsumer(IHttpContextAccessor httpContextAccessor, IEnumerable<IAcLogWriterBase> logWriters) :
|
public abstract class MgEventConsumer(IMgDbContextBase ctx, IHttpContextAccessor httpContextAccessor, IEnumerable<IAcLogWriterBase> logWriters) :
|
||||||
IConsumer<EntityUpdatedEvent<Product>>,
|
IConsumer<EntityUpdatedEvent<Product>>,
|
||||||
IConsumer<EntityInsertedEvent<Product>>,
|
IConsumer<EntityInsertedEvent<Product>>,
|
||||||
IConsumer<CustomerRegisteredEvent>,
|
IConsumer<CustomerRegisteredEvent>,
|
||||||
|
|
@ -30,6 +32,16 @@ public class MgEventConsumer(IHttpContextAccessor httpContextAccessor, IEnumerab
|
||||||
protected readonly IHttpContextAccessor HttpContextAccessor = httpContextAccessor;
|
protected readonly IHttpContextAccessor HttpContextAccessor = httpContextAccessor;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
protected virtual async Task<Product> CheckAndUpdateProductManageInventoryMethodToManageStock(Product product)
|
||||||
|
{
|
||||||
|
if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock) return product;
|
||||||
|
|
||||||
|
product.ManageInventoryMethod = ManageInventoryMethod.ManageStock;
|
||||||
|
await ctx.Products.UpdateAsync(product, false);
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
public virtual async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
||||||
{ }
|
{ }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue