using AyCode.Core.Loggers; using AyCode.Services.SignalRs; using FruitBank.Common.Entities; using FruitBank.Common.Server.Interfaces; using FruitBank.Common.Server.Services.SignalRs; using FruitBank.Common.SignalRs; using Mango.Nop.Core.Loggers; using Nop.Core; using Nop.Core.Events; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers; public class StockSignalREndpointServer(StockTakingDbContext ctx, SignalRSendToClientService sendToClient, IEventPublisher eventPublisher, IWorkContext workContext, IEnumerable logWriters) : IStockSignalREndpointServer { private const int LastStockTakingDays = 15; private readonly ILogger _logger = new Logger(logWriters.ToArray()); [SignalR(SignalRTags.GetStockTakings)] public async Task> GetStockTakings() { return await ctx.StockTakings.GetAll(true).ToListAsync(); } public async Task> GetStockTakingsByProductId(int productId) { throw new NotImplementedException(); } [SignalR(SignalRTags.AddStockTaking)] public async Task AddStockTaking(StockTaking stockTaking) { var result = await ctx.TransactionSafeAsync(async _ => { await ctx.StockTakings.InsertAsync(stockTaking); var productDtos = await ctx.ProductDtos.GetAll(true).ToListAsync(); foreach (var productDto in productDtos) { var stockTakingItem = new StockTakingItem { StockTakingId = stockTaking.Id, ProductId = productDto.Id, //IsMeasurable = productDto.IsMeasurable, OriginalStockQuantity = productDto.StockQuantity, OriginalNetWeight = productDto.NetWeight }; await ctx.StockTakingItems.InsertAsync(stockTakingItem); } return true; }); if (result) return await ctx.StockTakings.GetByIdAsync(stockTaking.Id, false); return null; } public async Task UpdateStockTaking(StockTaking stockTaking) { throw new NotImplementedException(); } [SignalR(SignalRTags.GetStockTakingItems)] public async Task> GetStockTakingItems() { return await ctx.StockTakingItems.GetAll(true).ToListAsync(); } [SignalR(SignalRTags.GetStockTakingItemsById)] public async Task GetStockTakingItemsById(int stockTakingItemId) { var result = await ctx.StockTakingItems.GetByIdAsync(stockTakingItemId, true); return result; } public async Task> GetStockTakingItemsByProductId(int productId) { throw new NotImplementedException(); } public async Task> GetStockTakingItemsByStockTakingId(int stockTakingId) { throw new NotImplementedException(); } public async Task AddStockTakingItem(StockTakingItem stockTakingItem) { throw new NotImplementedException(); } public async Task UpdateStockTakingItem(StockTakingItem stockTakingItem) { throw new NotImplementedException(); } public async Task> GetStockTakingItemPallets() { throw new NotImplementedException(); } public async Task> GetStockTakingItemPalletsByProductId(int productId) { throw new NotImplementedException(); } public async Task AddStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet) { throw new NotImplementedException(); } public async Task UpdateStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet) { throw new NotImplementedException(); } }