119 lines
3.9 KiB
C#
119 lines
3.9 KiB
C#
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<IAcLogWriterBase> logWriters)
|
|
: IStockSignalREndpointServer
|
|
{
|
|
private const int LastStockTakingDays = 15;
|
|
private readonly ILogger _logger = new Logger<StockSignalREndpointServer>(logWriters.ToArray());
|
|
|
|
[SignalR(SignalRTags.GetStockTakings)]
|
|
public async Task<List<StockTaking>> GetStockTakings()
|
|
{
|
|
return await ctx.StockTakings.GetAll(true).ToListAsync();
|
|
}
|
|
|
|
public async Task<List<StockTaking>> GetStockTakingsByProductId(int productId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
[SignalR(SignalRTags.AddStockTaking)]
|
|
public async Task<StockTaking> 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<StockTaking> UpdateStockTaking(StockTaking stockTaking)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetStockTakingItems)]
|
|
public async Task<List<StockTakingItem>> GetStockTakingItems()
|
|
{
|
|
return await ctx.StockTakingItems.GetAll(true).ToListAsync();
|
|
}
|
|
|
|
[SignalR(SignalRTags.GetStockTakingItemsById)]
|
|
public async Task<StockTakingItem> GetStockTakingItemsById(int stockTakingItemId)
|
|
{
|
|
var result = await ctx.StockTakingItems.GetByIdAsync(stockTakingItemId, true);
|
|
return result;
|
|
}
|
|
|
|
public async Task<List<StockTakingItem>> GetStockTakingItemsByProductId(int productId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<List<StockTakingItem>> GetStockTakingItemsByStockTakingId(int stockTakingId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<StockTakingItem> AddStockTakingItem(StockTakingItem stockTakingItem)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<StockTakingItem> UpdateStockTakingItem(StockTakingItem stockTakingItem)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<List<StockTakingItemPallet>> GetStockTakingItemPallets()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<List<StockTakingItemPallet>> GetStockTakingItemPalletsByProductId(int productId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<StockTakingItemPallet> AddStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<StockTakingItemPallet> UpdateStockTakingItemPallet(StockTakingItemPallet stockTakingItemPallet)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |