Compare commits
8 Commits
53abcb5a64
...
8ad64ac523
| Author | SHA1 | Date |
|---|---|---|
|
|
8ad64ac523 | |
|
|
93c22a2959 | |
|
|
38504edba6 | |
|
|
379710e120 | |
|
|
8af9b95fc5 | |
|
|
56474e1bf6 | |
|
|
764173485b | |
|
|
a48ad3d132 |
|
|
@ -68,7 +68,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
|||
|
||||
if (viewModel.IsActive == true)
|
||||
{
|
||||
var announcement = new MessageBase
|
||||
var announcement = new MessageWrapper
|
||||
{
|
||||
MessageType = "announcement",
|
||||
Data = new AnnouncementMessage
|
||||
|
|
@ -108,7 +108,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
|||
//await _announcementService.InsertAsync(objOfAuctionBid);
|
||||
|
||||
|
||||
var bid = new MessageBase
|
||||
var bid = new MessageWrapper
|
||||
{
|
||||
MessageType = "bidNotification",
|
||||
Data = new BidNotificationMessage
|
||||
|
|
|
|||
|
|
@ -110,10 +110,13 @@ public class AuctionPluginAdminController : BasePluginController
|
|||
|
||||
}
|
||||
|
||||
public IActionResult TestPage()
|
||||
public async Task<IActionResult> TestPage()
|
||||
{
|
||||
var model = new TestPageViewModel();
|
||||
model.Message = "Teszt üzenet";
|
||||
|
||||
var auctions = await _auctionService.GetAllAuctionsAsync();
|
||||
model.Message = $"Teszt üzenet; Auctions count: {auctions.Count}";
|
||||
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/TestPage.cshtml", model);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
|
|||
public string Title { get; set; }
|
||||
public string Message { get; set; }
|
||||
public Auction TestAuction { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public class AuctionBidDbTable: MgDbTableBase<AuctionBid>
|
||||
{
|
||||
public AuctionBidDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
using System;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>, IAuctionBidDbSet<AuctionBidDbTable>
|
||||
{
|
||||
public AuctionDbTable Auctions { get; set; }
|
||||
public AuctionBidDbTable AuctionBids { get; set; }
|
||||
|
||||
public EntityRepository<Auction> Auctions2 { get; set; }
|
||||
public IRepository<AuctionBid> AuctionBids2 { get; set; }
|
||||
|
||||
|
||||
public AuctionDbContext(INopDataProvider dataProvider, AuctionDbTable auctionDbTable, AuctionBidDbTable auctionBidDbTable) : base(dataProvider)
|
||||
{
|
||||
Auctions = auctionDbTable;
|
||||
AuctionBids = auctionBidDbTable;
|
||||
|
||||
//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;
|
||||
//}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using Mango.Nop.Core.Entities;
|
||||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public class AuctionDbTable: MgDbTableBase<Auction>
|
||||
{
|
||||
public AuctionDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<IList<Auction>> GetAllAuctionsAsync()
|
||||
{
|
||||
return GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
using System.Transactions;
|
||||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Domain.Catalog;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Data.DataProviders;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public class AuctionMgDal : MgDalBase<MgDbContextBase>
|
||||
{
|
||||
public IRepository<Auction> Auctions { get; set; }
|
||||
|
||||
//public AuctionMgDal(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
||||
// : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
||||
//{
|
||||
//}
|
||||
|
||||
public async Task AddProductToAuction(Product product, Auction auction)
|
||||
{
|
||||
//using var dataContext = ((MsSqlNopDataProvider)_dataProvider).
|
||||
//dataProvider.GetTable<TEntity>().wh
|
||||
|
||||
//using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
|
||||
//await _dataProvider.InsertEntityAsync()
|
||||
// InsertEntityAsync(product);
|
||||
//transaction.Complete();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public interface IAuctionBidDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<AuctionBid>
|
||||
{
|
||||
public TDbTable AuctionBids { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
||||
public interface IAuctionDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<Auction>
|
||||
{
|
||||
public TDbTable Auctions { get; set; }
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using Nop.Core;
|
|||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
||||
{
|
||||
|
||||
public class Announcement : EntityBase, ITimeStampCreated
|
||||
public class Announcement : MgEntityBase, ITimeStampCreated
|
||||
{
|
||||
|
||||
public string Name { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using AyCode.Interfaces.Entities;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using LinqToDB.Mapping;
|
||||
using Mango.Nop.Core.Entities;
|
||||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Core;
|
||||
|
|
@ -7,9 +9,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
public class Auction: EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
public partial class Auction: MgEntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
{
|
||||
public string AuctionName { get; set; }
|
||||
|
||||
public AuctionType AuctionType{ get; set; }
|
||||
|
||||
public DateTime StartDateUtc { get; set; }
|
||||
|
|
@ -17,6 +20,11 @@ public class Auction: EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
|||
|
||||
public bool Closed { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
[NotColumn]
|
||||
public List<ProductToAuctionMapping> ProductToAuctionMappings { get; } = [];
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -5,8 +5,10 @@ using Nop.Core;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
||||
{
|
||||
public class AuctionBid : EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
public partial class AuctionBid : MgEntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
{
|
||||
public int ProductAuctionMappingId { get; set; }
|
||||
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using Nop.Core;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
public class AuctionItem : EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
public partial class AuctionItem : MgEntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
{
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
public class ProductToAuctionMapping : EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
public partial class ProductToAuctionMapping : MgEntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int AuctionId { get; set; }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||
{
|
||||
public class MessageBase
|
||||
public class MessageWrapper
|
||||
{
|
||||
public string MessageType { get; set; }
|
||||
public object Data { get; set; }
|
||||
|
|
@ -10,6 +10,7 @@ using Nop.Core;
|
|||
using Nop.Core.Caching;
|
||||
using Nop.Core.Infrastructure;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||
using Nop.Services.Catalog;
|
||||
|
|
@ -53,8 +54,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
|
|||
services.AddScoped<IAuctionService, AuctionService>();
|
||||
services.AddScoped<IProductAttributeService, ProductAttributeService>();
|
||||
services.AddScoped<UrlHelperFactory>();
|
||||
services.AddScoped<IActionContextAccessor, ActionContextAccessor>();
|
||||
services.AddScoped<IRouteProvider, RouteProvider>();
|
||||
services.AddScoped<IActionContextAccessor, ActionContextAccessor>();
|
||||
|
||||
services.AddScoped<AuctionDbTable>();
|
||||
services.AddScoped<AuctionBidDbTable>();
|
||||
services.AddScoped<AuctionDbContext>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
using FluentMigrator;
|
||||
using FluentMigrator.Builders.Create.Table;
|
||||
using Nop.Data.Mapping.Builders;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
using Nop.Data.Extensions;
|
||||
using System.Data;
|
||||
using Nop.Core.Domain.Catalog;
|
||||
using Nop.Core.Domain.Common;
|
||||
using Nop.Data.Mapping;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Mapping.Builders;
|
||||
|
||||
public class ProductToAuctionMappingBuilder : NopEntityBuilder<ProductToAuctionMapping>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Apply entity configuration
|
||||
/// </summary>
|
||||
/// <param name="table">Create table expression builder</param>
|
||||
public override void MapEntity(CreateTableExpressionBuilder table)
|
||||
{
|
||||
table.WithColumn(nameof(ProductToAuctionMapping.Id)).AsInt32().PrimaryKey()
|
||||
|
||||
.WithColumn(nameof(ProductToAuctionMapping.AuctionId)).AsInt32().ForeignKey<Auction>(onDelete: Rule.None) //Rule.Cascade??
|
||||
.WithColumn(nameof(ProductToAuctionMapping.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.None) //Rule.Cascade??
|
||||
|
||||
.WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J.
|
||||
|
||||
.WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable()
|
||||
.WithColumn(nameof(ProductToAuctionMapping.BidPrice)).AsInt32().NotNullable()
|
||||
.WithColumn(nameof(ProductToAuctionMapping.BidAmount)).AsInt32().NotNullable().WithDefaultValue(1)
|
||||
.WithColumn(nameof(ProductToAuctionMapping.Created)).AsDateTime().NotNullable()
|
||||
.WithColumn(nameof(ProductToAuctionMapping.Modified)).AsDateTime().NotNullable().WithDefault(SystemMethods.CurrentUTCDateTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
using Nop.Core;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Domain.Customers;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||
|
|
@ -26,11 +28,12 @@ public class AuctionService : IAuctionService
|
|||
|
||||
#region Fields
|
||||
|
||||
protected readonly IRepository<AuctionBid> _customerBidRepository;
|
||||
protected readonly IRepository<Auction> _auctionRepository;
|
||||
protected readonly AuctionDbContext _ctx;
|
||||
//protected readonly IRepository<AuctionBid> _customerBidRepository;
|
||||
//protected readonly IRepository<Auction> _auctionRepository;
|
||||
protected readonly IShortTermCacheManager _shortTermCacheManager;
|
||||
protected readonly IStaticCacheManager _staticCacheManager;
|
||||
|
||||
protected readonly IWorkContext _workContext;
|
||||
#endregion
|
||||
|
||||
#region Ctor
|
||||
|
|
@ -41,22 +44,31 @@ public class AuctionService : IAuctionService
|
|||
/// <param name="customerBidRepository">Store pickup point repository</param>
|
||||
/// <param name="shortTermCacheManager">Short term cache manager</param>
|
||||
/// <param name="staticCacheManager">Cache manager</param>
|
||||
public AuctionService(
|
||||
IRepository<AuctionBid> customerBidRepository,
|
||||
IRepository<Auction> auctionRepository,
|
||||
IShortTermCacheManager shortTermCacheManager,
|
||||
IStaticCacheManager staticCacheManager)
|
||||
public AuctionService(AuctionDbContext ctx, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, IWorkContext workContext)
|
||||
{
|
||||
_customerBidRepository = customerBidRepository;
|
||||
_auctionRepository = auctionRepository;
|
||||
_ctx = ctx;
|
||||
//_customerBidRepository = customerBidRepository;
|
||||
//_auctionRepository = auctionRepository;
|
||||
|
||||
_shortTermCacheManager = shortTermCacheManager;
|
||||
_staticCacheManager = staticCacheManager;
|
||||
_workContext = workContext;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private async Task<bool> ValidateAuctionBid(AuctionBid auctionBid)
|
||||
{
|
||||
auctionBid.CustomerId = (await _workContext.GetCurrentCustomerAsync()).Id; //elvileg megnézi cache-ben, csak utána DB-zik! - J.
|
||||
auctionBid.Modified = DateTime.UtcNow;
|
||||
|
||||
//etc...
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all bids
|
||||
/// </summary>
|
||||
|
|
@ -84,19 +96,25 @@ public class AuctionService : IAuctionService
|
|||
|
||||
public virtual async Task<AuctionBid> GetBidByIdAsync(int bidId)
|
||||
{
|
||||
return await _customerBidRepository.GetByIdAsync(bidId);
|
||||
return await _ctx.AuctionBids.GetByIdAsync(bidId);
|
||||
}
|
||||
|
||||
public virtual async Task InsertBidAsync(AuctionBid auctionBid)
|
||||
{
|
||||
await _customerBidRepository.InsertAsync(auctionBid, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
if (await ValidateAuctionBid(auctionBid))
|
||||
{
|
||||
await _ctx.AuctionBids.InsertAsync(auctionBid, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task UpdateBidAsync(AuctionBid auctionBid)
|
||||
{
|
||||
await _customerBidRepository.UpdateAsync(auctionBid, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
if (await ValidateAuctionBid(auctionBid))
|
||||
{
|
||||
await _ctx.AuctionBids.UpdateAsync(auctionBid, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -106,16 +124,28 @@ public class AuctionService : IAuctionService
|
|||
/// <returns>A task that represents the asynchronous operation</returns>
|
||||
public virtual async Task DeleteBidAsync(AuctionBid pickupPoint)
|
||||
{
|
||||
await _customerBidRepository.DeleteAsync(pickupPoint, false);
|
||||
await _ctx.AuctionBids.DeleteAsync(pickupPoint, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
}
|
||||
|
||||
#region auctions
|
||||
public virtual async Task InsertAuctionAsync(Auction auction)
|
||||
{
|
||||
await _auctionRepository.InsertAsync(auction, false);
|
||||
await _ctx.Auctions.InsertAsync(auction, false);
|
||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||
}
|
||||
|
||||
public async Task<IList<Auction>> GetAllAuctionsAsync()
|
||||
{
|
||||
return await _ctx.Auctions.GetAllAuctionsAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false)
|
||||
{
|
||||
//return (await _ctx.Auctions.GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default)).ToList();
|
||||
return [];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -30,4 +30,6 @@ public interface IAuctionService
|
|||
Task DeleteBidAsync(AuctionBid pickupPoint);
|
||||
|
||||
Task InsertAuctionAsync(Auction auction);
|
||||
|
||||
Task<IList<Auction>> GetAllAuctionsAsync();
|
||||
}
|
||||
Loading…
Reference in New Issue