public static CqrsContext AddDistributedCache(this CqrsContext context)
        {
            context.Services.Add(new ServiceDescriptor(
                                     typeof(IPipelineBehavior <,>), typeof(CacheBehaviour <,>),
                                     context.ServiceLifetime));

            return(context);
        }
示例#2
0
        public static CqrsContext AddValidation(this CqrsContext context)
        {
            context.Services.Add(new ServiceDescriptor(
                                     typeof(IPipelineBehavior <,>), typeof(ValidationBehaviour <,>),
                                     context.ServiceLifetime));

            return(context);
        }
        public static CqrsContext AddErrorHandler(this CqrsContext context)
        {
            context.Services.Add(new ServiceDescriptor(
                                     typeof(IPipelineBehavior <,>), typeof(ErrorHandlerBehaviour <,>),
                                     context.ServiceLifetime));

            return(context);
        }
示例#4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CqrsContext cqrsContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            cqrsContext.Database.EnsureCreated();
        }
示例#5
0
        public async Task AfterExecute(CreateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var visitor = await _visitorsRepository.GetById(new ObjectId(cmd.VisitorId));

            var msg = $"Уважаемый(-ая) {visitor.FirstName}, будем рады видеть Вас в нашем офисе";

            using (var client = new HttpClient())
            {
                var r = await client.GetAsync($"https://smsc.ru/sys/send.php?login=movchinnikov&psw=qwerty&phones={visitor.PhoneNumber}&mes={msg}");
            }
        }
示例#6
0
        public async Task <TResult> ExecuteQuery <TQuery, TResult>(TQuery query, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
            where TQuery : IQuery <TResult>
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query), "Запрос не передан");
            }

            var handler = _container.Resolve <IQueryHandler <TQuery, TResult> >();

            if (handler == null)
            {
                throw new NotImplementedException($"Не определен обработчик для запроса {query.GetType()}");
            }

            return(await handler.Execute(query, ctx, cancellationToken));
        }
示例#7
0
        public async Task ExecuteCommand <TCommand>(TCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) where TCommand : ICommand
        {
            if (cmd == null)
            {
                throw new ArgumentNullException(nameof(cmd), "Команда не передана");
            }

            var handler = _container.Resolve <ICommandHandler <TCommand> >();

            if (handler == null)
            {
                throw new NotImplementedException($"Не определен обработчик для команды {cmd.GetType()}");
            }

            await handler.Execute(cmd, ctx, cancellationToken);

            var afterHandlers = _container.ResolveAll <IAfterCommandHandler <TCommand> >();

            foreach (var afterCommandHandler in afterHandlers)
            {
                await afterCommandHandler.AfterExecute(cmd, ctx, cancellationToken);
            }
        }
 public CandidateRepository(CqrsContext context) : base(context)
 {
 }
示例#9
0
 public QueryRepository(CqrsContext context)
 {
     _context = context;
 }
示例#10
0
        public async Task Execute(UpdateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var entity = new Admission(cmd);

            await _admissionRepository.Update(entity);
        }
示例#11
0
 public UserRepository(CqrsContext context)
 {
     _context = context;
 }
示例#12
0
        public async Task <IEnumerable <AdmissionResponse> > Execute(GetAdmissionsQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var entities = await _admissionRepository.GetAllByVisitor(new ObjectId(cmd.VisitorId));

            var dtos = entities.Select(x => new AdmissionResponse(x));

            return(dtos);
        }
示例#13
0
 public async Task Execute(DeleteAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
 {
     await _admissionRepository.Delete(new ObjectId(cmd.VisitorId), new ObjectId(cmd.AdmissionId));
 }
示例#14
0
 public async Task Execute(CreateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
 {
     var admission = new Admission(cmd);
     await _admissionRepository.Create(admission);
 }
示例#15
0
        public async Task <AdmissionResponse> Execute(GetAdmissionQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var entity = await _admissionRepository.Get(new ObjectId(cmd.VisitorId), new ObjectId(cmd.AdmissionId));

            return(new AdmissionResponse(entity));
        }
 public BaseRepository(CqrsContext context)
 {
     _dbContext = context;
     _dbSet     = _dbContext.Set <TEntity>();
 }
示例#17
0
        public async Task <IEnumerable <VisitorResponse> > Execute(GetVisitorsQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var entities = await _visitorsRepository.GetAll();

            var dtos = entities.Select(x => new VisitorResponse(x));

            return(dtos);
        }
示例#18
0
 public CommandRepository(CqrsContext context)
 {
     _context = context;
 }
示例#19
0
 public async Task Execute(DeleteVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
 {
     await _visitorsRepository.Delete(new ObjectId(cmd.Id));
 }
示例#20
0
 public async Task Execute(UpdateVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
 {
     var visitor = new Visitor(cmd);
     await _visitorsRepository.Update(visitor);
 }
示例#21
0
 public async Task AfterExecute(CreateVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
 {
     var command = new CreateAdmissionCommand(cmd);
     await _cqrsDispatcher.ExecuteCommand(command, ctx, cancellationToken);
 }
示例#22
0
        public async Task <VisitorResponse> Execute(GetVisitorQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken())
        {
            var entity = await _visitorsRepository.GetById(new ObjectId(cmd.Id));

            return(new VisitorResponse(entity));
        }