Exemplo n.º 1
0
        public Order CreateOrder(
            CreateOrderOptions options)
        {
            var customer = customerService.GetCustomerById(
                new GetCustomerByIdOptions()
            {
                CustomerId = options.CustomerId
            });

            if (customer == null)
            {
                return(null);
            }
            var order = new Order()
            {
                DeliveryAddress = options.DeliveryAddress
            };

            foreach (var item in options.ProductIds)
            {
                var product = productService.SearchProducts(
                    new SearchProductOptions()
                {
                    ProductId = item
                }).SingleOrDefault();

                if (product == null)
                {
                    return(null);
                }
                order.OrderProducts.Add(new OrderProduct()
                {
                    ProductId = product.ProductId
                });
            }
            Console.WriteLine(order.OrderProducts.Count);
            customer.Orders.Add(order);

            context.Add(order);

            if (context.SaveChanges() > 0)
            {
                return(order);
            }

            return(null);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext()) {
                ICustomerService customerService = new CustomerService(
                    context);

                var results = customerService.SearchCustomers(
                    new SearchCustomerOptions()
                {
                    CustomerId = 3
                }).SingleOrDefault();
            }

            var orderOptions = new CreateOrderOptions();

            orderOptions.CustomerId = 5;
            orderOptions.ProductIds.Add("1312");
            orderOptions.ProductIds.Add("13112312312");
        }