public ReturnData <Order> GetOrderdByOrderId(int customerId, int orderId)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                Customer customer = db.Customers.Find(customerId);

                if (customer == null)
                {
                    return(new ReturnData <Order>
                    {
                        Error = 1,
                        Description = "there is no such customer"
                    });
                }

                List <Order> orders = db.Orders.Where(o => o.CustomerId == customerId).ToList();

                Order order = db.Orders.Find(orderId);

                return(new ReturnData <Order>

                {
                    Data = order,
                    Error = (order == null) ? 1 : 0,
                    Description = (order == null) ? "there is no such order " : "ok"
                });
            }
        }
示例#2
0
        public void DoSale()
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            Customer c  = db.Customers.Find(1);
            Product  p1 = db.Products.Find(2);
            Product  p2 = db.Products.Find(4);

            Order order = new Order
            {
                Customer = c,
                Date     = new DateTime(),
            };
            OrderProduct op = new OrderProduct
            {
                Order         = order,
                OrderQuantity = 2,
                Product       = p1
            };

            OrderProduct op2 = new OrderProduct
            {
                Order         = order,
                OrderQuantity = 3,
                Product       = p2
            };



            db.OrderProducts.Add(op);
            db.OrderProducts.Add(op2);
            db.SaveChanges();
        }
        public ReturnData <Customer> UpdateCustomerById(CustomerDto customerdto, int customerid)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                Customer updatedcustomer = db.Customers.Find(customerid);

                if (customerdto.Name != null)
                {
                    updatedcustomer.Name = customerdto.Name;
                }

                if (customerdto.Address != null)
                {
                    updatedcustomer.Address = customerdto.Address;
                }

                if (customerdto.Balance != 0)
                {
                    updatedcustomer.Balance = customerdto.Balance;
                }
                if (customerdto.RegistrationDate != null)
                {
                    updatedcustomer.RegistrationDate = customerdto.RegistrationDate;
                }

                db.SaveChanges();

                return(new ReturnData <Customer>
                {
                    Data = updatedcustomer,
                    Error = (updatedcustomer == null) ? 1 : 0,
                    Description = (updatedcustomer == null) ? "there is no such customer" : "OK"
                });
            }
        }
        /* Services  for Products*/

        public List <Product> GetProducts(int howMany)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                List <Product> products = db.Products.Take(howMany).ToList();

                return(products);
            }
        }
示例#5
0
        public List <Customer> GetCustomers(int howMany)
        {
            List <Customer> customers;

            using EcommerceDbContent db = new EcommerceDbContent();
            customers = db.Customers
                        .Take(howMany)
                        .ToList();
            return(customers);
        }
示例#6
0
        public void Delete(int id)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            Customer = db.Customers.Find(id);
            if (Customer != null)
            {
                db.Customers.Remove(Customer);
            }

            db.SaveChanges();
        }
示例#7
0
        public ReturnData <Order> GetOrdersByCustomerId(int customerId)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            Order order = db.Orders.Find(customerId);

            return(new ReturnData <Order>
            {
                Data = order,
                Error = (order == null) ? 1 : 0,
                Description = (order == null) ? "No such customer Id = "
                              + customerId : "Ok"
            });
        }
示例#8
0
        public ReturnData <Product> GetProductById(int ProductId)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            Product product = db.Products.Find(ProductId);

            return(new ReturnData <Product>
            {
                Data = product,
                Error = (product == null) ? 1 : 0,
                Description = (product == null) ? "No such product Id = "
                              + ProductId : "Ok"
            });
        }
示例#9
0
        public Customer CreateCustomer(CustomerDto customerDto)
        {
            Customer c = new Customer
            {
                Name    = customerDto.Name,
                Address = customerDto.Address,
            };

            using EcommerceDbContent db = new EcommerceDbContent();
            db.Customers.Add(c);
            db.SaveChanges();
            return(c);
        }
        public ReturnData <Product> GetProductById(int productid)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                Product p = db.Products.Find(productid);

                return(new ReturnData <Product>
                {
                    Data = p,
                    Error = (p == null) ? 1 : 0,
                    Description = (p == null) ? "there is no such product" : "Ok"
                });
            }
        }
示例#11
0
        public ReturnData <List <Product> > GetProductByName(string productName)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            List <Product> product = db.Products
                                     .Where(n => n.Name.StartsWith(productName)).ToList();

            return(new ReturnData <List <Product> >
            {
                Data = product,
                Error = (product == null) ? 1 : 0,
                Description = (product == null) ? "No such product name = "
                              + productName : "Ok"
            });
        }
示例#12
0
        public ReturnData <List <Customer> > GetCustomerByName(string customerName)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            List <Customer> customers = db.Customers
                                        .Where(n => n.Name.StartsWith(customerName)).ToList();

            return(new ReturnData <List <Customer> >
            {
                Data = customers,
                Error = (customers == null) ? 1 : 0,
                Description = (customers == null) ? "No such customer name = "
                              + customerName : "Ok"
            });
        }
示例#13
0
        public Product CreateProduct(ProductDto productDto)
        {
            Product p = new Product
            {
                Name          = productDto.Name,
                Price         = productDto.Price,
                StockQuantity = productDto.StockQuantity
            };

            using EcommerceDbContent db = new EcommerceDbContent();
            db.Products.Add(p);
            db.SaveChanges();
            return(p);
        }
        public ReturnData <Customer> GetCustomerById(int customerId)
        {
            using (EcommerceDbContent college = new EcommerceDbContent())
            {
                Customer customer = college.Customers.Find(customerId);

                return(new ReturnData <Customer>
                {
                    Data = customer,
                    Error = (customer == null) ? 1 : 0,
                    Description = (customer == null) ? "no such student id " : "ok"
                });
            }
        }
示例#15
0
        public ReturnData <Order> GetOrderByCustomerId(int customerId, int orderId)
        {
            using EcommerceDbContent db = new EcommerceDbContent();
            List <Order> order = db.Orders
                                 .Where(c => c.CustomerId.Equals(customerId)).ToList();

            order = db.Orders
                    .Where(o => o.Id.Equals(orderId)).ToList();
            return(new ReturnData <Order>
            {
                Error = (order == null) ? 1 : 0,
                Description = (order == null) ? "No such order Id = "
                              + customerId : "Ok"
            });
        }
        public List <Customer> GetCustomers(int howMany)
        {
            List <Customer> Customers;



            using (EcommerceDbContent college = new EcommerceDbContent())
            {
                Customers = college.Customers
                            .Take(howMany)
                            .ToList();

                return(Customers);
            }
        }
示例#17
0
 public void Create()
 {
     Customer = new Customer
     {
         Name             = "Dimitris",
         Address          = "Athens",
         RegistrationDate = new DateTime(),
         Balance          = 0
     };
     using (EcommerceDbContent db = new EcommerceDbContent())
     {
         db.Customers.Add(Customer);
         db.SaveChanges();
     }
 }
        public ReturnData <List <Order> > GetOrdersByCustomerId(int customerId)
        {
            using (EcommerceDbContent college = new EcommerceDbContent())
            {
                List <Order> orders = college.Orders.Where(o => o.CustomerId == customerId).ToList();

                return(new ReturnData <List <Order> >

                {
                    Data = orders,
                    Error = (orders == null) ? 1 : 0,
                    Description = (orders == null) ? "the customer has no orders " : "ok"
                });
            }
        }
        public Product CreateProduct(ProductDto productdto)
        {
            Product p = new Product();

            p.Name          = productdto.Name;
            p.Price         = productdto.Price;
            p.StockQuantity = productdto.OrderQuantity;

            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                db.Products.Add(p);
                db.SaveChanges();
            }
            return(p);
        }
        public Order NewOrderById(int customerid, List <ProductDto> products)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                Customer c = db.Customers.Find(customerid);

                Order order = new Order()
                {
                    Customer = c,

                    CustomerId = customerid,

                    Date = DateTime.Now
                };


                List <OrderProduct> orderProducts = new List <OrderProduct>();

                foreach (var product in products)
                {
                    Product orderedProduct = db.Products.Where(p => p.Name.Equals(
                                                                   product.Name,
                                                                   StringComparison.OrdinalIgnoreCase))
                                             .First();


                    OrderProduct orderedproducts = new OrderProduct()
                    {
                        Product       = orderedProduct,
                        OrderQuantity = product.OrderQuantity,
                        OrderId       = order.Id,
                        ProductId     = orderedProduct.Id
                    };

                    orderProducts.Add(orderedproducts);
                    db.OrderProducts.Add(orderedproducts);
                }


                order.OrderProduct = orderProducts;

                db.Orders.Add(order);
                db.SaveChanges();
                return(order);
            }
        }
        public ReturnData <List <Product> > GetProductByName(string productname)
        {
            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                List <Product> products = db.Products.Where(p => p.Name.Contains
                                                                (productname,
                                                                StringComparison.OrdinalIgnoreCase)).
                                          ToList();

                return(new ReturnData <List <Product> >
                {
                    Data = products,
                    Error = (products == null) ? 1 : 0,
                    Description = (products == null) ? "there are no such product " : "Ok"
                });
            }
        }
        public Customer CreateCustomer(CustomerDto customerdto)
        {
            Customer c = new Customer()
            {
                Name             = customerdto.Name,
                Address          = customerdto.Address,
                Balance          = customerdto.Balance,
                RegistrationDate = customerdto.RegistrationDate
            };

            using (EcommerceDbContent db = new EcommerceDbContent())
            {
                db.Customers.Add(c);
                db.SaveChanges();
            }
            return(c);
        }
        public ReturnData <List <Customer> > GetCustomerByName(string customerName)
        {
            using (EcommerceDbContent college = new EcommerceDbContent())
            {
                List <Customer> customers = college.Customers.Where(s => s.Name.
                                                                    Contains(customerName,
                                                                             StringComparison.OrdinalIgnoreCase)).
                                            ToList();

                return(new ReturnData <List <Customer> >

                {
                    Data = customers,
                    Error = (customers == null) ? 1 : 0,
                    Description = (customers == null) ? "no such student " : "ok"
                });
            }
        }
示例#24
0
        public ReturnData <Customer> UpdateCustomerById(int customerId, CustomerDto customerDto)
        {
            if (customerDto == null)
            {
                return(new ReturnData <Customer>
                {
                    Error = 1001,
                    Description = "No data were given"
                });
            }

            using EcommerceDbContent db = new EcommerceDbContent();
            Customer customer = db.Customers.Find(customerId);

            if (customer == null)
            {
                return(new ReturnData <Customer>
                {
                    Error = 1002,
                    Description = "No such customer Id"
                });
            }

            if (customerDto.Address != null)
            {
                customer.Address = customerDto.Address;
            }
            if (customerDto.Name != null)
            {
                customer.Name = customerDto.Name;
            }

            db.SaveChanges();
            return(new ReturnData <Customer>
            {
                Data = customer,
                Error = 0,
                Description = "No errors"
            });
        }
示例#25
0
        public void Update(CustomerDto customerDto, int id)
        {
            if (customerDto == null)
            {
                return;
            }
            using EcommerceDbContent db = new EcommerceDbContent();
            Customer = db.Customers.Find(id);
            if (Customer != null)
            {
                if (customerDto.Name != null)
                {
                    Customer.Name = customerDto.Name;
                }
                if (customerDto.Address != null)
                {
                    Customer.Address = customerDto.Address;
                }
            }

            db.SaveChanges();
        }
示例#26
0
        public void CreateData()
        {
            using EcommerceDbContent db = new EcommerceDbContent();


            db.Customers.AddRange(
                new List <Customer>
            {
                new Customer
                {
                    Name             = "Eleana",
                    Address          = "Athina",
                    Balance          = 100,
                    RegistrationDate = new DateTime()
                },
                new Customer
                {
                    Name             = "Dimitra",
                    Address          = "Athina",
                    Balance          = 120,
                    RegistrationDate = new DateTime()
                },
                new Customer
                {
                    Name             = "Theodora",
                    Address          = "Athina",
                    Balance          = 98,
                    RegistrationDate = new DateTime()
                },
            }

                );

            db.Products.AddRange(
                new List <Product>
            {
                new Product
                {
                    Name          = "car",
                    Price         = 99,
                    StockQuantity = 4
                },

                new Product
                {
                    Name          = "yacht",
                    Price         = 29,
                    StockQuantity = 20
                },
                new Product
                {
                    Name          = "iphone",
                    Price         = 39,
                    StockQuantity = 2
                },

                new Product
                {
                    Name          = "drone",
                    Price         = 133,
                    StockQuantity = 2
                },
            }

                );

            db.SaveChanges();
        }
示例#27
0
 public ProductsController(EcommerceDbContent ecommerceDbContent)
 {
     _ecommerceDbContent = ecommerceDbContent;
 }
示例#28
0
 public void Read(int id)
 {
     using EcommerceDbContent db = new EcommerceDbContent();
     Customer = db.Customers.Find(id);
 }