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); }
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"); }