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

            //    var results = customerService.CreateCustomer(
            //        new CreateCustomerOptions()
            //        {
            //            FirstName = "Dimitris",
            //            LastName = "grevenos",
            //            Email = "*****@*****.**",
            //            Phone = "6988776655",
            //            VatNumber = "123456789",
            //            IsActive = true,
            //        });
            //}

            using (var context = new TinyCrmDbContext())
            {
                IProductService productService = new ProductService(
                    context);

                var results = productService.CreateProduct(
                    new CreateProductOptions()
                {
                    ProductId       = "AB",
                    Name            = "p1",
                    Description     = "The Product 1 is this product",
                    ProductCategory = ProductCategory.Laptops
                });
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext())
            {
                var customerService = new CustomerService(context);

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

                //Console.WriteLine(results.Firstname);

                var result = customerService.CreateCustomer(new CreateCustomerOptions
                {
                    Firstname = "Thanos",
                    Lastname  = "batzelios",
                    VatNumber = "123456789"
                });

                Console.WriteLine(result.Firstname);

                //var up = customerService.UpdateCustomer(new UpdateCustomerOptions
                //{

                //    Email = "*****@*****.**"
                //},2);
            }
        }
Exemplo n.º 3
0
 public OrderService(
     TinyCrmDbContext contextByProgram,
     ICustomerService custService,
     IProductService prodService)
 {
     context         = contextByProgram;
     customerService = custService;
     productService  = prodService;
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext()) {
                ICustomerService customerService = new CustomerService(
                    context);

                var customer = customerService.CreateCustomer(
                    new CreateCustomerOptions()
                {
                    Firstname = "Dimitris",
                    Lastname  = "Pnevmatikos",
                    Vatnumber = "123456789"
                });
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext())
            {
                IProductService  productService  = new ProductService(context);
                ICustomerService customerService = new CustomerService(context);
                IOrderService    orderService    = new OrderService(context, customerService, productService);


                var customer = customerService.CreateCustomer(new CreateCustomerOptions()
                {
                    FirstName = "Dimitris",
                    LastName  = "Pnevmatikos",
                    VatNumber = "123456789"
                });
            }
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext())
            {
                ICustomerService customerService = new CustomerService(context);

                var customer = customerService.CreateCustomer(
                    new CreateCustomerOptions()
                {
                    Firstname = "Dimitris",
                    LastName  = "Pneumatikos",
                    Vatnumber = "123456789"
                });

                //IOrderService orderService = new OrderService(context, customerService);
                //var results = customerService.SearchCustomers(new SearchCustomerOptions()
                //{
                //    CustomerId = 3
                //}).SingleOrDefault();
            }
        }
Exemplo n.º 8
0
 public ProductService(TinyCrmDbContext contextByProgram)
 {
     context = contextByProgram;
 }
Exemplo n.º 9
0
 static void Main(string[] args)
 {
     using (var context = new TinyCrmDbContext()) {
     }
 }
Exemplo n.º 10
0
        public static IQueryable <Customer> SearchCustomers(CustomerOptions customerOptions, TinyCrmDbContext dbContext)
        {
            if (customerOptions.CreatedFrom != null &&
                customerOptions.CreatedTo != null &&
                customerOptions.CreatedFrom > customerOptions.CreatedTo)
            {
                return(null);
            }

            var query = dbContext.Set <Customer>().AsQueryable();

            if (customerOptions.CustomerId != null)
            {
                query = query.Where(c => c.CustomerId == customerOptions.CustomerId);
            }

            if (customerOptions.VatNumber != null)
            {
                query = query.Where(c => c.VatNumber == customerOptions.VatNumber);
            }

            if (customerOptions.CreatedFrom != null)
            {
                query = query.Where(c => c.Created >= customerOptions.CreatedFrom);
            }

            if (customerOptions.CreatedTo != null)
            {
                query = query.Where(c => c.Created <= customerOptions.CreatedTo);
            }

            if (!String.IsNullOrWhiteSpace(customerOptions.FirstName))
            {
                query = query.Where(c => c.FirstName.Contains(customerOptions.FirstName));
            }

            if (!String.IsNullOrWhiteSpace(customerOptions.LastName))
            {
                query = query.Where(c => c.LastName.Contains(customerOptions.LastName));
            }

            query = query.Take(500);
            return(query);
        }
Exemplo n.º 11
0
        public static IQueryable <Product> SearchProducts(ProductOptions productOptions, TinyCrmDbContext dbContext)
        {
            if (productOptions.PriceFrom != null &&
                productOptions.PriceTo != null &&
                productOptions.PriceFrom > productOptions.PriceTo)
            {
                return(null);
            }

            var query = dbContext.Set <Product>().AsQueryable();

            if (productOptions.ProductId != null)
            {
                query = query.Where(p => p.ProductId == productOptions.ProductId);
            }

            if (productOptions.Categories != null && productOptions.Categories.Any())
            {
                query = query.Where(p => productOptions.Categories.Contains(p.Category));
            }

            if (productOptions.PriceFrom != null)
            {
                query = query.Where(p => p.Price >= productOptions.PriceFrom);
            }

            if (productOptions.PriceTo != null)
            {
                query = query.Where(p => p.Price <= productOptions.PriceTo);
            }

            query = query.Take(500);
            return(query);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            var dbContext = new TinyCrmDbContext();

            /*var productsSeed = GetProductsFromCsv("C:\\data.csv");
             * foreach (Product p in productsSeed)
             * {
             *    dbContext.Add(p);
             * }
             * dbContext.SaveChanges();*/

            var customerOpts = new CustomerOptions
            {
                CreatedFrom = new DateTime(2020, 5, 1),
                CreatedTo   = new DateTime(2020, 5, 3)
            };

            // var customer = SearchCustomers(customerOpts, dbContext).SingleOrDefault();

            var customers = SearchCustomers(customerOpts, dbContext).ToList();

            if (customers.Any())
            {
                Console.WriteLine("===Customers===");
                foreach (Customer c in customers)
                {
                    Console.WriteLine($"| {c.CustomerId} | {c.VatNumber} | {c.FirstName} | {c.LastName} | {c.Created} |");
                }
            }
            else
            {
                Console.WriteLine("Nothing Found!");
            }

            /*var productOpts = new ProductOptions
             * {
             *    Categories = new List<ProductCategory>()
             *    {
             *          ProductCategory.Headphones
             *    }
             * };
             *
             * var products = SearchProducts(productOpts, dbContext).ToList();
             *
             * var order = new Order()
             * {
             *    DeliveryAddress = "Unknown 123, 00000"
             * };
             *
             * if (products.Any())
             * {
             *    foreach (Product p in products)
             *    {
             *          order.OrderProducts.Add(
             *                new OrderProduct()
             *                {
             *                      Product = p
             *                });
             *    }
             * }
             * else
             * {
             *    Console.WriteLine("Nothing Found!");
             * }
             *
             * if (customer != null)
             * {
             *    customer.Orders.Add(order);
             *    dbContext.SaveChanges();
             * }*/

            dbContext.Dispose();
        }
Exemplo n.º 13
0
 public CustomerService(TinyCrmDbContext context)
 {
     context_ = context;
 }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            using (var context = new TinyCrmDbContext())
            {
                ICustomerService customerService = new CustomerService(
                    context);

                // IProductService productService = new ProductService(
                //      context);

                // IOrderService orderService = new OrderService(
                //      context, customerService, productService);

                // CREATE CUSTOMER
                var customer = customerService.CreateCustomer(
                    new CreateCustomerOptions()
                {
                    //Firstname = "Sakis",
                    //Lastname = "Batsilas",
                    //Email = "*****@*****.**",
                    VatNumber = "098765432"
                });

                /*
                 * // SEARCH CUSTOMERS
                 * var customers = customerService.SearchCustomers(
                 * new SearchCustomerOptions {
                 *  Firstname = "Sakis"
                 * }).ToList();
                 *
                 * // UPDATE CUSTOMERS
                 * var customer = customerService.UpdateCustomer(
                 * new UpdateCustomerOptions {
                 *  CustomerId = 9,
                 *  Firstname = "Kevin"
                 * });
                 *
                 * // GET CUSTOMERS BY ID
                 * var customer = customerService.GetCustomerById(
                 *  new GetCustomerByIdOptions() {
                 *      CustomerId = 2
                 *  });
                 *
                 * // CREATE PRODUCTS
                 * var product = productService.CreateProduct(
                 *   new CreateProductOptions()
                 *   {
                 *      ProductId = "PRCT100",
                 *      Name = "xiaomi",
                 *      Price = 60.0m,
                 *      Category = ProductCategory.Headphones,
                 *      Description = "product 100"
                 *   });
                 *
                 * // SEARCH PRODUCTS
                 * var products = productService.SearchProducts(
                 *  new SearchProductOptions
                 * {
                 *  ProductId = "PRCT100"
                 * }).ToList();
                 *
                 * //UPDATE PRODUCTS
                 * var customer = productService.UpdateProduct(
                 * new UpdateProductOptions {
                 *  ProductId = "PRCT100",
                 *  Name = "lenovo",
                 *  Price = 35.0m,
                 *  Category = ProductCategory.Printers
                 * });
                 *
                 * // GET PRODUCTS BY ID
                 * var product = productService.GetProductById(
                 *  new GetProductByIdOptions()
                 *  {
                 *      ProductId = "PDCT3"
                 *  });
                 *
                 * // CREATE ORDER
                 * var order = orderService.CreateOrder(
                 *  new CreateOrderOptions()
                 *  {
                 *      CustomerId = 2,
                 *      DeliveryAddress = "Los Angeles",
                 *      ProductIds = { "PDCT5","PDCT6","PRCT9"}
                 *  });
                 *
                 * // SEARCH ORDERS
                 * var orders = orderService.SearchOrders(
                 *  new SearchOrderOptions
                 *  {
                 *      OrderId = 5
                 *  }).ToList();
                 *
                 * //UPDATE ORDERS
                 * var orders = orderService.UpdateOrder(
                 * new UpdateOrderOptions
                 * {
                 *  OrderId = 2,
                 *  DeliveryAddress = "Krania"
                 * });
                 */
            }
        }
Exemplo n.º 15
0
 public CustomerService(TinyCrmDbContext contextByProgram)
 {
     context = contextByProgram;
 }