dev
Last change
on this file since f3c4950 was f3c4950, checked in by Стојков Марко <mst@…>, 2 years ago |
Moderator can create categories
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[f3c4950] | 1 | using FinkiChattery.Common.Mediator.Contracs;
|
---|
| 2 | using FinkiChattery.Persistence.Models;
|
---|
| 3 | using FinkiChattery.Persistence.UnitOfWork;
|
---|
| 4 | using System;
|
---|
| 5 | using System.Threading;
|
---|
| 6 | using System.Threading.Tasks;
|
---|
| 7 |
|
---|
| 8 | namespace FinkiChattery.Commands.Moderating
|
---|
| 9 | {
|
---|
| 10 | public class CreateCategoryCommand : ICommand<Guid>
|
---|
| 11 | {
|
---|
| 12 | public CreateCategoryCommand(string categoryName)
|
---|
| 13 | {
|
---|
| 14 | CategoryName = categoryName;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public string CategoryName { get; }
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | public class CreateCategoryHandler : ICommandHandler<CreateCategoryCommand, Guid>
|
---|
| 21 | {
|
---|
| 22 | public CreateCategoryHandler(IUnitOfWork unitOfWork)
|
---|
| 23 | {
|
---|
| 24 | UnitOfWork = unitOfWork;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public IUnitOfWork UnitOfWork { get; }
|
---|
| 28 |
|
---|
| 29 | public async Task<Guid> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
|
---|
| 30 | {
|
---|
| 31 | var category = new Category()
|
---|
| 32 | {
|
---|
| 33 | Name = request.CategoryName
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | UnitOfWork.Categories.Add(category);
|
---|
| 37 |
|
---|
| 38 | await UnitOfWork.SaveAsync();
|
---|
| 39 |
|
---|
| 40 | return category.Uid;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.