コード例 #1
0
ファイル: AddOfferCommand.cs プロジェクト: TomeQ2k/_MyVinted
        public async Task <AddOfferResponse> Handle(AddOfferRequest request, CancellationToken cancellationToken)
        {
            var createdOffer = await offerService.AddOffer(request);

            if (createdOffer != null)
            {
                var followersIds = FollowersUtils.GetFollowersIds(createdOffer.Owner);

                foreach (var followerId in followersIds)
                {
                    var notification = await notifier.Push(NotificationMessages.NewOfferByFollowedUserAddedMessage(createdOffer.Owner.UserName), followerId);

                    await hubManager.Invoke(SignalrActions.NOTIFICATION_RECEIVED, followerId, mapper.Map <NotificationDto>(notification));
                }

                return(new AddOfferResponse {
                    Offer = mapper.Map <OfferDto>(createdOffer)
                });
            }

            throw new CrudException("Adding offer failed");
        }
コード例 #2
0
        public async Task <DenyOfferAuctionResponse> Handle(DenyOfferAuctionRequest request, CancellationToken cancellationToken)
        {
            var offer = await offerService.GetOffer(request.OfferId) ?? throw new EntityNotFoundException("Offer not found");

            var denied = await auctionManager.DenyAuction(request.AuctionId, request.OfferId);

            if (denied)
            {
                var followersIds = FollowersUtils.GetFollowersIds(offer.Owner);

                foreach (var followerId in followersIds)
                {
                    var notification = await notifier.Push(NotificationMessages.OfferAuctionDenied(request.OfferId), followerId);

                    await hubManager.Invoke(SignalrActions.NOTIFICATION_RECEIVED, followerId, mapper.Map <NotificationDto>(notification));
                }

                return(new DenyOfferAuctionResponse());
            }

            throw new CrudException("Deny offer auction failed");
        }