public async Task <OneOf <NotFound, Success> > Execute( DocumentClient client, Configuration configuration, UpdateProviderInfo request) { var documentUri = UriFactory.CreateDocumentUri( configuration.DatabaseId, configuration.ProviderCollectionName, request.ProviderId.ToString()); Provider provider; try { var response = await client.ReadDocumentAsync <Provider>(documentUri); provider = response.Document; } catch (DocumentClientException dex) when(dex.StatusCode == HttpStatusCode.NotFound) { return(new NotFound()); } provider.MarketingInformation = request.MarketingInformation; provider.DateUpdated = request.UpdatedOn; provider.UpdatedBy = request.UpdatedBy.Email; await client.ReplaceDocumentAsync(documentUri, provider); return(new Success()); }
public async Task <OneOf <ModelWithErrors <Command>, Success> > Handle( Command request, CancellationToken cancellationToken) { var validator = new CommandValidator(); var validationResult = await validator.ValidateAsync(request); if (!validationResult.IsValid) { return(new ModelWithErrors <Command>(request, validationResult)); } var currentUser = _currentUserProvider.GetCurrentUser(); var updateCommand = new UpdateProviderInfo() { ProviderId = request.ProviderId, MarketingInformation = request.MarketingInformation, UpdatedBy = currentUser, UpdatedOn = _clock.UtcNow }; await _cosmosDbQueryDispatcher.ExecuteQuery(updateCommand); return(new Success()); }
public OneOf <NotFound, Success> Execute( InMemoryDocumentStore inMemoryDocumentStore, UpdateProviderInfo request) { var provider = inMemoryDocumentStore.Providers.All.SingleOrDefault(p => p.Id == request.ProviderId); if (provider == null) { return(new NotFound()); } provider.MarketingInformation = request.MarketingInformation; provider.DateUpdated = request.UpdatedOn; provider.UpdatedBy = request.UpdatedBy.UserId; inMemoryDocumentStore.Providers.Save(provider); return(new Success()); }