Ejemplo n.º 1
0
        public async Task <ProductModel> Update(ProductModel product)
        {
            var products = await ProductDictionary();

            using (var tx = this.StateManager.CreateTransaction())
            {
                var existingProduct = await products.TryGetValueAsync(tx, product.Id);

                var updatedProduct = product.Clone();
                if (existingProduct.HasValue)
                {
                    updatedProduct.VendorId = existingProduct.Value.VendorId;
                    updatedProduct.Id       = existingProduct.Value.Id;
                }

                updatedProduct.LastUpdate = DateTime.UtcNow;
                await products.SetAsync(tx, updatedProduct.Id, updatedProduct);

                await tx.CommitAsync();

                await this.RaiseEvent(serviceBusConfiguration.ProductChangedTopicName, new ProductChangedEvent()
                {
                    Previous = existingProduct.Value, Current = updatedProduct
                });


                return(updatedProduct);
            }
        }
Ejemplo n.º 2
0
        public async Task <ProductModel> Create(ProductModel product)
        {
            var products = await ProductDictionary();

            using (var tx = this.StateManager.CreateTransaction())
            {
                var createdProduct = product.Clone();
                if (createdProduct.Id == Guid.Empty)
                {
                    createdProduct.Id = Guid.NewGuid();
                }
                createdProduct.CreationDate = DateTime.UtcNow;

                await products.AddAsync(tx, createdProduct.Id, createdProduct);

                await tx.CommitAsync();

                await this.RaiseEvent(serviceBusConfiguration.ProductChangedTopicName, new ProductChangedEvent()
                {
                    Current = createdProduct
                });

                return(product);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateProduct(Guid vendorId, Guid?productId, [FromBody] ProductModel productModel)
        {
            try
            {
                if (!productId.HasValue)
                {
                    productId = Guid.NewGuid();
                }

                var createdProduct = productModel.Clone();
                createdProduct.VendorId     = vendorId;
                createdProduct.CreationDate = DateTime.UtcNow;
                createdProduct.LastUpdate   = null;
                createdProduct.Id           = productId.Value;

                var savedProduct = await ServiceProxyUtils.GetProductService(productId.Value).Create(createdProduct);

                return(CreatedAtAction(nameof(Product), new { vendorId = vendorId, productId = savedProduct.Id }, savedProduct));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }
        /// <summary>
        /// Test methods exposed by the EntityHelper class.
        /// </summary>
        private void Step_20_TestEntityHelper_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                mock = CreateMockInstance(tm);

                ProductModel entity = mock.Copy() as ProductModel;
                entity = (ProductModel)mock.Clone();
                Assert.IsTrue(ProductModel.ValueEquals(entity, mock), "Clone is not working");
            }
        }
Ejemplo n.º 5
0
        private void uxProductChange_Click(object sender, RoutedEventArgs e)
        {
            var window = new ProductWindow();

            window.Product = selectedProduct.Clone();

            if (true == window.ShowDialog())
            {
                App.InventoryRepository.Update(window.Product.ToRepositoryModel());
                LoadProducts();
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateProduct(Guid vendorId, Guid productId, [FromBody] ProductModel product)
        {
            try
            {
                var updatedProduct = product.Clone();
                updatedProduct.Id         = productId;
                updatedProduct.VendorId   = vendorId;
                updatedProduct.LastUpdate = DateTime.UtcNow;

                var savedProduct = await ServiceProxyUtils.GetProductService(productId).Update(updatedProduct);

                return(new OkObjectResult(savedProduct));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }