StockQuantityHistoryExt, StockQuantityHistoryDto; improvements, fixes;

This commit is contained in:
Loretta 2025-11-13 19:58:39 +01:00
parent 995fa050ef
commit f72a031a7e
5 changed files with 74 additions and 17 deletions

View File

@ -30,6 +30,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
public class FruitBankDataController(
FruitBankDbContext ctx,
MeasurementService measurementService,
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtoDbTable,
IWorkContext workContext,
ICustomerService customerService,
ICustomerRegistrationService customerRegistrationService,
@ -51,6 +52,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
throw new NotImplementedException("GetMeasuringModels");
}
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
=> await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync();
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
=> await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync();
[SignalR(SignalRTags.GetPartners)]
public async Task<List<Partner>> GetPartners()
{
@ -313,26 +322,26 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
switch (loginResult)
{
case CustomerLoginResults.Successful:
{
var customer = await customerService.GetCustomerByEmailAsync(customerEmail);
var isInMeasuringRole = await customerService.IsInCustomerRoleAsync(customer, FruitBankConst.MeasuringRoleSystemName);
if (!isInMeasuringRole)
{
resultLoginModel.ErrorMessage = "Is not in MeauringRole!";
var customer = await customerService.GetCustomerByEmailAsync(customerEmail);
var isInMeasuringRole = await customerService.IsInCustomerRoleAsync(customer, FruitBankConst.MeasuringRoleSystemName);
if (!isInMeasuringRole)
{
resultLoginModel.ErrorMessage = "Is not in MeauringRole!";
break;
}
//var actionResult = await customerRegistrationService.SignInCustomerAsync(customer, returnUrl, loginModel.RememberMe);
//await _workContext.SetCurrentCustomerAsync(customer);
//await _authenticationService.SignInAsync(customer, isPersist);
////raise event
//await _eventPublisher.PublishAsync(new CustomerLoggedinEvent(customer));
resultLoginModel.CustomerDto = new CustomerDto(customer); //customer.ToModel<CustomerDto>();
break;
}
//var actionResult = await customerRegistrationService.SignInCustomerAsync(customer, returnUrl, loginModel.RememberMe);
//await _workContext.SetCurrentCustomerAsync(customer);
//await _authenticationService.SignInAsync(customer, isPersist);
////raise event
//await _eventPublisher.PublishAsync(new CustomerLoggedinEvent(customer));
resultLoginModel.CustomerDto = new CustomerDto(customer); //customer.ToModel<CustomerDto>();
break;
}
case CustomerLoginResults.CustomerNotExist:
resultLoginModel.ErrorMessage = await localizationService.GetResourceAsync("Account.Login.WrongCredentials.CustomerNotExist");
break;

View File

@ -613,6 +613,9 @@ public class FruitBankDbContext : MgDbContextBase,
if (productDto.StockQuantity < 0)
Logger.Error($"productDto.StockQuantity < 0; Id: {productDto.Id}; StockQuantity: {productDto.StockQuantity}");
//TODO: !!!!!!!!!!!!!!!! - J.
//await _productService.AdjustInventoryAsync(product, quantityInc, string.Empty, "");
await ProductDtos.UpdateAsync(productDto, publishEvent);
return await Task.FromResult(true);

View File

@ -0,0 +1,37 @@
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using LinqToDB;
using Mango.Nop.Core.Entities;
using Mango.Nop.Core.Loggers;
using Mango.Nop.Data.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Domain.Catalog;
using Nop.Core.Events;
using Nop.Data;
using System.Linq.Expressions;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class StockQuantityHistoryDtoDbTable : MgDtoDbTableBase<StockQuantityHistoryDto, StockQuantityHistory>
{
public StockQuantityHistoryDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
{
}
public override IQueryable<StockQuantityHistoryDto> GetAll() => base.GetAll().LoadWith(sqh => sqh.StockQuantityHistoryExt);
public IQueryable<StockQuantityHistoryDto> GetAll(bool loadProductRelation)
{
return loadProductRelation
? GetAll().LoadWith(sqh => sqh.ProductDto).ThenLoad(p => p.GenericAttributes)
: GetAll();
}
public Task<StockQuantityHistoryDto> GetByIdAsync(int id, bool loadProductRelation)
=> GetAll(loadProductRelation).FirstOrDefaultAsync(p => p.Id == id);
public IQueryable<StockQuantityHistoryDto> GetByProductIdAsync(int productId, bool loadProductRelation)
=> GetAll(loadProductRelation).Where(p => p.ProductId == productId);
}

View File

@ -72,6 +72,8 @@ public class PluginNopStartup : INopStartup
services.AddScoped<FilesDbTable>();
services.AddScoped<ShippingDocumentToFilesDbTable>();
services.AddScoped<StockQuantityHistoryDtoDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<SignalRSendToClientService>();

View File

@ -1,6 +1,8 @@
using FruitBank.Common;
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using Mango.Nop.Core.Dtos;
using Mango.Nop.Core.Entities;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Orders;
using Nop.Data.Mapping;
@ -29,6 +31,10 @@ public partial class NameCompatibility : INameCompatibility
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
{ typeof(StockQuantityHistoryDto), nameof(StockQuantityHistory)},
{ typeof(StockQuantityHistoryExt), FruitBankConstClient.StockQuantityHistoryExtDbTableName},
};