Changeset 95d80e4 for src/FinkiChattery/FinkiChattery.Commands/Questioning/AskQuestion/AskQuestionCommand.cs
- Timestamp:
- 10/21/21 19:16:53 (3 years ago)
- Branches:
- dev
- Children:
- 3b395c5
- Parents:
- 9885bee
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FinkiChattery/FinkiChattery.Commands/Questioning/AskQuestion/AskQuestionCommand.cs
r9885bee r95d80e4 1 1 using FinkiChattery.Common.Mediator.Contracs; 2 2 using FinkiChattery.Common.User; 3 using FinkiChattery.Persistence.Context;4 3 using FinkiChattery.Persistence.Models; 5 using FinkiChattery.Persistence. Repositories;4 using FinkiChattery.Persistence.UnitOfWork; 6 5 using System; 7 6 using System.Collections.Generic; … … 27 26 public class AskQuestionHandler : ICommandHandler<AskQuestionCommand, Guid> 28 27 { 29 public AskQuestionHandler( ApplicationDbContext dbContext, ICategoriesRepo categoriesRepo, IStudentRepo studentRepo, ICurrentUser currentUser)28 public AskQuestionHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser) 30 29 { 31 DbContext = dbContext; 32 CategoriesRepo = categoriesRepo; 33 StudentRepo = studentRepo; 30 UnitOfWork = unitOfWork; 34 31 CurrentUser = currentUser; 35 32 } 36 33 37 public ApplicationDbContext DbContext { get; } 38 public ICategoriesRepo CategoriesRepo { get; } 39 public IStudentRepo StudentRepo { get; } 34 public IUnitOfWork UnitOfWork { get; } 40 35 public ICurrentUser CurrentUser { get; } 41 36 42 37 public async Task<Guid> Handle(AskQuestionCommand request, CancellationToken cancellationToken) 43 38 { 44 var questionCategories = await CategoriesRepo.GetCategories(request.Categories);45 var currentStudent = await StudentRepo.GetStudent(CurrentUser.Id);39 var questionCategories = await UnitOfWork.Categories.GetCategories(request.Categories); 40 var currentStudent = await UnitOfWork.Students.GetStudent(CurrentUser.Id); 46 41 47 42 var questionDatabaseEntity = new Question() … … 60 55 } 61 56 62 DbContext.Questions.Add(questionDatabaseEntity);63 await DbContext.SaveChangesAsync();57 UnitOfWork.Questions.Add(questionDatabaseEntity); 58 await UnitOfWork.SaveAsync(); 64 59 return questionDatabaseEntity.Uid; 65 60 }
Note:
See TracChangeset
for help on using the changeset viewer.