示例#1
0
        public OneOf <NotFound, Success> Execute(
            InMemoryDocumentStore inMemoryDocumentStore,
            UpdateApprenticeshipStatus request)
        {
            var app = inMemoryDocumentStore.Apprenticeships.All.SingleOrDefault(a => a.Id == request.ApprenticeshipId);

            if (app == null)
            {
                return(new NotFound());
            }
            else
            {
                app.RecordStatus = request.Status;
                return(new Success());
            }
        }
示例#2
0
        public async Task <OneOf <NotFound, Success> > Execute(
            DocumentClient client,
            Configuration configuration,
            UpdateApprenticeshipStatus request)
        {
            var documentUri = UriFactory.CreateDocumentUri(
                configuration.DatabaseId,
                configuration.ApprenticeshipCollectionName,
                request.ApprenticeshipId.ToString());

            var partitionKey = new PartitionKey(request.ProviderUkprn);

            Apprenticeship apprenticeship;

            try
            {
                var query = await client.ReadDocumentAsync <Apprenticeship>(
                    documentUri,
                    new RequestOptions()
                {
                    PartitionKey = partitionKey
                });

                apprenticeship = query.Document;
            }
            catch (DocumentClientException dex) when(dex.StatusCode == HttpStatusCode.NotFound)
            {
                return(new NotFound());
            }

            apprenticeship.RecordStatus = request.Status;

            await client.ReplaceDocumentAsync(
                documentUri,
                apprenticeship,
                new RequestOptions()
            {
                PartitionKey = partitionKey
            });

            return(new Success());
        }