/// <summary>
        /// Adds the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        public void Add(AddNewCustomerViewModel model)
        {
            var createCustomerCommand = _mapper.Map <CreateCustomerCommand>(model);

            // TODO Get password by MD5 enscript

            _commandDispatcher.Send(createCustomerCommand);
        }
Exemplo n.º 2
0
 public Task CreateAsync(ApplicationRole role)
 {
     _commandDispatcher.Send(new AddRoleCommand
     {
         Name        = role?.Details.Name,
         Description = role?.Details.Description,
         RoleType    = role.Details == null ? null : role.Details.RoleType,
     });
     return(Task.FromResult(0));
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(CategoryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await _commands.Send(new CreateCategoryCommand { Id = model.Id, Name = model.Name });

            return(RedirectToAction("Index", new { id = model.Id }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        public void Add(AddNewCustomerViewModel model)
        {
            const int saltLength            = 64;
            var       createCustomerCommand = _mapper.Map <CreateCustomerCommand>(model);
            var       passwordResult        = PasswordWithSaltHasher.ActionEncrypt(model.Password, saltLength);

            createCustomerCommand.SecurityStamp = passwordResult.Salt;
            createCustomerCommand.PasswordHash  = passwordResult.Digest;

            _commandDispatcher.Send(createCustomerCommand);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(PodcastCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var id = Guid.NewGuid();
            await _commands.Send(new CreatePodcastCommand { Id = id, Link = model.Link, CategoryId = model.CategoryId });

            return(RedirectToAction("ForPodcastCreation", "Wait", new { Id = id }));
        }
Exemplo n.º 6
0
        public ActionResult <RentalModelResult> PostRental([FromBody] CreateRentCommand createRentCommand)
        {
            Guid rentId = Guid.Empty;

            _commandDispatcher.Send(createRentCommand, out rentId);

            var modelToReturn = _mapper.Map <RentalModelResult>(createRentCommand);

            modelToReturn.RentalId = rentId;

            return(CreatedAtRoute("GetRent", new { rentId = rentId }, modelToReturn));
        }
Exemplo n.º 7
0
        public ActionResult Edit(TravellerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _commandDispatcher.Send(new ChangeTravellerName(model.Id, model.Firstname, model.Lastname));
            _commandDispatcher.Send(new ChangeTravellerCountry(model.Id, model.Country));

            this.FlashSuccess(string.Format("Traveller '{0} {1}' updated", model.Firstname, model.Lastname));

            return(RedirectToAction("Edit", new { id = model.Id }));
        }
Exemplo n.º 8
0
        public async Task Set([ActivityTrigger] SetSuccessfulLearnerMatchInput input)
        {
            _logger.LogInformation("Setting SuccessfulLearnerMatch for apprenticeship incentive id {apprenticeshipIncentiveId}, ULN {uln}, Succeeded: {succeeded}", input.ApprenticeshipIncentiveId, input.Uln, input.Succeeded);
            await _commandDispatcher.Send(new SetSuccessfulLearnerMatchCommand(input.ApprenticeshipIncentiveId, input.Uln, input.Succeeded));

            _logger.LogInformation("Set SuccessfulLearnerMatch for apprenticeship incentive id {apprenticeshipIncentiveId}, ULN {uln}, Succeeded: {succeeded}", input.ApprenticeshipIncentiveId, input.Uln, input.Succeeded);
        }
Exemplo n.º 9
0
        public async Task Update([ActivityTrigger] LearnerChangeOfCircumstanceInput input)
        {
            _logger.LogInformation("Calling Learner Change of Circumstance for apprenticeship incentive id {apprenticeshipIncentiveId}, uln {uln}", input.ApprenticeshipIncentiveId, input.Uln);
            await _commandDispatcher.Send(new LearnerChangeOfCircumstanceCommand(input.ApprenticeshipIncentiveId));

            _logger.LogInformation("Called Learner Change of Circumstance for apprenticeship incentive id {apprenticeshipIncentiveId}, uln {uln}", input.ApprenticeshipIncentiveId, input.Uln);
        }
Exemplo n.º 10
0
        public async Task Create([ActivityTrigger] LearnerMatchInput input)
        {
            _logger.LogInformation("Creating Learner Match record for apprenticeship incentive id {apprenticeshipIncentiveId}", input.ApprenticeshipIncentiveId);
            await _commandDispatcher.Send(new RefreshLearnerCommand(input.ApprenticeshipIncentiveId));

            _logger.LogInformation("Created Learner Match record for apprenticeship incentive id {apprenticeshipIncentiveId}", input.ApprenticeshipIncentiveId);
        }
Exemplo n.º 11
0
        public async Task Handle(AccountVrfCaseStatusRemindersCommand command, CancellationToken cancellationToken = default)
        {
            var accountsWithoutVrfStatus = await _accountDataRepository.GetByVrfCaseStatus(null);

            foreach (var account in accountsWithoutVrfStatus)
            {
                var applications = new List <ApprenticeApplicationDto>();

                foreach (var legalEntity in account.LegalEntities)
                {
                    var applicationsForLegalEntity = await _applicationDataRepository.GetList(account.AccountId, legalEntity.AccountLegalEntityId);

                    applications.AddRange(applicationsForLegalEntity);
                }

                var submittedApplications = applications.Where(x => x.ApplicationDate < command.ApplicationCutOffDate)
                                            .OrderBy(x => x.ApplicationDate);

                if (submittedApplications.Any())
                {
                    var application = submittedApplications.First();

                    var firstSubmittedApplicationId = await _applicationDataRepository.GetFirstSubmittedApplicationId(application.AccountLegalEntityId);

                    var sendRepeatReminderEmailCommand = new SendBankDetailsRepeatReminderEmailCommand(application.AccountId,
                                                                                                       application.AccountLegalEntityId,
                                                                                                       firstSubmittedApplicationId.Value,
                                                                                                       application.SubmittedByEmail);

                    await _commandDispatcher.Send(sendRepeatReminderEmailCommand);
                }
            }
        }
Exemplo n.º 12
0
        public async Task Create([ActivityTrigger] CalculateDaysInLearningInput input)
        {
            _logger.LogInformation("Calculating DaysinLearning for apprenticeship incentive id {apprenticeshipIncentiveId}, active period {activePeriod}", input.ApprenticeshipIncentiveId, input.ActivePeriod);
            await _commandDispatcher.Send(new CalculateDaysInLearningCommand(input.ApprenticeshipIncentiveId, input.ActivePeriod.Period, input.ActivePeriod.Year ));

            _logger.LogInformation("Calculated DaysinLearning for apprenticeship incentive id {apprenticeshipIncentiveId}, active period {activePeriod}", input.ApprenticeshipIncentiveId, input.ActivePeriod);
        }
        public async Task Create([ActivityTrigger] CreatePaymentInput input)
        {
            _logger.LogInformation("Creating Payment for apprenticeship incentive id {apprenticeshipIncentiveId}, pending payment id {pendingPaymentId}, collection period {collectionPeriod}", input.ApprenticeshipIncentiveId, input.PendingPaymentId, input.CollectionPeriod);
            await _commandDispatcher.Send(new CreatePaymentCommand(input.ApprenticeshipIncentiveId, input.PendingPaymentId, input.CollectionPeriod.Year, input.CollectionPeriod.Period));

            _logger.LogInformation("Created Payment for apprenticeship incentive id {apprenticeshipIncentiveId}, pending payment id {pendingPaymentId}, collection period {collectionPeriod}", input.ApprenticeshipIncentiveId, input.PendingPaymentId, input.CollectionPeriod);
        }
Exemplo n.º 14
0
        public IActionResult PostDriver([FromBody] CreateDriverCommand createDriverCommand)
        {
            if (createDriverCommand == null)
            {
                return(BadRequest());
            }
            Guid driverId = Guid.Empty;

            _commandDispatcher.Send(createDriverCommand, out driverId);

            var driverToReturn = _mapper.Map <DriverResult>(createDriverCommand);

            driverToReturn.DriverId = driverId;

            return(CreatedAtRoute("GetDriver", new { driverId = driverId }, driverToReturn));
        }
        public async Task Update([ActivityTrigger] object input)
        {
            _logger.LogInformation("Setting active collection period to in progress");
            await _commandDispatcher.Send(new SetActivePeriodToInProgressCommand());

            _logger.LogInformation("Active collection period set to in progress");
        }
Exemplo n.º 16
0
        public async Task Update([ActivityTrigger] CalculateEarningsInput input)
        {
            _logger.LogInformation("Calculating Earnings for apprenticeship incentive id {apprenticeshipIncentiveId}, uln {uln}", input.ApprenticeshipIncentiveId, input.Uln);
            await _commandDispatcher.Send(new CalculateEarningsCommand(input.ApprenticeshipIncentiveId));

            _logger.LogInformation("Calculated Earnings for apprenticeship incentive id {apprenticeshipIncentiveId}, uln {uln}", input.ApprenticeshipIncentiveId, input.Uln);
        }
Exemplo n.º 17
0
        public async Task Complete([ActivityTrigger] CompletePaymentProcessInput input)
        {
            _logger.LogInformation("Completing payment process");
            await _commandDispatcher.Send(new CompleteCommand(input.CompletionDateTime, new Domain.ValueObjects.CollectionPeriod(input.CollectionPeriod.Period, input.CollectionPeriod.Year)));

            _logger.LogInformation("Payment process completed for collection period {collectionPeriod}", input.CollectionPeriod);
        }
 private void CompleteIfPossible(ICommandDispatcher dispatcher)
 {
     if (status == Status.ReadyToComplete)
     {
         ApplyChanges(new OrderDelivered(this.id));
         dispatcher.Send(new CompleteOrder(this.id)); //todo this is wierd should do it after events have been persisted
     }
 }
Exemplo n.º 19
0
        public IActionResult Post([FromBody] CreateCarCommand createCarCommand)
        {
            if (createCarCommand == null)
            {
                return(BadRequest());
            }

            Guid carId = Guid.Empty;

            _commandDispatcher.Send(createCarCommand, out carId);

            var carToReturn = _mapper.Map <CarResult>(createCarCommand);

            carToReturn.CarId = carId;

            return(CreatedAtRoute("GetCar", new { carId }, carToReturn));
        }
Exemplo n.º 20
0
        public async Task <bool> Send([ActivityTrigger] AccountLegalEntityCollectionPeriod accountLegalEntityCollectionPeriod)
        {
            var collectionPeriod     = accountLegalEntityCollectionPeriod.CollectionPeriod;
            var accountLegalEntityId = accountLegalEntityCollectionPeriod.AccountLegalEntityId;

            _logger.LogInformation("[SendPaymentRequestsForAccountLegalEntity] Publish SendPaymentRequestsCommand for account legal entity {accountLegalEntityId}, collection period {collectionPeriod}", accountLegalEntityId, collectionPeriod);
            await _commandDispatcher.Send(new SendPaymentRequestsCommand(accountLegalEntityId, DateTime.UtcNow));

            _logger.LogInformation("[SendPaymentRequestsForAccountLegalEntity] Published SendPaymentRequestsCommand for account legal entity {accountLegalEntityId}, collection period {collectionPeriod}", accountLegalEntityId, collectionPeriod);
            return(true);
        }
 public void ConsumeCommand(string sender, Parcel parcel)
 {
     if (_messageInboxItemRepository.AllowReceive(parcel.MessageId, sender))
     {
         var     mapToClass  = _messageTypeMap[parcel.Route];
         var     commandType = Type.GetType(mapToClass);
         dynamic command     = _jsonSerializer.Deserialize(parcel.MessageBody, commandType);
         _commandDispatcher.Send(command);
         _messageInboxItemRepository.Receive(parcel.MessageId, sender);
     }
 }
Exemplo n.º 22
0
 public async Task Validate([ActivityTrigger] ValidatePendingPaymentData payment)
 {
     _logger.LogInformation("Validating Pending Payment [PendingPaymentId={pendingPaymentId}], [collection period={year}/{period}], [ApprenticeshipIncentiveId={apprenticeshipIncentiveId}]",
                            payment.PendingPaymentId, payment.Year, payment.Period, payment.ApprenticeshipIncentiveId);
     try
     {
         await _commandDispatcher.Send(new ValidatePendingPaymentCommand(payment.ApprenticeshipIncentiveId,
                                                                         payment.PendingPaymentId, payment.Year, payment.Period));
     }
     catch (Exception ex)
     {
         throw new ValidatePendingPaymentException(payment.ApprenticeshipIncentiveId, payment.PendingPaymentId, ex);
     }
 }
        public async Task Send <TCommand>(TCommand command, CancellationToken cancellationToken = default) where TCommand : ICommand
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }

                    await _commandDispatcher.Send(command);

                    if (_hook?.OnProcessed != null)
                    {
                        _hook.OnProcessed(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _commandDispatcher.Send(command);
            }
        }
Exemplo n.º 24
0
        public async Task <Result <T> > Send <T>(ICommand <T> command, CancellationToken cancellationToken = default)
        {
            _logger.Sending(command.GetType(), command.CorrelationId);

            var result = await _bus.Send(command, cancellationToken);

            if (result is Ok <T> )
            {
                _logger.Success(command.CorrelationId);
            }
            else if (result is Error <T> error)
            {
                _logger.Error(command.CorrelationId, error.Message);
            }

            return(result);
        }
        public async Task Send <T>(T command, CancellationToken cancellationToken = default) where T : ICommand
        {
            var log       = _logfactory.CreateLogger <T>();
            var domainLog = (command is ILogWriter) ? (command as ILogWriter).Log : new Log();

            try
            {
                if (domainLog.OnProcessing == null)
                {
                    log.LogInformation($"Start dispatch  '{typeof(T)}' command");
                }
                else
                {
                    log.LogInformation($"Start dispatch '{typeof(T)}' command : {domainLog.OnProcessing.Invoke()}");
                }

                await _dispatcher.Send(command, cancellationToken);

                if (domainLog.OnProcessed == null)
                {
                    log.LogInformation($"End dispatch '{typeof(T)}' command");
                }
                else
                {
                    log.LogInformation($"End dispatch '{typeof(T)}' command : {domainLog.OnProcessed.Invoke()}");
                }
            }
            catch (Exception ex)
            {
                if (domainLog.OnError == null)
                {
                    log.LogError(ex, $"Error dispatching '{typeof(T)}' command");
                }
                else
                {
                    log.LogError(ex, $"Error dispatching '{typeof(T)}' command : {domainLog.OnError.Invoke()}");
                }

                throw;
            }
        }
Exemplo n.º 26
0
        public async Task Execute(CreatePodcastCommand command)
        {
            using (var work = _factory.Begin())
            {
                if (work.Podcasts.Exists(command.Id))
                {
                    return;
                }

                var Podcast = new Podcast {
                    Id         = command.Id,
                    Link       = command.Link,
                    CategoryId = command.CategoryId
                };

                work.Podcasts.Save(Podcast);
                work.Commit();
            }

            await _command.Send(new RetrievePodcastCommand { Id = command.Id, Link = command.Link });
        }
        public async Task <IActionResult> PausePayments([FromBody] PausePaymentsRequest request)
        {
            try
            {
                await _commandDispatcher.Send(new PausePaymentsCommand(request.ULN, request.AccountLegalEntityId, request.ServiceRequest?.TaskId, request.ServiceRequest?.DecisionReference, request.ServiceRequest?.TaskCreatedDate, request.Action));

                return(new OkObjectResult(new { Message = $"Payments have been successfully {request.Action}d" }));
            }
            catch (InvalidRequestException e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
            catch (KeyNotFoundException e)
            {
                return(new NotFoundObjectResult(new { e.Message }));
            }
            catch (PausePaymentsException e)
            {
                return(new BadRequestObjectResult(new { e.Message }));
            }
        }
Exemplo n.º 28
0
 public async Task <Result <T> > Send <T>(ICommand <T> command, CancellationToken cancellationToken = default)
 {
     try
     {
         _logger.Debug("Exception to result: Send");
         return(await _bus.Send(command, cancellationToken));
     }
     catch (DomainException dex)
     {
         _logger.Information(dex, "Domain error processing command {Id}", command.CorrelationId);
         return(command.Error(dex.Message));
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "Error processing command {Id}", command.CorrelationId);
         return(command.Error($"An error occurred processing command {command.CorrelationId}"));
     }
     finally
     {
         _logger.Debug("Exception to result: End");
     }
 }
 protected Task SendCommandAsync <TCommand>(TCommand command) where TCommand : ICommand
 {
     return(_commandDispatcher.Send(command));
 }
Exemplo n.º 30
0
        public async Task <Result <T> > Send <T>(ICommand <T> command, CancellationToken cancellationToken = default)
        {
            var result = await _bus.Send(command, cancellationToken);

            return(result);
        }