Ejemplo n.º 1
0
        public void Update(Client updatedClient)
        {
            var priceCalculator = new ClientsProductsHelper(_products);

            updatedClient = priceCalculator.CalculatePriceVariations(updatedClient);
            _clients.ReplaceOne(client => client.Id == updatedClient.Id, updatedClient);
        }
Ejemplo n.º 2
0
        public void Create(Client client)
        {
            client.VisibleProducts = GetProducts();
            var priceCalculator = new ClientsProductsHelper(_products);

            client = priceCalculator.CalculatePriceVariations(client);
            _clients.InsertOne(client);
        }
Ejemplo n.º 3
0
        public Product Create(Product product)
        {
            _products.InsertOne(product);
            var clients = GetClients();
            var clientPriceCalculator = new ClientsProductsHelper(_products);

            foreach (var client in clients)
            {
                client.VisibleProducts.Add(product);
                var updatedClient = clientPriceCalculator.CalculatePriceVariations(client);
                _clients.ReplaceOne(clientDB => clientDB.Id == updatedClient.Id, updatedClient);
            }
            return(product);
        }
Ejemplo n.º 4
0
        public void Delete(string productId)
        {
            var clients = GetClients();
            var clientPriceCalculator = new ClientsProductsHelper(_products);

            foreach (var client in clients)
            {
                var productToUpdate = client.VisibleProducts.Find(product => product.Id == productId);
                if (productToUpdate != null)
                {
                    client.VisibleProducts.Remove(productToUpdate);
                    _clients.ReplaceOne(clientDB => clientDB.Id == client.Id, client);
                }
            }
            _products.DeleteOne(product => product.Id == productId);
        }
Ejemplo n.º 5
0
        public void Update(Product updatedProduct)
        {
            _products.ReplaceOne(product => product.Id == updatedProduct.Id, updatedProduct);
            var clients = GetClients();
            var clientPriceCalculator = new ClientsProductsHelper(_products);

            foreach (var client in clients)
            {
                var productToUpdate = client.VisibleProducts.Find(product => product.Id == updatedProduct.Id);
                if (productToUpdate != null)
                {
                    client.VisibleProducts.Remove(productToUpdate);
                    client.VisibleProducts.Add(updatedProduct);
                    var updatedClient = clientPriceCalculator.CalculatePriceVariations(client);
                    _clients.ReplaceOne(clientDB => clientDB.Id == updatedClient.Id, updatedClient);
                }
            }
        }