Ignore:
Timestamp:
10/21/21 19:17:43 (3 years ago)
Author:
Стојков Марко <mst@…>
Branches:
dev
Children:
31c006c, 45cf412
Parents:
9885bee (diff), 95d80e4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged feature unit of work into dev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/AskQuestion/AskQuestionCommand.cs

    r9885bee r3b395c5  
    11using FinkiChattery.Common.Mediator.Contracs;
    22using FinkiChattery.Common.User;
    3 using FinkiChattery.Persistence.Context;
    43using FinkiChattery.Persistence.Models;
    5 using FinkiChattery.Persistence.Repositories;
     4using FinkiChattery.Persistence.UnitOfWork;
    65using System;
    76using System.Collections.Generic;
     
    2726    public class AskQuestionHandler : ICommandHandler<AskQuestionCommand, Guid>
    2827    {
    29         public AskQuestionHandler(ApplicationDbContext dbContext, ICategoriesRepo categoriesRepo, IStudentRepo studentRepo, ICurrentUser currentUser)
     28        public AskQuestionHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser)
    3029        {
    31             DbContext = dbContext;
    32             CategoriesRepo = categoriesRepo;
    33             StudentRepo = studentRepo;
     30            UnitOfWork = unitOfWork;
    3431            CurrentUser = currentUser;
    3532        }
    3633
    37         public ApplicationDbContext DbContext { get; }
    38         public ICategoriesRepo CategoriesRepo { get; }
    39         public IStudentRepo StudentRepo { get; }
     34        public IUnitOfWork UnitOfWork { get; }
    4035        public ICurrentUser CurrentUser { get; }
    4136
    4237        public async Task<Guid> Handle(AskQuestionCommand request, CancellationToken cancellationToken)
    4338        {
    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);
    4641
    4742            var questionDatabaseEntity = new Question()
     
    6055            }
    6156
    62             DbContext.Questions.Add(questionDatabaseEntity);
    63             await DbContext.SaveChangesAsync();
     57            UnitOfWork.Questions.Add(questionDatabaseEntity);
     58            await UnitOfWork.SaveAsync();
    6459            return questionDatabaseEntity.Uid;
    6560        }
Note: See TracChangeset for help on using the changeset viewer.