source: src/FinkiChattery/FinkiChattery.Commands/Moderating/CreateCategory/CreateCategoryCommand.cs@ f3c4950

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
Line 
1using FinkiChattery.Common.Mediator.Contracs;
2using FinkiChattery.Persistence.Models;
3using FinkiChattery.Persistence.UnitOfWork;
4using System;
5using System.Threading;
6using System.Threading.Tasks;
7
8namespace 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.