示例#1
0
        public virtual PartialViewResult AddLike()
        {
            var likeTarget     = FullContext.Value;
            var targetEntityId = likeTarget.EntityId.Value;

            var command = new AddLikeCommand(FullContext, _intranetMemberService.GetCurrentMemberId());

            _commandPublisher.Publish(command);

            switch (likeTarget.Type.ToInt())
            {
            case (int)Comment:
                return(Likes(_likesService.GetLikeModels(targetEntityId), targetEntityId));

            case (int)ContentPage:
                return(Likes(_likesService.GetLikeModels(targetEntityId), targetEntityId, showTitle: true));

            case int type when HasFlagScalar(type, Activity | PagePromotion):
                var activityLikeInfo = GetActivityLikes(targetEntityId);

                return(Likes(activityLikeInfo.Likes, activityLikeInfo.Id, activityLikeInfo.IsReadOnly, showTitle: HasFlagScalar(type, PagePromotion)));

            default:
                throw new IndexOutOfRangeException();
            }
        }
        public async Task Publish <T>(T command, CancellationToken cancellationToken = default) where T : class, ICommand
        {
            if (_hook != null)
            {
                try
                {
                    if (_hook?.OnReceived != null)
                    {
                        _hook.OnReceived(command);
                    }
                    await _commandPublisher.Publish(command);

                    if (_hook?.OnPublished != null)
                    {
                        _hook.OnPublished(command);
                    }
                }
                catch (Exception ex)
                {
                    bool suppressError = false;
                    if (_hook?.OnErrored != null)
                    {
                        suppressError = _hook.OnErrored(ex, command);
                    }
                    if (!suppressError)
                    {
                        throw;
                    }
                }
            }
            else
            {
                await _commandPublisher.Publish(command);
            }
        }
        public override void UpdateMemberCache(Guid memberId)
        {
            base.UpdateMemberCache(memberId);
            var member = Get(memberId);

            _commandPublisher.Publish(new MemberChanged(member));
        }
        public virtual PartialViewResult Add(CommentCreateModel model)
        {
            var commentsTarget = FullContext.GetCommentsTarget();
            var targetEntityId = commentsTarget.EntityId.Value;

            if (!ModelState.IsValid)
            {
                return(OverView(targetEntityId));
            }

            var createDto = MapToCreateDto(model, targetEntityId);
            var command   = new AddCommentCommand(FullContext, createDto);

            _commandPublisher.Publish(command);

            OnCommentCreated(createDto.Id);

            switch (commentsTarget.Type.ToInt())
            {
            case int type
                when ContextExtensions.HasFlagScalar(type, ContextType.Activity | ContextType.PagePromotion):
                var activityCommentsInfo = GetActivityComments(targetEntityId);

                return(OverView(activityCommentsInfo));

            default:
                return(OverView(targetEntityId));
            }
        }
示例#5
0
        public async Task <IHttpActionResult> AddLike([FromUri] Guid entityId, [FromUri] IntranetEntityTypeEnum entityType)
        {
            if (!await CanAddRemoveLikeAsync(entityId, entityType))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var command = new AddLikeCommand(entityId, entityType, await _intranetMemberService.GetCurrentMemberIdAsync());

            _commandPublisher.Publish(command);

            switch (entityType)
            {
            case IntranetEntityTypeEnum.Comment:
                return(Ok(await _likesService.GetLikeModelsAsync(entityId)));

            case IntranetEntityTypeEnum.ContentPage:
                return(Ok(await _likesService.GetLikeModelsAsync(entityId)));

            case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events):
                var activityLikeInfo = GetActivityLikes(entityId);

                return(Ok(activityLikeInfo.Likes));

            default:
                throw new IndexOutOfRangeException();
            }
        }
示例#6
0
 public virtual void Hide(Guid groupId, bool hide)
 {
     if (hide)
     {
         var command = new HideGroupCommand(groupId);
         _commandPublisher.Publish(command);
     }
     else
     {
         var command = new UnhideGroupCommand(groupId);
         _commandPublisher.Publish(command);
     }
 }
示例#7
0
        public Guid UpdateBook(Guid id, [FromBody] DTOs.BookDTO dto)
        {
            var command = new UpdateBookCommand
            {
                BookId      = dto.BookId,
                BookName    = dto.BookName,
                ISBN        = dto.ISBN,
                DateIssued  = dto.IssueDate,
                Description = dto.Description
            };

            _commandPublisher.Publish(command);
            return(command.CommandUniqueId);
        }
        public Guid Rent(int customerId, [FromBody] RentBookDTO dto)
        {
            var command = new RentBookCommand
            {
                BookId     = dto.BookId,
                BookName   = dto.BookName,
                ISBN       = dto.ISBN,
                Name       = dto.Name,
                CustomerId = dto.CustomerId
            };

            _commandPublisher.Publish(command);

            return(command.CommandUniqueId);
        }
        public async Task <int> FinishBestelling(BestellingAfrondenCommand command)
        {
            var bestelling = await _datamapper.GetBestelling(command.Id);

            foreach (var bestellingItem in bestelling.BesteldeArtikelen)
            {
                try
                {
                    _logger.LogInformation("Lowering voorraad by {0} of artikel {1}", bestellingItem.Aantal,
                                           bestellingItem.Artikelnummer);
                    var result = await _commandPublisher.Publish <bool>(
                        new HaalVoorraadUitMagazijnCommand(bestellingItem.Artikelnummer, bestellingItem.Aantal),
                        "Kantilever.MagazijnService", "Kantilever.MagazijnService.HaalVoorraadUitMagazijnCommand");
                }
                catch (FunctionalException e)
                {
                    //Do nothing yet because not implemented.
                    _logger.LogWarning(
                        "Tried finishing a bestelling with not enough voorraad, this should not happen. {0}",
                        e.Message);
                }
            }

            _eventPublisher.Publish(new BestellingVerzondenEvent {
                Id = bestelling.Id
            });

            _logger.LogInformation("Finished bestelling {0}", bestelling.Id);
            return(command.Id);
        }
示例#10
0
        public async Task <IActionResult> BetalingVerwerken([FromBody] BetalingCM betaling)
        {
            var betalingVerwerkenCommand = new VerwerkBetalingCommand(betaling, NameConstants.BetaalServiceBetalingVerwerkenCommandQueue);

            try
            {
                await _commandPublisher.Publish <long>(betalingVerwerkenCommand);
            }
            catch (InvalidFactuurnummerException)
            {
                _logger.LogError("InvalidFactuurnummerException occured, the factuurnummer is: {}", betaling.Factuurnummer);
                return(BadRequest($"Factuurnummer {betaling.Factuurnummer} kon niet worden gevonden"));
            }
            catch (TimeoutException)
            {
                _logger.LogError("BetalingVerwerkenCommand resulted in a TimeoutException.");
                return(StatusCode((int)HttpStatusCode.RequestTimeout, "Aanvraag kon niet worden verwerkt"));
            }
            catch (Exception ex)
            {
                _logger.LogError("BetalingVerwerkenCommand resulted in an internal server error.");
                _logger.LogDebug(
                    "Exception occured during execution of UpdateBestelStatusCommand {}, it threw exception: {}. Inner exception: {}",
                    betaling, ex.Message, ex.InnerException?.Message
                    );
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            return(StatusCode((int)HttpStatusCode.OK));
        }
示例#11
0
 public Task Handle(ComplianceWithdrawn @event, CancellationToken cancellationToken = default)
 {
     return(_commandPublisher.Publish(
                new WithdrawCommand(
                    @event.AccountId,
                    @event.Model.Id)));
 }
示例#12
0
        public Task Handle(EarningsCalculationRequired @event, CancellationToken cancellationToken = default)
        {
            var commands = new List <Task>();

            foreach (var apprenticeship in @event.Model.ApprenticeshipModels)
            {
                var command = new CreateIncentiveCommand(
                    @event.Model.AccountId,
                    @event.Model.AccountLegalEntityId,
                    apprenticeship.Id,
                    apprenticeship.ApprenticeshipId,
                    apprenticeship.FirstName,
                    apprenticeship.LastName,
                    apprenticeship.DateOfBirth,
                    apprenticeship.ULN,
                    apprenticeship.PlannedStartDate,
                    apprenticeship.ApprenticeshipEmployerTypeOnApproval,
                    apprenticeship.UKPRN,
                    @event.Model.DateSubmitted.Value,
                    @event.Model.SubmittedByEmail,
                    apprenticeship.CourseName
                    );

                var task = _commandPublisher.Publish(command);
                commands.Add(task);
            }

            return(Task.WhenAll(commands));
        }
示例#13
0
        public async Task <IEnumerable <TicketFile> > UploadFiles(Guid userId, params IFormFile[] formFiles)
        {
            var files = GenerateFileUploadCommands(userId, formFiles).ToList();
            await _publisher.Publish <UploadFileCommand>(files, CommandBusConstants.ErazerDocumentStore);

            return(files.Select(f => new TicketFile(f.Id, f.Name, f.Type, f.Data.Length, f.Created, f.UserId)));
        }
        public virtual ActionResult Hide(Guid id)
        {
            var command = new HideGroupCommand(id);

            _commandPublisher.Publish(command);

            return(Json(_groupLinkProvider.GetGroupsOverviewLink()));
        }
        public async Task <IActionResult> Login(Credentials credentials)
        {
            JwtResult jwtResult;

            try
            {
                jwtResult = await _commandPublisher.Publish <JwtResult>(
                    new LogGebruikerInCommand { Credentials = credentials },
                    NameConstants.LogGebuikerInCommandQueue);
            }
            catch (LoginFailedException)
            {
                return(Unauthorized());
            }

            return(Ok(jwtResult));
        }
        public Task Handle(BankDetailsApprovedForLegalEntity @event, CancellationToken cancellationToken = default)
        {
            var command = new AddEmployerVendorIdCommand()
            {
                HashedLegalEntityId = @event.HashedLegalEntityId
            };

            return(_commandPublisher.Publish(command));
        }
        public Task Handle(EarningsCalculated @event, CancellationToken cancellationToken = default)
        {
            var command = new CompleteEarningsCalculationCommand(
                @event.AccountId,
                @event.ApplicationApprenticeshipId,
                @event.ApprenticeshipId,
                @event.ApprenticeshipIncentiveId);

            return(_commandPublisher.Publish(command));
        }
示例#18
0
        public async Task <IHttpActionResult> Add([FromBody] CommentCreateModel model)
        {
            if (model.EntityType.Is(IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Events))
            {
                var member = await _intranetMemberService.GetCurrentMemberAsync();

                var activityGroupId = _groupActivityService.GetGroupId(model.EntityId);

                if (activityGroupId.HasValue)
                {
                    var group = _groupService.Get(activityGroupId.Value);
                    if (group == null || group.IsHidden)
                    {
                        return(StatusCode(HttpStatusCode.Forbidden));
                    }
                }

                if (activityGroupId.HasValue && !member.GroupIds.Contains(activityGroupId.Value))
                {
                    return(StatusCode(HttpStatusCode.Forbidden));
                }
            }

            var createDto = await MapToCreateDtoAsync(model, model.EntityId);

            var command = new AddCommentCommand(model.EntityId, model.EntityType, createDto);

            _commandPublisher.Publish(command);

            await OnCommentCreatedAsync(createDto.Id, model.EntityType);

            switch (model.EntityType)
            {
            case IntranetEntityTypeEnum type
                when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events):
                var activityCommentsInfo = GetActivityComments(model.EntityId);

                return(Ok(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)));

            default:
                return(Ok(await _commentsHelper.OverViewAsync(model.EntityId)));
            }
        }
        public async Task Handle(SendBankDetailsReminderEmailCommand command, CancellationToken cancellationToken = default)
        {
            var template = _emailTemplates.BankDetailsReminder;

            var personalisationTokens = new Dictionary <string, string>
            {
                { AddBankDetailsUrlToken, command.AddBankDetailsUrl }
            };

            var sendEmailCommand = new SendEmailCommand(template.TemplateId, command.EmailAddress, personalisationTokens);

            await _commandPublisher.Publish(sendEmailCommand);
        }
示例#20
0
        public virtual ActionResult Hide(Guid id)
        {
            var canHide = _groupService.CanHide(id);

            if (canHide)
            {
                var command = new HideGroupCommand(id);
                _commandPublisher.Publish(command);
            }

            return(Json(canHide ? _groupLinkProvider.GetGroupsOverviewLink() :
                        _groupLinkProvider.GetGroupLink(id)));
        }
示例#21
0
        public void Convert(MediaConvertModel model)
        {
            VideoConvertedCommand command = null;

            try
            {
                var tempFilePath = Path.GetTempFileName();
                File.WriteAllBytes(tempFilePath, model.File.FileBytes);

                var inputFile = new MediaFile {
                    Filename = tempFilePath
                };
                var outputFile = new MediaFile {
                    Filename = Path.ChangeExtension(tempFilePath, Mp4ExtensionName)
                };

                using (var engine = new Engine(HostingEnvironment.MapPath(IntranetConstants.FfmpegRelativePath)))
                {
                    engine.GetMetadata(inputFile);
                    var options = new Uintra.Core.MediaToolkit.Options.ConversionOptions();
                    engine.Convert(inputFile, outputFile, options);
                }

                File.Delete(inputFile.Filename);

                command = new VideoConvertedCommand
                {
                    Success           = true,
                    ConvertedFilePath = outputFile.Filename,
                    MediaId           = model.MediaId
                };
            }
            catch (Exception ex)
            {
                command = new VideoConvertedCommand
                {
                    MediaId = model.MediaId,
                    Success = false,
                    Message = new VideoConvertedCommandMessageModel
                    {
                        ExceptionMessage = ex.Message,
                        StackTrace       = ex.StackTrace,
                        FileName         = model.File.FileName
                    }
                };
            }
            finally
            {
                _commandPublisher.Publish(command);
            }
        }
示例#22
0
        public void Convert(MediaConvertModel model)
        {
            VideoConvertedCommand command = null;

            try
            {
                var tempFilePath = Path.GetTempFileName();
                File.WriteAllBytes(tempFilePath, model.File.FileBytes);

                var inputFile = new MediaFile {
                    Filename = tempFilePath
                };
                var outputFile = new MediaFile {
                    Filename = Path.ChangeExtension(tempFilePath, Mp4ExtensionName)
                };

                using (_engine)
                {
                    _engine.GetMetadata(inputFile);
                    var options = new ConversionOptions();
                    _engine.Convert(inputFile, outputFile, options);
                }

                File.Delete(inputFile.Filename);

                command = new VideoConvertedCommand
                {
                    Success           = true,
                    ConvertedFilePath = outputFile.Filename,
                    MediaId           = model.MediaId
                };
            }
            catch (Exception ex)
            {
                command = new VideoConvertedCommand()
                {
                    MediaId = model.MediaId,
                    Success = false,
                    Message = new VideoConvertedCommandMessageModel()
                    {
                        ExceptionMessage = ex.Message,
                        StackTrace       = ex.StackTrace,
                        FileName         = model.File.FileName
                    }
                };
            }
            finally
            {
                _commandPublisher.Publish(command);
            }
        }
        public async Task <IActionResult> CreateBestelling([FromBody] Bestelling incomingBestelling)
        {
            var klantEmail = _jwtHelper.GetEmail(HttpContext);
            var klant      = _klantDataMapper.GetByEmail(klantEmail);

            var bestelling = Mapper.Map <BestellingCM>(incomingBestelling);

            bestelling.Klantnummer = klant.Id;

            try
            {
                var bestellingCommand = new PlaatsBestellingCommand(bestelling, NameConstants.BestelServicePlaatsBestellingCommandQueue);
                var result            = await _commandPublisher.Publish <long>(bestellingCommand);

                return(Created($"/api/bestelling/{result}", result));
            }
            catch (DatabaseException)
            {
                _logger.LogError("PlaatsBestellingCommand resulted in a DatabaseException.");
                return(BadRequest("Bestelling bevat incorrecte data"));
            }
            catch (TimeoutException)
            {
                _logger.LogError("PlaatsBestellingCommand resulted in a TimeoutException.");
                return(StatusCode((int)HttpStatusCode.RequestTimeout, "Aanvraag kon niet worden verwerkt"));
            }
            catch (Exception ex)
            {
                _logger.LogError("PlaatsBestellingCommand resulted in an internal server error.");
                _logger.LogDebug(
                    "Exception occured during execution of PlaatsBestellingCommand {}, it threw exception: {}. Inner exception: {}",
                    bestelling, ex.Message, ex.InnerException?.Message
                    );

                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
示例#24
0
        public ActionResult DtoAdd(string name)
        {
            var id = Guid.NewGuid();

            _commandSender.Publish(new DtoCommand <ISingleSignOnToken, UserDto>(id, null, new UserDto {
                Id = id, Name = name
            }));
            return(RedirectToAction("DtoIndex"));
        }
        public async Task <int> NieuweBestelling(Bestelling bestelling)
        {
            var besteldeArtikelen = new List <BestellingItemDB>();

            foreach (var bestellingItem in bestelling.BesteldeArtikelen)
            {
                besteldeArtikelen.Add(new BestellingItemDB(bestellingItem.Artikelnummer, bestellingItem.Aantal));
            }

            var command = new NieuweBestellingCommand
            {
                KlantId           = bestelling.KlantId,
                AdresRegel1       = bestelling.AdresRegel1,
                AdresRegel2       = bestelling.AdresRegel2,
                BesteldeArtikelen = besteldeArtikelen,
                Plaats            = bestelling.Plaats,
                Postcode          = bestelling.Postcode
            };

            var result = await _commandPublisher.Publish <int>(command, NameConstants.NieuweBestellingCommandQueue);

            _logger.LogInformation("New bestelling with id {id} added", result);
            return(result);
        }
示例#26
0
        public async Task Handle(UpdateVendorRegistrationCaseStatusCommand command, CancellationToken cancellationToken = default)
        {
            var accounts = await _domainRepository.GetByHashedLegalEntityId(command.HashedLegalEntityId);

            var tasks = accounts.Select(account =>
                                        _commandPublisher.Publish(
                                            new UpdateVendorRegistrationCaseStatusForAccountCommand(
                                                account.Id,
                                                command.HashedLegalEntityId,
                                                command.CaseId,
                                                command.Status,
                                                command.CaseStatusLastUpdatedDate),
                                            cancellationToken));

            await Task.WhenAll(tasks);
        }
        public async Task <IActionResult> BetaalBestelling(Betaling betaling)
        {
            var command = new BetaalBestellingCommand
            {
                Bedrag       = betaling.Bedrag,
                BestellingId = betaling.Factuurnummer
            };
            var bestellingId =
                await _commandPublisher.Publish <int>(command, NameConstants.BetaalBestellingCommandQueue);

            if (bestellingId == 0)
            {
                return(BadRequest());
            }

            return(Ok());
        }
示例#28
0
        public async Task Handle(AccountLegalEntityRemoved @event, CancellationToken cancellationToken = default)
        {
            var applications = await _incentiveApplicationDataRepository.FindApplicationsByAccountLegalEntity(@event.AccountLegalEntityId);

            var withdrawTasks = new List <Task>();

            foreach (var application in applications)
            {
                foreach (var apprenticeship in application.ApprenticeshipModels)
                {
                    var withdrawCommand = new WithdrawCommand(application.AccountId, apprenticeship.Id);

                    withdrawTasks.Add(_commandPublisher.Publish(withdrawCommand));
                }
            }

            await Task.WhenAll(withdrawTasks);
        }
示例#29
0
        public virtual async Task <IHttpActionResult> Hide(Guid id)
        {
            var group = await _groupService.GetAsync(id);

            if (group == null || group.IsHidden)
            {
                return(NotFound());
            }

            var canHide = await _groupService.CanHideAsync(id);

            if (!canHide)
            {
                return(Ok(_groupLinkProvider.GetGroupRoomLink(id)));
            }

            var command = new HideGroupCommand(id);

            _commandPublisher.Publish(command);

            return(Ok(_groupLinkProvider.GetGroupsOverviewLink()));
        }
示例#30
0
        public async Task Handle(SendBankDetailsRepeatReminderEmailCommand command, CancellationToken cancellationToken = default)
        {
            var template = _emailTemplates.BankDetailsRepeatReminder;
            var account  = await _accountDomainRepository.Find(command.AccountId);

            var legalEntity = account?.GetLegalEntity(command.AccountLegalEntityId);

            if (legalEntity == null)
            {
                throw new ArgumentException($"Account legal entity not found - account id {command.AccountId} account legal entity id {command.AccountLegalEntityId}");
            }

            var personalisationTokens = new Dictionary <string, string>
            {
                { AddBankDetailsUrlToken, GenerateBankDetailsUrl(command) },
                { OrganisationNameToken, legalEntity.Name }
            };

            var sendEmailCommand = new SendEmailCommand(template.TemplateId, command.EmailAddress, personalisationTokens);

            await _commandPublisher.Publish(sendEmailCommand);
        }