コード例 #1
0
        public async Task <OperationResult <WebsiteOutputModel> > Handle(CreateWebsite request, CancellationToken cancellationToken)
        {
            var passwordAsPlainText = request.Password;

            Website website = request.ToWebsite(_cypher.Encrypt(request.Password));

            _repository.Add(website);

            try
            {
                await _unitOfWork.CommitAsync(cancellationToken);
            }
            catch (UrlExistsException)
            {
                return(OperationResult <WebsiteOutputModel> .Failure(new Dictionary <string, string> {
                    { "Url", "Url already exists." }
                }));
            }

            return(OperationResult <WebsiteOutputModel> .Success(website.ToWebsiteOutputModel(passwordAsPlainText)));
        }