Beispiel #1
0
        public async Task <OperationResult <bool> > Handle(UpdateWebsite request, CancellationToken cancellationToken)
        {
            Website website = await _repository.GetByIdAsync(request.WebsiteId);

            if (website is null)
            {
                return(OperationResult <bool> .Failure(new Dictionary <string, string> {
                    { "WebsiteId", ErrorMessages.WebsiteNotFound }
                }));
            }

            website.Update(request.ToWebsite(_cypher.Encrypt(request.Password)));

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

            return(OperationResult <bool> .Success(true));
        }
Beispiel #2
0
        public async Task <EntityActionOutcome> UpdateEntityAsync(WebsiteInputData viewData, Guid id)
        {
            var getCurrent = await _repository.GetByIdAsync <Website>(id);

            var validator = new WebsiteInputDataValidator();
            var result    = validator.Validate(viewData);

            if (result.IsValid == false)
            {
                return(EntityActionOutcome.UpdateFailed);
            }

            var updateSuccessful = _repository.Update(await PopulateEntityDataWithViewData(viewData, id));

            if (updateSuccessful == null)
            {
                return(EntityActionOutcome.EntityNotFound);
            }

            return(EntityActionOutcome.Success);
        }
Beispiel #3
0
        public async Task <OperationResult <WebsiteOutputModel> > Handle(GetWebsite request, CancellationToken cancellationToken)
        {
            Website website = await _repository.GetByIdAsync(request.WebsiteId);

            if (website is null)
            {
                return(OperationResult <WebsiteOutputModel> .Failure(new Dictionary <string, string> {
                    { "WebsiteId", ErrorMessages.WebsiteNotFound }
                }));
            }

            return(OperationResult <WebsiteOutputModel> .Success(website.ToWebsiteOutputModel(_cypher.Decrypt(website.Password))));
        }
Beispiel #4
0
        public async Task <OperationResult <ImageContentOutputModel> > Handle(GetImage query, CancellationToken cancellationToken)
        {
            query = query ?? throw new ArgumentNullException(nameof(query));

            Website website = await _repository.GetByIdAsync(query.WebsiteId);

            if (website is null)
            {
                return(OperationResult <ImageContentOutputModel> .Failure(new Dictionary <string, string> {
                    { "WebsiteId", ErrorMessages.WebsiteNotFound }
                }));
            }

            return(OperationResult <ImageContentOutputModel> .Success(new ImageContentOutputModel(website.Image.Name, website.Image.MimeType, website.Image.Blob)));
        }
Beispiel #5
0
        public async Task <OperationResult <bool> > Handle(DeleteWebsite request, CancellationToken cancellationToken)
        {
            Website website = await _repository.GetByIdAsync(request.WebsiteId);

            if (website is null)
            {
                return(OperationResult <bool> .Failure(new Dictionary <string, string> {
                    { "WebsiteId", ErrorMessages.WebsiteNotFound }
                }));
            }

            website.IsDeleted = true;
            await _unitOfWork.CommitAsync(cancellationToken);

            return(OperationResult <bool> .Success(true));
        }