Implement AuctionDtos; improvements, fixes, etc...
This commit is contained in:
parent
38ec5c475e
commit
3f5eb9f0db
|
|
@ -0,0 +1,9 @@
|
|||
using AyCode.Interfaces;
|
||||
using AyCode.Interfaces.Entities;
|
||||
|
||||
namespace Mango.Nop.Core.Interfaces;
|
||||
|
||||
public interface IMgModelDtoBase : IEntityInt //: IAcModelDtoBase //TODO: IEntityGuid gond... - J.
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
using System.Linq.Expressions;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Core;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Domain.Common;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
|
||||
|
|
@ -16,64 +19,160 @@ public class MgDbTableBase<TEntity>(IEventPublisher eventPublisher, INopDataProv
|
|||
protected IShortTermCacheManager ShortTermCacheManager = shortTermCacheManager;
|
||||
protected IStaticCacheManager StaticCacheManager = staticCacheManager;
|
||||
|
||||
#region SetTimeStampInfos
|
||||
private static void SetTimeStampCreated(TEntity entity)
|
||||
{
|
||||
if (typeof(TEntity).GetInterface(nameof(ITimeStampCreated)) != null)
|
||||
{
|
||||
((entity as ITimeStampCreated)!).Created = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetTimeStampModified(TEntity entity)
|
||||
{
|
||||
if (typeof(TEntity).GetInterface(nameof(ITimeStampModified)) != null)
|
||||
{
|
||||
((entity as ITimeStampModified)!).Modified = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
#endregion SetTimeStampInfos
|
||||
|
||||
#region OnCrudEvents
|
||||
private void OnInsert(IList<TEntity> entities)
|
||||
{
|
||||
foreach (var entity in entities) OnInsert(entity);
|
||||
}
|
||||
|
||||
protected virtual void OnInsert(TEntity entity)
|
||||
{
|
||||
SetTimeStampCreated(entity);
|
||||
SetTimeStampModified(entity);
|
||||
}
|
||||
|
||||
private void OnUpdate(IList<TEntity> entities)
|
||||
{
|
||||
foreach (var entity in entities) OnUpdate(entity);
|
||||
}
|
||||
|
||||
protected virtual void OnUpdate(TEntity entity) => SetTimeStampModified(entity);
|
||||
|
||||
private void OnDelete(IList<TEntity> entities)
|
||||
{
|
||||
foreach (var entity in entities) OnDelete(entity);
|
||||
}
|
||||
|
||||
protected virtual void OnDelete(TEntity entity)
|
||||
{
|
||||
if (typeof(TEntity).GetInterface(nameof(ISoftDeletedEntity)) != null)
|
||||
{
|
||||
SetTimeStampModified(entity);
|
||||
}
|
||||
|
||||
}
|
||||
#endregion OnCrudEvents
|
||||
|
||||
#region Insert
|
||||
|
||||
public override void Insert(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnInsert(entity);
|
||||
base.Insert(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override void Insert(IList<TEntity> entities, bool publishEvent = true)
|
||||
{
|
||||
OnInsert(entities);
|
||||
base.Insert(entities, publishEvent);
|
||||
}
|
||||
|
||||
public override Task InsertAsync(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnInsert(entity);
|
||||
return base.InsertAsync(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override Task InsertAsync(IList<TEntity> entities, bool publishEvent = true)
|
||||
{
|
||||
OnInsert(entities);
|
||||
return base.InsertAsync(entities, publishEvent);
|
||||
}
|
||||
#endregion Insert
|
||||
|
||||
#region Update
|
||||
public override void Update(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnUpdate(entity);
|
||||
base.Update(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override void Update(IList<TEntity> entities, bool publishEvent = true)
|
||||
{
|
||||
OnUpdate(entities);
|
||||
base.Update(entities, publishEvent);
|
||||
}
|
||||
|
||||
public override Task UpdateAsync(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnUpdate(entity);
|
||||
return base.UpdateAsync(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override Task UpdateAsync(IList<TEntity> entities, bool publishEvent = true)
|
||||
{
|
||||
OnUpdate(entities);
|
||||
return base.UpdateAsync(entities, publishEvent);
|
||||
}
|
||||
#endregion Update
|
||||
|
||||
#region Delete
|
||||
protected override Task DeleteAsync(IList<TEntity> entities)
|
||||
{
|
||||
OnDelete(entities);
|
||||
return base.DeleteAsync(entities);
|
||||
}
|
||||
|
||||
protected override Task DeleteAsync<T>(IList<T> entities)
|
||||
{
|
||||
if(typeof(T) == typeof(TEntity)) OnDelete(entities.Cast<TEntity>().ToList());
|
||||
|
||||
return base.DeleteAsync(entities);
|
||||
}
|
||||
|
||||
protected override IQueryable<TEntity> AddDeletedFilter(IQueryable<TEntity> query, in bool includeDeleted)
|
||||
{
|
||||
foreach (var entity in query) OnDelete(entity);
|
||||
|
||||
return base.AddDeletedFilter(query, in includeDeleted);
|
||||
}
|
||||
|
||||
public override Task DeleteAsync(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnDelete(entity);
|
||||
return base.DeleteAsync(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override Task DeleteAsync(IList<TEntity> entities, bool publishEvent = true)
|
||||
{
|
||||
OnDelete(entities);
|
||||
return base.DeleteAsync(entities, publishEvent);
|
||||
}
|
||||
|
||||
public override Task<int> DeleteAsync(Expression<Func<TEntity, bool>> predicate)
|
||||
{
|
||||
//TODO:ide mit kéne?! - J.
|
||||
return base.DeleteAsync(predicate);
|
||||
}
|
||||
|
||||
public override void Delete(TEntity entity, bool publishEvent = true)
|
||||
{
|
||||
OnDelete(entity);
|
||||
base.Delete(entity, publishEvent);
|
||||
}
|
||||
|
||||
public override int Delete(Expression<Func<TEntity, bool>> predicate)
|
||||
{
|
||||
//TODO:ide mit kéne?! - J.
|
||||
return base.Delete(predicate);
|
||||
}
|
||||
#endregion Delete
|
||||
}
|
||||
Loading…
Reference in New Issue