Skip to content

Commit c8a29a9

Browse files
authored
Code refactoring for #1090 (#1092)
1 parent 4565b57 commit c8a29a9

File tree

15 files changed

+4821
-62
lines changed

15 files changed

+4821
-62
lines changed

src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Views/Product/ProductDetail.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
<div class="back-in-stock-subscribe">
204204
<form action="api/stocks/back-in-stock">
205205
<div>
206-
@if (SignInManager.IsSignedIn(User))
206+
@if (User.Identity.IsAuthenticated)
207207
{
208208
<p>Subscribe and we'll notify you when the product is back in stock.</p>
209209
<div class="d-flex">

src/Modules/SimplCommerce.Module.Core/Extensions/WorkContext.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public WorkContext(UserManager<User> userManager,
3333
_configuration = configuration;
3434
}
3535

36-
public string GetCurrentHostName()
37-
{
38-
return _httpContext.Request.Host.Value;
39-
}
36+
public string GetCurrentHostName() => _httpContext.Request.Host.Value;
4037

4138
public async Task<User> GetCurrentUser()
4239
{

src/Modules/SimplCommerce.Module.Inventory/Areas/Inventory/Controllers/StockApiController.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class StockApiController : Controller
2424
private readonly IWorkContext _workContext;
2525
private readonly IRepository<Warehouse> _warehouseRepository;
2626
private readonly IRepository<StockHistory> _stockHistoryRepository;
27-
private readonly IRepository<BackInStockSubscription> _backInStockSubscriptionRepository;
27+
private readonly IRepository<ProductBackInStockSubscription> _backInStockSubscriptionRepository;
2828

29-
public StockApiController(IRepository<Stock> stockRepository, IStockService stockService, IWorkContext workContext, IRepository<Warehouse> warehouseRepository, IRepository<StockHistory> stockHistoryRepository, IRepository<BackInStockSubscription> backInStockSubscriptionRepository, IStockSubscriptionService stockSubscriptionService)
29+
public StockApiController(IRepository<Stock> stockRepository, IStockService stockService, IWorkContext workContext, IRepository<Warehouse> warehouseRepository, IRepository<StockHistory> stockHistoryRepository, IRepository<ProductBackInStockSubscription> backInStockSubscriptionRepository, IStockSubscriptionService stockSubscriptionService)
3030
{
3131
_stockRepository = stockRepository;
3232
_stockService = stockService;
@@ -145,13 +145,12 @@ public async Task<IActionResult> GetStockHistory(int warehouseId, int productId)
145145
public async Task<IActionResult> BackInStockSubscribe(long productId, string customerEmail)
146146
{
147147
if (await _backInStockSubscriptionRepository.Query()
148-
.Where(o => o.ProductId == productId && o.CustomerEmail == customerEmail)
149-
.AnyAsync())
148+
.AnyAsync(o => o.ProductId == productId && o.CustomerEmail == customerEmail))
150149
{
151150
return Conflict();
152151
}
153152

154-
await _stockSubscriptionService.BackInStockSubscribeAsync(productId, customerEmail);
153+
await _stockSubscriptionService.ProductBackInStockSubscribeAsync(productId, customerEmail);
155154

156155
return Ok();
157156
}

src/Modules/SimplCommerce.Module.Inventory/Areas/Inventory/Views/EmailTemplates/BackInStockEmail.cshtml renamed to src/Modules/SimplCommerce.Module.Inventory/Areas/Inventory/Views/EmailTemplates/ProductBackInStockEmail.cshtml

File renamed without changes.

src/Modules/SimplCommerce.Module.Inventory/Event/BackInStockSendEmailHandler.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Modules/SimplCommerce.Module.Inventory/Event/BackInStock.cs renamed to src/Modules/SimplCommerce.Module.Inventory/Event/ProductBackInStock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace SimplCommerce.Module.Inventory.Event
99
{
10-
public class BackInStock : INotification
10+
public class ProductBackInStock : INotification
1111
{
1212
public long ProductId { get; set; }
1313
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using MediatR;
8+
using SimplCommerce.Module.Inventory.Services;
9+
10+
namespace SimplCommerce.Module.Inventory.Event
11+
{
12+
public class ProductBackInStockSendEmailHandler : INotificationHandler<ProductBackInStock>
13+
{
14+
public readonly IStockSubscriptionService _stockSubscriptionService;
15+
16+
public ProductBackInStockSendEmailHandler(IStockSubscriptionService stockSubscriptionService)
17+
=> _stockSubscriptionService = stockSubscriptionService;
18+
19+
public async Task Handle(ProductBackInStock notification, CancellationToken cancellationToken)
20+
=> await _stockSubscriptionService.ProductBackInStockSendNotificationsAsync(notification.ProductId);
21+
}
22+
}

src/Modules/SimplCommerce.Module.Inventory/Models/BackInStockSubscription.cs renamed to src/Modules/SimplCommerce.Module.Inventory/Models/ProductBackInStockSubscription.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
namespace SimplCommerce.Module.Inventory.Models
99
{
10-
public class BackInStockSubscription : EntityBase
10+
public class ProductBackInStockSubscription : EntityBase
1111
{
1212
public long ProductId { get; set; }
13+
1314
public string CustomerEmail { get; set; }
1415
}
1516
}

src/Modules/SimplCommerce.Module.Inventory/ModuleInitializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public void ConfigureServices(IServiceCollection serviceCollection)
1717
{
1818
serviceCollection.AddTransient<IStockService, StockService>();
1919
serviceCollection.AddTransient<IStockSubscriptionService, StockSubscriptionService>();
20-
serviceCollection.AddTransient<INotificationHandler<BackInStock>, BackInStockSendEmailHandler>();
21-
20+
serviceCollection.AddTransient<INotificationHandler<ProductBackInStock>, ProductBackInStockSendEmailHandler>();
2221

2322
GlobalConfiguration.RegisterAngularModule("simplAdmin.inventory");
2423
}

src/Modules/SimplCommerce.Module.Inventory/Services/IStockSubscriptionService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace SimplCommerce.Module.Inventory.Services
88
{
99
public interface IStockSubscriptionService
1010
{
11-
Task BackInStockSubscribeAsync(long productId, string customerEmail);
11+
Task ProductBackInStockSubscribeAsync(long productId, string customerEmail);
1212

13-
Task BackInStockSendNotificationsAsync(long productId);
13+
Task ProductBackInStockSendNotificationsAsync(long productId);
1414
}
1515
}

0 commit comments

Comments
 (0)