Mango.Nop.Plugins/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs

115 lines
3.9 KiB
C#

using AyCode.Core.Loggers;
using AyCode.Services.SignalRs;
using DocumentFormat.OpenXml.Office2010.Excel;
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Loggers;
using FruitBank.Common.Models;
using FruitBank.Common.SignalRs;
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Services.Customers;
using Nop.Web.Framework.Controllers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
{
//https://linq2db.github.io/articles/sql/Join-Operators.html
public class FruitBankDataController(FruitBankDbContext ctx, IWorkContext workContext, ICustomerService customerService, IEnumerable<IAcLogWriterBase> logWriters): BasePluginController, IFruitBankDataControllerServer
{
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
[SignalR(SignalRTags.GetMeasuringModels)]
public async Task<List<MeasuringModel>> GetMeasuringModels()
{
throw new NotImplementedException("GetMeasuringModels");
}
[SignalR(SignalRTags.GetMeasuringModelByShippingId)]
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
{
return await ctx.GetMeasuringModelByShippingId(shippingId).FirstOrDefaultAsync();
}
[SignalR(SignalRTags.GetPartners)]
public async Task<List<Partner>> GetPartners()
{
_logger.Detail($"GetPartners invoked");
return await ctx.Partners.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetPartnerById)]
public async Task<Partner> GetPartnerById(int id)
{
_logger.Detail($"GetPartnerById invoked; id: {id}");
var customers = await ctx.GetCustormersBySystemRoleName("Measuring").ToListAsync();
_logger.Error($"COUNT: {customers.Count}");
return await ctx.Partners.GetByIdAsync(id);
}
[SignalR(SignalRTags.UpdatePartner)]
public async Task<Partner> UpdatePartner(Partner partner)
{
ArgumentNullException.ThrowIfNull(partner);
_logger.Detail($"UpdatePartner invoked; id: {partner.Id}");
await ctx.Partners.UpdateAsync(partner);
return partner;
}
[SignalR(SignalRTags.GetShippings)]
public async Task<List<Shipping>> GetShippings()
{
_logger.Detail($"GetShippings invoked");
return await ctx.Shippings.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingById)]
public async Task<Shipping> GetShippingById(int id)
{
_logger.Detail($"GetShippingById invoked; id: {id}");
return await ctx.Shippings.GetByIdAsync(id);
}
[SignalR(SignalRTags.GetShippingItems)]
public async Task<List<ShippingItem>> GetShippingItems()
{
_logger.Detail($"GetShippingItems invoked");
return await ctx.ShippingItems.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingItemById)]
public async Task<ShippingItem> GetShippingItemById(int id)
{
_logger.Detail($"GetShippingItemById invoked; id: {id}");
return await ctx.ShippingItems.GetByIdAsync(id);
}
[SignalR(SignalRTags.GetShippingDocuments)]
public async Task<List<ShippingDocument>> GetShippingDocuments()
{
_logger.Detail($"GetShippingDocuments invoked");
return await ctx.ShippingDocuments.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingDocumentById)]
public async Task<ShippingDocument> GetShippingDocumentById(int id)
{
_logger.Detail($"GetShippingDocumentById invoked; id: {id}");
return await ctx.ShippingDocuments.GetByIdAsync(id);
}
}
}