-
Notifications
You must be signed in to change notification settings - Fork 525
Expand file tree
/
Copy pathAddCollectionCommandHandler.cs
More file actions
36 lines (32 loc) · 1.41 KB
/
AddCollectionCommandHandler.cs
File metadata and controls
36 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Grand.Module.Api.Commands.Models.Catalog;
using Grand.Module.Api.DTOs.Catalog;
using Grand.Module.Api.Extensions;
using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Seo;
using MediatR;
namespace Grand.Module.Api.Commands.Handlers.Catalog;
public class AddCollectionCommandHandler : IRequestHandler<AddCollectionCommand, CollectionDto>
{
private readonly ICollectionService _collectionService;
private readonly ISlugService _slugService;
private readonly ISeNameService _seNameService;
public AddCollectionCommandHandler(
ICollectionService collectionService,
ISlugService slugService,
ISeNameService seNameService)
{
_collectionService = collectionService;
_slugService = slugService;
_seNameService = seNameService;
}
public async Task<CollectionDto> Handle(AddCollectionCommand request, CancellationToken cancellationToken)
{
var collection = request.Model.ToEntity();
await _collectionService.InsertCollection(collection);
request.Model.SeName = await _seNameService.ValidateSeName(collection, request.Model.SeName, collection.Name, true);
collection.SeName = request.Model.SeName;
await _collectionService.UpdateCollection(collection);
await _slugService.SaveSlug(collection, request.Model.SeName, "");
return collection.ToModel();
}
}