Esempio n. 1
0
        public async Task UpdateRegionStock(RegionStockDocument regionStock)
        {
            try
            {
                var requestOptions = new RequestOptions()
                {
                    AccessCondition = new AccessCondition()
                    {
                        Type      = AccessConditionType.IfMatch,
                        Condition = regionStock.Version
                    }
                };
                await _documentClient.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(_dbName, _stockQuantityCollectionName, regionStock.Id), regionStock, requestOptions);
            }
            catch (DocumentClientException de)
            {
                Exception baseException = de.GetBaseException();
                var       message       = $"{de.StatusCode} error occurred: {de.Message}, Message: {baseException.Message}";
                Trace.TraceError(message);
                if (de.StatusCode == HttpStatusCode.PreconditionFailed)
                {
                    throw new OptimisticConcurrencyException(message, de);
                }

                if (de.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message, de);
                }

                throw;
            }
        }
Esempio n. 2
0
 public async Task Persist(IRegionStockAggregate regionStockAggregate)
 {
     if (string.IsNullOrEmpty(regionStockAggregate.Version))
     {
         await CreateRegionStock(RegionStockDocument.CreateFrom(regionStockAggregate));
     }
     else
     {
         await UpdateRegionStock(RegionStockDocument.CreateFrom(regionStockAggregate));
     }
 }
Esempio n. 3
0
        //public RegionStockDocument GetRegionStockBySku(string sku)
        //{
        //    var response = _documentClient.CreateDocumentQuery<RegionStockDocument>(
        //        UriFactory.CreateDocumentCollectionUri(_dbName, _stockQuantityCollectionName))
        //        .Where(rs => rs.WarehouseAvailableStocks.Any(x => x.Sku == sku))
        //        .AsEnumerable()
        //        .Where();

        //    return response.FirstOrDefault();
        //}

        public async Task CreateRegionStock(RegionStockDocument regionStock)
        {
            try
            {
                await _documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(_dbName, _stockQuantityCollectionName), regionStock);
            }
            catch (DocumentClientException de)
            {
                Exception baseException = de.GetBaseException();
                var       message       = $"{de.StatusCode} error occurred: {de.Message}, Message: {baseException.Message}";
                Trace.TraceError(message);
                if (de.StatusCode == HttpStatusCode.Conflict)
                {
                    throw new DuplicateResourceKeyException(message, de);
                }

                throw;
            }
        }