Exemplo n.º 1
0
        public Product CreateProduct(
            CreateProductOptions options) {

            if (options == null)
            {
                return null;
            }

            var product = new Product() { 
                ProductId = options.ProductId,
                Description = options.Description,
                Name = options.Name,
                Category = options.Category,
                Price = options.Price                
            };

            context.Add(product);

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

            return null;
        }
Exemplo n.º 2
0
        public Customer CreateCustomer(
            CreateCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }
            var customer = new Customer()
            {
                Created   = DateTimeOffset.Now,
                Firstname = options.Firstname,
                Lastname  = options.Lastname,
                Email     = options.Email,
                VatNumber = options.VatNumber,
                IsActive  = true
            };

            context.Add(customer);

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

            return(null);
        }
Exemplo n.º 3
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.º 4
0
        public Customer CreateCustomer(
            CreateCustomerOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var customer = new Customer()
            {
                Lastname  = options.Lastname,
                Firstname = options.Firstname,
                VatNumber = options.Vatnumber
            };

            context_.Add(customer);

            if (context_.SaveChanges() > 0)
            {
                return(customer);
            }

            return(null);
        }