improvements
This commit is contained in:
parent
379710e120
commit
38504edba6
|
|
@ -1,4 +1,5 @@
|
||||||
using Mango.Nop.Core.Repositories;
|
using Mango.Nop.Core.Repositories;
|
||||||
|
using Nop.Core;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,10 @@ public class AuctionDbTable: MgDbTableBase<Auction>
|
||||||
public AuctionDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ using Nop.Core;
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
||||||
{
|
{
|
||||||
|
|
||||||
public class Announcement : EntityBase, ITimeStampCreated
|
public class Announcement : MgEntityBase, ITimeStampCreated
|
||||||
{
|
{
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using AyCode.Interfaces.Entities;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using AyCode.Interfaces.Entities;
|
||||||
using AyCode.Interfaces.TimeStampInfo;
|
using AyCode.Interfaces.TimeStampInfo;
|
||||||
using Mango.Nop.Core.Entities;
|
using Mango.Nop.Core.Entities;
|
||||||
using Mango.Nop.Core.Interfaces;
|
using Mango.Nop.Core.Interfaces;
|
||||||
|
|
@ -7,7 +8,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
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 string AuctionName { get; set; }
|
||||||
public AuctionType AuctionType{ get; set; }
|
public AuctionType AuctionType{ get; set; }
|
||||||
|
|
@ -17,6 +18,9 @@ public class Auction: EntityBase, ITimeStampInfo//, ISoftRemoveEntityInt
|
||||||
|
|
||||||
public bool Closed { get; set; }
|
public bool Closed { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public List<ProductToAuctionMapping> ProductToAuctionMappings { get; } = [];
|
||||||
|
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
public DateTime Modified { get; set; }
|
public DateTime Modified { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ using Nop.Core;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
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 ProductAuctionMappingId { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using Nop.Core;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
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 Created { get; set; }
|
||||||
public DateTime Modified { 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;
|
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 ProductId { get; set; }
|
||||||
public int AuctionId { get; set; }
|
public int AuctionId { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -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,5 +1,6 @@
|
||||||
using Nop.Core;
|
using Nop.Core;
|
||||||
using Nop.Core.Caching;
|
using Nop.Core.Caching;
|
||||||
|
using Nop.Core.Domain.Customers;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||||
|
|
@ -32,7 +33,7 @@ public class AuctionService : IAuctionService
|
||||||
//protected readonly IRepository<Auction> _auctionRepository;
|
//protected readonly IRepository<Auction> _auctionRepository;
|
||||||
protected readonly IShortTermCacheManager _shortTermCacheManager;
|
protected readonly IShortTermCacheManager _shortTermCacheManager;
|
||||||
protected readonly IStaticCacheManager _staticCacheManager;
|
protected readonly IStaticCacheManager _staticCacheManager;
|
||||||
|
protected readonly IWorkContext _workContext;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
|
|
@ -43,7 +44,7 @@ public class AuctionService : IAuctionService
|
||||||
/// <param name="customerBidRepository">Store pickup point repository</param>
|
/// <param name="customerBidRepository">Store pickup point repository</param>
|
||||||
/// <param name="shortTermCacheManager">Short term cache manager</param>
|
/// <param name="shortTermCacheManager">Short term cache manager</param>
|
||||||
/// <param name="staticCacheManager">Cache manager</param>
|
/// <param name="staticCacheManager">Cache manager</param>
|
||||||
public AuctionService(AuctionDbContext ctx, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager)
|
public AuctionService(AuctionDbContext ctx, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, IWorkContext workContext)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
//_customerBidRepository = customerBidRepository;
|
//_customerBidRepository = customerBidRepository;
|
||||||
|
|
@ -51,12 +52,23 @@ public class AuctionService : IAuctionService
|
||||||
|
|
||||||
_shortTermCacheManager = shortTermCacheManager;
|
_shortTermCacheManager = shortTermCacheManager;
|
||||||
_staticCacheManager = staticCacheManager;
|
_staticCacheManager = staticCacheManager;
|
||||||
|
_workContext = workContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#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>
|
/// <summary>
|
||||||
/// Gets all bids
|
/// Gets all bids
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -88,16 +100,22 @@ public class AuctionService : IAuctionService
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task InsertBidAsync(AuctionBid auctionBid)
|
public virtual async Task InsertBidAsync(AuctionBid auctionBid)
|
||||||
|
{
|
||||||
|
if (await ValidateAuctionBid(auctionBid))
|
||||||
{
|
{
|
||||||
await _ctx.AuctionBids.InsertAsync(auctionBid, false);
|
await _ctx.AuctionBids.InsertAsync(auctionBid, false);
|
||||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual async Task UpdateBidAsync(AuctionBid auctionBid)
|
public virtual async Task UpdateBidAsync(AuctionBid auctionBid)
|
||||||
|
{
|
||||||
|
if (await ValidateAuctionBid(auctionBid))
|
||||||
{
|
{
|
||||||
await _ctx.AuctionBids.UpdateAsync(auctionBid, false);
|
await _ctx.AuctionBids.UpdateAsync(auctionBid, false);
|
||||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a pickup point
|
/// Deletes a pickup point
|
||||||
|
|
@ -117,9 +135,15 @@ public class AuctionService : IAuctionService
|
||||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<Auction>> GetAllAuctionsAsync()
|
public async Task<IList<Auction>> GetAllAuctionsAsync()
|
||||||
{
|
{
|
||||||
return (await _ctx.Auctions.GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default)).ToList();
|
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
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,5 @@ public interface IAuctionService
|
||||||
|
|
||||||
Task InsertAuctionAsync(Auction auction);
|
Task InsertAuctionAsync(Auction auction);
|
||||||
|
|
||||||
Task<List<Auction>> GetAllAuctionsAsync();
|
Task<IList<Auction>> GetAllAuctionsAsync();
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue