Implement FruitBankDbContext, DbTables, stc...
This commit is contained in:
parent
372a3d6b40
commit
d245c50890
|
|
@ -0,0 +1,26 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using AyCode.Services.SignalRs;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Loggers;
|
||||
using FruitBank.Common.Models;
|
||||
using FruitBank.Common.SignalRs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
||||
{
|
||||
public class FruitBankDataController(FruitBankDbContext ctx, IEnumerable<IAcLogWriterBase> logWriters): Controller, IFruitBankDataControllerServer
|
||||
{
|
||||
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
|
||||
|
||||
|
||||
[SignalR(SignalRTags.GetMeasuringModel)]
|
||||
public async Task<MeasuringModel> GetMeasuringModel()
|
||||
{
|
||||
_logger.Detail($"GetMeasuringModel invoked");
|
||||
|
||||
var partner = await ctx.Partners.Table.FirstOrDefaultAsync();
|
||||
return new MeasuringModel($"GetMeasuringModel invoked [{DateTime.Now}] [{partner?.Name}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||
using Nop.Services.Catalog;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
||||
{
|
||||
private readonly IProductService _productService;
|
||||
private readonly IStaticCacheManager _staticCacheManager;
|
||||
|
||||
public PartnerDbTable Partners { get; set; }
|
||||
//public EntityRepository<Auction> Auctions2 { get; set; }
|
||||
//public IRepository<AuctionBid> AuctionBids2 { get; set; }
|
||||
|
||||
|
||||
public FruitBankDbContext(INopDataProvider dataProvider, PartnerDbTable partnerDbTable, IProductService productService, IStaticCacheManager staticCacheManager, ILogger logger) : base(dataProvider, logger)
|
||||
{
|
||||
_productService = productService;
|
||||
_staticCacheManager = staticCacheManager;
|
||||
|
||||
Partners = partnerDbTable;
|
||||
|
||||
//Auctions.Table
|
||||
//var auctions = DataProvider.GetTable<Auction>().Where(x => x.Closed);
|
||||
}
|
||||
|
||||
////public AuctionDbContext(IRepository<Auction> _auctionRepository, IRepository<AuctionBid> _auctionBidRepository)
|
||||
////{
|
||||
//// Auctions2 = _auctionRepository as EntityRepository<Auction>;
|
||||
//// AuctionBids2 = _auctionBidRepository;
|
||||
////}
|
||||
|
||||
//public Task<List<AuctionBid>> GetAllLastBidByAuctionIdAsync(int auctionId) => AuctionBids.GetAllLastBidByAuctionId(auctionId).ToListAsync();
|
||||
|
||||
//public Task<Dictionary<int, AuctionBid>> GetAllLastBidDictionaryByAuctionIdAsync(int auctionId)
|
||||
// => AuctionBids.GetAllLastBidByAuctionId(auctionId).ToDictionaryAsync(x => x.ProductAuctionMappingId);
|
||||
|
||||
//public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
|
||||
//{
|
||||
// return [..await ProductToAuctions.GetByProductId(productId).ToListAsync()];
|
||||
//}
|
||||
|
||||
//public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly)
|
||||
//{
|
||||
// return [..await ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
|
||||
//}
|
||||
|
||||
//public Task<bool> HasBidByProductToAuctionIdAsync(int productToAuctionId)
|
||||
// => AuctionBids.HasBidByProductToAuctionIdAsync(productToAuctionId);
|
||||
|
||||
//public Task<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId)
|
||||
// => AuctionBids.GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
|
||||
|
||||
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
|
||||
// => AuctionBids.GetBidsCountByProductToAuctionIdAsync(productToAuctionId);
|
||||
|
||||
|
||||
//public Task<AuctionBid> RevertAuctionBidByProductToAuctionId(int productToAuctionId)
|
||||
// => AuctionBids.RevertByProductToAuctionIdAsync(productToAuctionId);
|
||||
|
||||
////public async Task ResetProductToAuctionByProductId(int productId)
|
||||
//// => await ResetProductToAuctionAsync(await ProductToAuctions.GetByProductId(productId).FirstOrDefaultAsync());
|
||||
|
||||
//public async Task ResetProductToAuctionByIdAsync(int productToAuctionId, decimal basePrice = 0)
|
||||
// => await ResetProductToAuctionAsync(ProductToAuctions.GetById(productToAuctionId), basePrice);
|
||||
|
||||
//public async Task ResetProductToAuctionAsync(ProductToAuctionMapping productToAuction, decimal basePrice = 0)
|
||||
//{
|
||||
// if (productToAuction == null)
|
||||
// {
|
||||
// Logger.Error($"AuctionDbContext.ResetProductToAuctionAsync(); productToAuction == null");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// await Logger.InformationAsync($"AuctionDbContext.ResetProductToAuctionAsync(); productToAuction.Id: {productToAuction.Id}; basePrice: {basePrice}");
|
||||
|
||||
// var product = await _productService.GetProductByIdAsync(productToAuction.ProductId);
|
||||
// if (product == null)
|
||||
// {
|
||||
// Logger.Error($"AuctionDbContext.ResetProductToAuctionAsync(); product == null");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (basePrice <= 0) basePrice = product.Price;
|
||||
// else
|
||||
// {
|
||||
// product.Price = basePrice;
|
||||
// await _productService.UpdateProductAsync(product);
|
||||
// }
|
||||
|
||||
// await ProductToAuctions.ResetAsync(productToAuction, basePrice);
|
||||
// await AuctionBids.DeleteAllByProductToAuctionIdAsync(productToAuction.Id);
|
||||
|
||||
// await _staticCacheManager.ClearAsync();
|
||||
// //await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
//}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||
|
||||
public interface IPartnerDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<Partner>
|
||||
{
|
||||
public TDbTable Partners { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class PartnerDbTable : MgDbTableBase<Partner>
|
||||
{
|
||||
public PartnerDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
{
|
||||
}
|
||||
|
||||
//public IOrderedQueryable<AuctionBid> GetAllLastBidByAuctionId(int auctionId)
|
||||
//{
|
||||
// return GetAllByAuctionId(auctionId)
|
||||
// .OrderByDescending(x => x.Id)
|
||||
// .GroupBy(x => x.AuctionId, (_, bids) => bids.FirstOrDefault())
|
||||
// .OrderByDescending(percentGroup => percentGroup.Id);
|
||||
//}
|
||||
|
||||
//public IOrderedQueryable<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId)
|
||||
// => GetAllByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
|
||||
|
||||
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
|
||||
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
|
||||
|
||||
//public IQueryable<AuctionBid> GetAllByAuctionId(int auctionId)
|
||||
// => Table.Where(x => x.AuctionId == auctionId);
|
||||
|
||||
//public IQueryable<AuctionBid> GetAllByProductToAuctionId(int productToAuctionId)
|
||||
// => Table.Where(x => x.ProductAuctionMappingId == productToAuctionId);
|
||||
|
||||
//public Task<bool> HasBidByProductToAuctionIdAsync(int productToAuctionId)
|
||||
//{
|
||||
// return Table.AnyAsync(x => x.ProductAuctionMappingId == productToAuctionId);
|
||||
//}
|
||||
|
||||
//public async Task<AuctionBid> RevertByProductToAuctionIdAsync(int productToAuctionId)
|
||||
//{
|
||||
// var lastBid = await GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
|
||||
// if (lastBid == null)
|
||||
// {
|
||||
// await Logger.InformationAsync($"AuctionBidDbTable.RevertByProductToAuctionIdAsync(); (lastBid == null); productToAuction.Id: {productToAuctionId}");
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// await DeleteAsync(lastBid);
|
||||
// return await GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
|
||||
//}
|
||||
|
||||
//public async Task<int> DeleteAllByProductToAuctionIdAsync(int productToAuctionId)
|
||||
//{
|
||||
// var deletedBids = await DeleteAsync(x => x.ProductAuctionMappingId == productToAuctionId);
|
||||
// await Logger.InformationAsync($"AuctionBidDbTable.DeleteAllByProductToAuctionIdAsync(); productToAuction.Id: {productToAuctionId}; deletedBids: {deletedBids}");
|
||||
|
||||
// return deletedBids;
|
||||
//}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains;
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
[Table(Name = "fbPartner")]
|
||||
public class Partner : MgEntityBase, IPartner
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
|
@ -14,6 +16,7 @@ public class Partner : MgEntityBase, IPartner
|
|||
public string City { get; set; }
|
||||
public string Street { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains;
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
[Table(Name = "fbShipping")]
|
||||
public class Shipping : MgEntityBase, IShipping
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
|
@ -10,6 +12,7 @@ public class Shipping : MgEntityBase, IShipping
|
|||
public DateTime ShippingDate { get; set; }
|
||||
public string LicencePlate { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains;
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
public class SippingDocument : MgEntityBase, ISippingDocument
|
||||
[Table(Name = "fbShippingDocument")]
|
||||
public class ShippingDocument : MgEntityBase, ISippingDocument
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int PartnerId { get; set; }
|
||||
|
|
@ -12,6 +14,7 @@ public class SippingDocument : MgEntityBase, ISippingDocument
|
|||
public DateTime ShippingDate { get; set; }
|
||||
public string Country { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains;
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
[Table(Name = "fbShippingItem")]
|
||||
public class ShippingItem : MgEntityBase, IShippingItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
|
@ -13,6 +15,7 @@ public class ShippingItem : MgEntityBase, IShippingItem
|
|||
public double MeasuredNetWeight { get; set; }
|
||||
public double MeasuredGrossWeight { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
using AyCode.Core.Loggers;
|
||||
using FruitBank.Common;
|
||||
using FruitBank.Common.Server.Controllers;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Server.Services.Loggers;
|
||||
using FruitBank.Common.Server.Services.SignalRs;
|
||||
using Mango.Nop.Core.Loggers;
|
||||
|
|
@ -12,9 +12,11 @@ using Microsoft.AspNetCore.SignalR;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nop.Core.Infrastructure;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Filters;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||
using Nop.Services.Catalog;
|
||||
using FruitBankDataController = Nop.Plugin.Misc.FruitBankPlugin.Controllers.FruitBankDataController;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;
|
||||
|
||||
|
|
@ -39,7 +41,10 @@ public class PluginNopStartup : INopStartup
|
|||
services.AddSingleton<IAcLogWriterBase, NopLogWriter>();
|
||||
services.AddSingleton<LoggerToLoggerApiController2>();
|
||||
//services.AddSingleton<SessionService>();
|
||||
services.AddScoped<FruitBankDataController>();
|
||||
|
||||
services.AddScoped<PartnerDbTable>();
|
||||
services.AddScoped<FruitBankDbContext>();
|
||||
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
|
||||
|
||||
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
|
||||
services.AddScoped<IPriceCalculationService, CustomPriceCalculationService>();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Nop.Data.Mapping;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Mapping;
|
||||
|
||||
|
|
@ -7,7 +8,14 @@ public partial class NameCompatibility : INameCompatibility
|
|||
/// <summary>
|
||||
/// Gets table name for mapping with the type
|
||||
/// </summary>
|
||||
public Dictionary<Type, string> TableNames => new();
|
||||
public Dictionary<Type, string> TableNames => new Dictionary<Type, string>
|
||||
{
|
||||
{ typeof(Partner), "fbPartner" },
|
||||
{ typeof(Shipping), "fbShipping" },
|
||||
{ typeof(ShippingItem), "fbShippingItem" },
|
||||
{ typeof(ShippingDocument), "fbShippingDocument" },
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets column name for mapping with the entity's property and type
|
||||
|
|
|
|||
Loading…
Reference in New Issue