public async Task <bool> Handle(CanSellQuery request, CancellationToken cancellationToken) { var userId = _httpContextAccessor.HttpContext.User.Claims.ToTokenPayload().UserClaims.Id; var sellerInfo = await _sellerInfoRepository.GetByUserIdAsync(userId); return(sellerInfo != null); }
public async Task <PublicSellerInfoDto> Handle(GetPublicSellerInfoQuery request, CancellationToken cancellationToken) { var sellerId = Guid.Parse(request.SellerId); var sellerInfo = await _sellerInfoRepository.GetByUserIdAsync(sellerId); if (sellerInfo == null) { return(null); } return(new PublicSellerInfoDto { ContactEmail = sellerInfo.ContactEmail, PhoneNumber = sellerInfo.PhoneNumber, AdditionalInfo = sellerInfo.AdditionalInfo }); }
public async Task <Unit> Handle(CreateOrUpdateSellerInfoCommand request, CancellationToken cancellationToken) { var userId = _httpContext.User.Claims.ToTokenPayload().UserClaims.Id; var sellerInfo = await _sellerInfoRepository.GetByUserIdAsync(userId); var sellerInfoExists = sellerInfo != null; if (!sellerInfoExists) { sellerInfo = new SellerInfo(userId, request.ContactEmail, request.PhoneNumber, request.BankAccountNumber); if (request.AdditionalInfo != null) { sellerInfo.SetAdditionalInfo(request.AdditionalInfo); } _sellerInfoRepository.Add(sellerInfo); } else { if (request.ContactEmail != null) { sellerInfo.SetContactEmail(request.ContactEmail); } if (request.PhoneNumber != null) { sellerInfo.SetPhoneNumber(request.PhoneNumber); } if (request.BankAccountNumber != null) { sellerInfo.SetBankAccountNumber(request.BankAccountNumber); } if (request.AdditionalInfo != null) { sellerInfo.SetAdditionalInfo(request.AdditionalInfo); } } if (sellerInfoExists) { _sellerInfoRepository.Update(sellerInfo); } await _sellerInfoRepository.UnitOfWork.SaveChangesAndDispatchDomainEventsAsync(cancellationToken); return(await Unit.Task); }