improvements, fixes, etc...
This commit is contained in:
parent
fbad15e02f
commit
3abfc03d1e
|
|
@ -7,12 +7,15 @@ using FruitBank.Common.Loggers;
|
||||||
using FruitBank.Common.Models;
|
using FruitBank.Common.Models;
|
||||||
using FruitBank.Common.SignalRs;
|
using FruitBank.Common.SignalRs;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Nop.Core;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
using Nop.Services.Customers;
|
||||||
|
using Nop.Web.Framework.Controllers;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
{
|
{
|
||||||
//https://linq2db.github.io/articles/sql/Join-Operators.html
|
//https://linq2db.github.io/articles/sql/Join-Operators.html
|
||||||
public class FruitBankDataController(FruitBankDbContext ctx, IEnumerable<IAcLogWriterBase> logWriters): Controller, IFruitBankDataControllerServer
|
public class FruitBankDataController(FruitBankDbContext ctx, IWorkContext workContext, ICustomerService customerService, IEnumerable<IAcLogWriterBase> logWriters): BasePluginController, IFruitBankDataControllerServer
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
|
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
|
||||||
|
|
||||||
|
|
@ -26,7 +29,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
[SignalR(SignalRTags.GetMeasuringModelByShippingId)]
|
[SignalR(SignalRTags.GetMeasuringModelByShippingId)]
|
||||||
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
||||||
{
|
{
|
||||||
return await ctx.GetMeasuringModelByShippingId(shippingId);
|
return await ctx.GetMeasuringModelByShippingId(shippingId).FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetPartners)]
|
[SignalR(SignalRTags.GetPartners)]
|
||||||
|
|
@ -34,7 +37,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
{
|
{
|
||||||
_logger.Detail($"GetPartners invoked");
|
_logger.Detail($"GetPartners invoked");
|
||||||
|
|
||||||
return await ctx.Partners.Table.ToListAsync();
|
return await ctx.Partners.GetAll().ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetPartnerById)]
|
[SignalR(SignalRTags.GetPartnerById)]
|
||||||
|
|
@ -42,15 +45,30 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
{
|
{
|
||||||
_logger.Detail($"GetPartnerById invoked; id: {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);
|
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)]
|
[SignalR(SignalRTags.GetShippings)]
|
||||||
public async Task<List<Shipping>> GetShippings()
|
public async Task<List<Shipping>> GetShippings()
|
||||||
{
|
{
|
||||||
_logger.Detail($"GetShippings invoked");
|
_logger.Detail($"GetShippings invoked");
|
||||||
|
|
||||||
return await ctx.Shippings.Table.ToListAsync();
|
return await ctx.Shippings.GetAll().ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SignalR(SignalRTags.GetShippingById)]
|
[SignalR(SignalRTags.GetShippingById)]
|
||||||
|
|
@ -61,24 +79,36 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||||
return await ctx.Shippings.GetByIdAsync(id);
|
return await ctx.Shippings.GetByIdAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ShippingItem>> GetShippingItem()
|
[SignalR(SignalRTags.GetShippingItems)]
|
||||||
|
public async Task<List<ShippingItem>> GetShippingItems()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.Detail($"GetShippingItems invoked");
|
||||||
|
|
||||||
|
return await ctx.ShippingItems.GetAll().ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetShippingItemById)]
|
||||||
public async Task<ShippingItem> GetShippingItemById(int id)
|
public async Task<ShippingItem> GetShippingItemById(int id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.Detail($"GetShippingItemById invoked; id: {id}");
|
||||||
|
|
||||||
|
return await ctx.ShippingItems.GetByIdAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetShippingDocuments)]
|
||||||
public async Task<List<ShippingDocument>> GetShippingDocuments()
|
public async Task<List<ShippingDocument>> GetShippingDocuments()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.Detail($"GetShippingDocuments invoked");
|
||||||
|
|
||||||
|
return await ctx.ShippingDocuments.GetAll().ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SignalR(SignalRTags.GetShippingDocumentById)]
|
||||||
public async Task<ShippingDocument> GetShippingDocumentById(int id)
|
public async Task<ShippingDocument> GetShippingDocumentById(int id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.Detail($"GetShippingDocumentById invoked; id: {id}");
|
||||||
|
|
||||||
|
return await ctx.ShippingDocuments.GetByIdAsync(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,41 @@
|
||||||
using FruitBank.Common.Models;
|
using DocumentFormat.OpenXml.Drawing;
|
||||||
|
using FruitBank.Common.Models;
|
||||||
|
using LinqToDB;
|
||||||
using Mango.Nop.Core.Repositories;
|
using Mango.Nop.Core.Repositories;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Nop.Core.Caching;
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Domain.Customers;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
using Nop.Services.Catalog;
|
using Nop.Services.Catalog;
|
||||||
using Nop.Services.Logging;
|
using Nop.Services.Logging;
|
||||||
|
using NUglify.Helpers;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingItemDbSet<ShippingItemDbTable>
|
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingItemDbSet<ShippingItemDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>
|
||||||
{
|
{
|
||||||
private readonly IProductService _productService;
|
private readonly IProductService _productService;
|
||||||
private readonly IStaticCacheManager _staticCacheManager;
|
private readonly IStaticCacheManager _staticCacheManager;
|
||||||
|
|
||||||
|
protected readonly IRepository<Customer> _customerRepository;
|
||||||
|
protected readonly IRepository<CustomerCustomerRoleMapping> _customerCustomerRoleMappingRepository;
|
||||||
|
protected readonly IRepository<CustomerRole> _customerRoleRepository;
|
||||||
|
|
||||||
public PartnerDbTable Partners { get; set; }
|
public PartnerDbTable Partners { get; set; }
|
||||||
public ShippingDbTable Shippings { get; set; }
|
public ShippingDbTable Shippings { get; set; }
|
||||||
public ShippingItemDbTable ShippingItems { get; set; }
|
public ShippingItemDbTable ShippingItems { get; set; }
|
||||||
|
public ShippingDocumentDbTable ShippingDocuments { get; set; }
|
||||||
//public EntityRepository<Auction> Auctions2 { get; set; }
|
//public EntityRepository<Auction> Auctions2 { get; set; }
|
||||||
//public IRepository<AuctionBid> AuctionBids2 { get; set; }
|
//public IRepository<AuctionBid> AuctionBids2 { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public FruitBankDbContext(INopDataProvider dataProvider, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingItemDbTable shippingItemDbTable, IProductService productService, IStaticCacheManager staticCacheManager, ILogger logger) : base(dataProvider, logger)
|
public FruitBankDbContext(INopDataProvider dataProvider, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingItemDbTable shippingItemDbTable,
|
||||||
|
ShippingDocumentDbTable shippingDocumentDbTable, IProductService productService, IStaticCacheManager staticCacheManager,
|
||||||
|
IRepository<Customer> customerRepository,
|
||||||
|
IRepository<CustomerCustomerRoleMapping> customerCustomerRoleMappingRepository,
|
||||||
|
IRepository<CustomerRole> customerRoleRepository,
|
||||||
|
ILogger logger) : base(dataProvider, logger)
|
||||||
{
|
{
|
||||||
_productService = productService;
|
_productService = productService;
|
||||||
_staticCacheManager = staticCacheManager;
|
_staticCacheManager = staticCacheManager;
|
||||||
|
|
@ -28,12 +43,18 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
||||||
Partners = partnerDbTable;
|
Partners = partnerDbTable;
|
||||||
Shippings = shippingDbTable;
|
Shippings = shippingDbTable;
|
||||||
ShippingItems = shippingItemDbTable;
|
ShippingItems = shippingItemDbTable;
|
||||||
|
ShippingDocuments = shippingDocumentDbTable;
|
||||||
|
|
||||||
|
_customerRepository = customerRepository;
|
||||||
|
_customerCustomerRoleMappingRepository = customerCustomerRoleMappingRepository;
|
||||||
|
_customerRoleRepository = customerRoleRepository;
|
||||||
|
|
||||||
|
|
||||||
//Auctions.Table
|
//Auctions.Table
|
||||||
//var auctions = DataProvider.GetTable<Auction>().Where(x => x.Closed);
|
//var auctions = DataProvider.GetTable<Auction>().Where(x => x.Closed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
public IQueryable<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
||||||
{
|
{
|
||||||
var query =
|
var query =
|
||||||
from p in Partners.Table
|
from p in Partners.Table
|
||||||
|
|
@ -41,7 +62,30 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
||||||
where s.Id == shippingId
|
where s.Id == shippingId
|
||||||
select new MeasuringModel(p.Name);
|
select new MeasuringModel(p.Name);
|
||||||
|
|
||||||
return await query.FirstOrDefaultAsync();
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<Customer> GetCustormersBySystemRoleName(string systemRoleName)
|
||||||
|
{
|
||||||
|
if (systemRoleName.IsNullOrWhiteSpace()) throw new ArgumentException("systemRoleName.IsNullOrWhiteSpace()", nameof(systemRoleName));
|
||||||
|
|
||||||
|
var query =
|
||||||
|
from c in _customerRepository.Table
|
||||||
|
join crm in _customerCustomerRoleMappingRepository.Table on c.Id equals crm.CustomerId
|
||||||
|
join cr in _customerRoleRepository.Table on crm.CustomerRoleId equals cr.Id
|
||||||
|
where c.Active && !c.Deleted && cr.SystemName == systemRoleName
|
||||||
|
select c;
|
||||||
|
|
||||||
|
return query.Distinct();
|
||||||
|
|
||||||
|
// query = query.Join(_customerCustomerRoleMappingRepository.Table, x => x.Id, y => y.CustomerId,
|
||||||
|
// (x, y) => new { Customer = x, Mapping = y })
|
||||||
|
// .Where(z => z.Mapping.CustomerRoleId == customerRoleId)
|
||||||
|
// .Select(z => z.Customer)
|
||||||
|
// .Distinct();
|
||||||
|
//});
|
||||||
|
|
||||||
|
//return customers;
|
||||||
}
|
}
|
||||||
|
|
||||||
////public AuctionDbContext(IRepository<Auction> _auctionRepository, IRepository<AuctionBid> _auctionBidRepository)
|
////public AuctionDbContext(IRepository<Auction> _auctionRepository, IRepository<AuctionBid> _auctionBidRepository)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using FruitBank.Common.Interfaces;
|
||||||
|
using Mango.Nop.Core.Interfaces;
|
||||||
|
using Nop.Data;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||||
|
|
||||||
|
public interface IShippingDocumentDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<ShippingDocument>
|
||||||
|
{
|
||||||
|
public TDbTable ShippingDocuments { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,8 @@ public class PartnerDbTable : MgDbTableBase<Partner>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<Partner> GetAll() => Table;
|
||||||
|
|
||||||
//public IOrderedQueryable<AuctionBid> GetAllLastBidByAuctionId(int auctionId)
|
//public IOrderedQueryable<AuctionBid> GetAllLastBidByAuctionId(int auctionId)
|
||||||
//{
|
//{
|
||||||
// return GetAllByAuctionId(auctionId)
|
// return GetAllByAuctionId(auctionId)
|
||||||
|
|
@ -27,7 +29,7 @@ public class PartnerDbTable : MgDbTableBase<Partner>
|
||||||
// => GetAllByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
|
// => GetAllByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
|
||||||
|
|
||||||
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
|
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
|
||||||
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
|
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
|
||||||
|
|
||||||
//public IQueryable<AuctionBid> GetAllByAuctionId(int auctionId)
|
//public IQueryable<AuctionBid> GetAllByAuctionId(int auctionId)
|
||||||
// => Table.Where(x => x.AuctionId == auctionId);
|
// => Table.Where(x => x.AuctionId == auctionId);
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,6 @@ public class ShippingDbTable : MgDbTableBase<Shipping>
|
||||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<Shipping> GetAll() => Table;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
|
using Mango.Nop.Core.Repositories;
|
||||||
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Configuration;
|
||||||
|
using Nop.Core.Events;
|
||||||
|
using Nop.Data;
|
||||||
|
using Nop.Services.Logging;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
public class ShippingDocumentDbTable : MgDbTableBase<ShippingDocument>
|
||||||
|
{
|
||||||
|
public ShippingDocumentDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||||
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<ShippingDocument> GetAll() => Table;
|
||||||
|
}
|
||||||
|
|
@ -14,4 +14,6 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
|
||||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<ShippingItem> GetAll() => Table;
|
||||||
}
|
}
|
||||||
|
|
@ -50,8 +50,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin
|
||||||
// --- INSTALL ---
|
// --- INSTALL ---
|
||||||
public override async Task InstallAsync()
|
public override async Task InstallAsync()
|
||||||
{
|
{
|
||||||
|
//TODO: Add "Measuring" role
|
||||||
// TODO: Add "NeedsToBeMeasured" product attribute if not exists
|
//TODO: Add "NeedsToBeMeasured" product attribute if not exists
|
||||||
|
|
||||||
// Default settings
|
// Default settings
|
||||||
var settings = new OpenAiSettings
|
var settings = new OpenAiSettings
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public class PluginNopStartup : INopStartup
|
||||||
services.AddScoped<PartnerDbTable>();
|
services.AddScoped<PartnerDbTable>();
|
||||||
services.AddScoped<ShippingDbTable>();
|
services.AddScoped<ShippingDbTable>();
|
||||||
services.AddScoped<ShippingItemDbTable>();
|
services.AddScoped<ShippingItemDbTable>();
|
||||||
|
services.AddScoped<ShippingDocumentDbTable>();
|
||||||
|
|
||||||
services.AddScoped<FruitBankDbContext>();
|
services.AddScoped<FruitBankDbContext>();
|
||||||
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
|
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue