예제 #1
0
        public override async Task <Model.Order> Add(Model.Order entity)
        {
            var idCustomer = entity.Customer.Id;

            entity.Customer = await _customerSQLServerRepository.ReadById(idCustomer);

            if (entity.Customer is null)
            {
                entity.ValidationResult.Errors.Add(new ValidationFailure("Id do cliente", $"Cliente id {idCustomer} inexistente"));
            }

            foreach (var item in entity.OrderItems)
            {
                Product.Model.Product product = await _productSQLServerRepository.ReadById(item.ProductId);

                if (product is null)
                {
                    entity.ValidationResult.Errors.Add(new ValidationFailure("Id do Produto", $"Produto id {item.ProductId} inexistente"));
                }
            }

            if (entity.ValidationResult.Errors.Count > 0)
            {
                return(entity);
            }

            return(await base.Add(entity));
        }
예제 #2
0
        private void Initilise()
        {
            Product.Model.Product prodBread  = new Product.Model.Product(1, "bread");
            Product.Model.Product prodButter = new Product.Model.Product(2, "butter");
            Product.Model.Product prodMilk   = new Product.Model.Product(3, "milk");

            // Initialise available products:
            ProductProvider = new Product.Provider();
            ProductProvider.Add(prodBread);
            ProductProvider.Add(prodButter);
            ProductProvider.Add(prodMilk);

            // Initialise available prices:
            PriceProvider = new Price.Provider();
            PriceProvider.AddCost(new Price.Model.Cost(prodBread.Id, 1));
            PriceProvider.AddCost(new Price.Model.Cost(prodButter.Id, 0.8));
            PriceProvider.AddCost(new Price.Model.Cost(prodMilk.Id, 1.15));

            // Intialise available offers:
            PriceProvider.AddOffer(new Price.Model.Offer("Buy 2 butter and get a Bread at 50% off", new Price.Model.Trigger(new List <Price.Model.Product>()
            {
                new Price.Model.Product(prodButter.Id, 2), new Price.Model.Product(prodBread.Id, 1)
            }), new Price.Model.Reward(0.5)));
            PriceProvider.AddOffer(new Price.Model.Offer("Buy 3 milk get the 4th milk for free", new Price.Model.Trigger(new List <Price.Model.Product>()
            {
                new Price.Model.Product(prodMilk.Id, 3)
            }), new Price.Model.Reward(1.15)));

            Basket = new App.Basket(PriceProvider);
        }
예제 #3
0
        public async Task AddProduct(Product.Model.Product product)
        {
            IReliableDictionary <Guid, Product.Model.Product> products = await
                                                                         _stateManager.GetOrAddAsync <IReliableDictionary <Guid, Product.Model.Product> >("products");

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                await products.AddOrUpdateAsync(tx, product.Id, product, (id, value) => product);

                await tx.CommitAsync();
            }
        }
        public async Task PostAsync([FromBody] ApiProduct apiProduct)
        {
            var newProduct = new Product.Model.Product()
            {
                Price        = apiProduct.Price,
                Name         = apiProduct.Name,
                Description  = apiProduct.Description,
                Availability = apiProduct.Availability,
                Id           = Guid.NewGuid()
            };

            await _service.AddProductAsync(newProduct);
        }
예제 #5
0
        public bool Post([FromForm] BodyData bodyData)
        {
            var product = new Product.Model.Product();

            JsonConvert.PopulateObject(bodyData.values, product);


            //Validate(order);
            if (!ModelState.IsValid)
            {
                return(false);
            }
            this.productContext.Products.Add(product);
            this.productContext.SaveChanges();
            return(true);
        }
예제 #6
0
        /// <summary>
        /// This is the main entry point for your service replica.
        /// This method executes when this replica of your service becomes primary and has write status.
        /// </summary>
        /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param>
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            _repo = new ServiceFabricProductRepository(this.StateManager);

            Product.Model.Product product1 = new Product.Model.Product()
            {
                Availability = 5,
                Description  = "IPhone",
                Id           = Guid.NewGuid(),
                Name         = "Iphone 5",
                Price        = 200.500
            };

            await _repo.AddProduct(product1);


            await _repo.GetAllProducts();
        }
예제 #7
0
 public async Task AddProductAsync(Product.Model.Product product)
 {
     await _repo.AddProduct(product);
 }