Skip to content

Commit

Permalink
#5096 Added implementation of the ISoftDeletedEntity interface to the…
Browse files Browse the repository at this point in the history
… Store entity
  • Loading branch information
exileDev committed Aug 26, 2022
1 parent 30e52c6 commit dec19a9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/Libraries/Nop.Core/Domain/Stores/Store.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Localization;

namespace Nop.Core.Domain.Stores
{
/// <summary>
/// Represents a store
/// </summary>
public partial class Store : BaseEntity, ILocalizedEntity
public partial class Store : BaseEntity, ILocalizedEntity, ISoftDeletedEntity
{
/// <summary>
/// Gets or sets the store name
Expand Down Expand Up @@ -56,5 +57,10 @@ public partial class Store : BaseEntity, ILocalizedEntity
/// Gets or sets the company VAT (used in Europe Union countries)
/// </summary>
public string CompanyVat { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
public bool Deleted { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/Libraries/Nop.Data/Migrations/UpgradeTo460/StoreMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentMigrator;
using Nop.Core.Domain.Stores;
using Nop.Data.Mapping;

namespace Nop.Data.Migrations.UpgradeTo460
{
[NopMigration("2022-05-13 00:00:00", "Store soft deleting", MigrationProcessType.NoDependencies)]
public class StoreMigration : ForwardOnlyMigration
{
public override void Up()
{
if (!Schema.Table(NameCompatibilityManager.GetTableName(typeof(Store))).Column(nameof(Store.Deleted)).Exists())
{
//add new column
Alter.Table(NameCompatibilityManager.GetTableName(typeof(Store)))
.AddColumn(nameof(Store.Deleted)).AsBoolean().WithDefaultValue(false);

Alter.Table(NameCompatibilityManager.GetTableName(typeof(Store)))
.AlterColumn(nameof(Store.Deleted)).AsBoolean();
}
}
}
}
8 changes: 3 additions & 5 deletions src/Libraries/Nop.Services/Stores/StoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ public virtual async Task DeleteStoreAsync(Store store)
/// </returns>
public virtual async Task<IList<Store>> GetAllStoresAsync()
{
var result = await _storeRepository.GetAllAsync(query =>
return await _storeRepository.GetAllAsync(query =>
{
return from s in query orderby s.DisplayOrder, s.Id select s;
}, cache => default);

return result;
}, _ => default, includeDeleted: false);
}

/// <summary>
Expand All @@ -102,7 +100,7 @@ public virtual async Task<IList<Store>> GetAllStoresAsync()
/// </returns>
public virtual async Task<Store> GetStoreByIdAsync(int storeId)
{
return await _storeRepository.GetByIdAsync(storeId, cache => default);
return await _storeRepository.GetByIdAsync(storeId, cache => default, false);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/Nop.Web.Framework/WebStoreContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public virtual Store GetCurrentStore()
var allStores = _storeRepository.GetAll(query =>
{
return from s in query orderby s.DisplayOrder, s.Id select s;
}, cache => default);
}, _ => default, includeDeleted: false);

var store = allStores.FirstOrDefault(s => _storeService.ContainsHostValue(s, host));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,8 @@ protected virtual void CreateStoresMaps()
{
CreateMap<Store, StoreModel>()
.ForMember(model => model.AvailableLanguages, options => options.Ignore());
CreateMap<StoreModel, Store>();
CreateMap<StoreModel, Store>()
.ForMember(entity => entity.Deleted, options => options.Ignore());
}

/// <summary>
Expand Down

0 comments on commit dec19a9

Please sign in to comment.