Exemplo n.º 1
0
        public string Register(string username)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                var customer = (from c in dbDriver.CustomerSet
                                where c.Username == username
                                select c).SingleOrDefault();

                if (customer == null)
                {
                    char[] charArray = username.ToCharArray();
                    Array.Reverse(charArray);
                    string password = new string(charArray);

                    Customer c1 = new Customer
                    {
                        Username = username,
                        Password = password,
                        Money    = 20
                    };

                    dbDriver.CustomerSet.Add(c1);
                    dbDriver.SaveChanges();
                    return(password);
                }
                else
                {
                    return("Username already exists!");
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                Product p1 = new Product
                {
                    Name   = "Pizza Margherita",
                    Price  = 7.50,
                    Amount = 100
                };
                Product p2 = new Product
                {
                    Name   = "Pizza Marinara",
                    Price  = 7.00,
                    Amount = 100
                };
                Product p3 = new Product
                {
                    Name   = "Pizza Pepperoni",
                    Price  = 8.00,
                    Amount = 100
                };
                Product p4 = new Product
                {
                    Name   = "Pizza Hawaii",
                    Price  = 8.00,
                    Amount = 10
                };
                dbDriver.ProductSet.Add(p1);
                dbDriver.ProductSet.Add(p2);
                dbDriver.ProductSet.Add(p3);
                dbDriver.ProductSet.Add(p4);
                dbDriver.SaveChanges();

                Customer c1 = new Customer
                {
                    Username = "******",
                    Password = "******",
                    Money    = 20
                };
                Customer c2 = new Customer
                {
                    Username = "******",
                    Password = "******",
                    Money    = 100
                };

                Customer c3 = new Customer
                {
                    Username = "******",
                    Password = "******",
                    Money    = 100
                };

                dbDriver.CustomerSet.Add(c1);
                dbDriver.CustomerSet.Add(c2);
                dbDriver.CustomerSet.Add(c3);
                dbDriver.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public int GetUserId(string username)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                var user = (from u in dbDriver.CustomerSet
                            where u.Username == username
                            select u).SingleOrDefault();

                return(user.Id);
            }
        }
Exemplo n.º 4
0
        public Customer GetCustomerById(int userid)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                dbDriver.Configuration.ProxyCreationEnabled = false;
                var user = (from u in dbDriver.CustomerSet
                            where u.Id == userid
                            select u).SingleOrDefault();

                return(user);
            }
        }
Exemplo n.º 5
0
        public Product GetProductById(int productid)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                dbDriver.Configuration.ProxyCreationEnabled = false;
                var product = (from p in dbDriver.ProductSet
                               where p.Id == productid
                               select p).SingleOrDefault();

                return(product);
            }
        }
Exemplo n.º 6
0
 public Order NewOrder(int custid)
 {
     using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
     {
         Order o1 = new Order
         {
             OrderDate  = DateTime.Now,
             CustomerId = custid
         };
         dbDriver.OrderSet.Add(o1);
         dbDriver.SaveChanges();
         return(o1);
     }
 }
Exemplo n.º 7
0
        public OrderEntry Buy(int orderid, int productid, int custid)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())

            {
                dbDriver.Configuration.ProxyCreationEnabled = false;

                OrderEntry orderentry = (from o in dbDriver.OrderEntrySet
                                         where o.OrderId == orderid && o.Product_Id == productid
                                         select o).SingleOrDefault();
                Customer cust = (from c in dbDriver.CustomerSet
                                 where c.Id == custid
                                 select c).SingleOrDefault();
                Product product = (from p in dbDriver.ProductSet
                                   where p.Id == productid
                                   select p).SingleOrDefault();

                if (product != null && cust.Money >= product.Price && product.Amount > 0)
                {
                    if (orderentry == null)
                    {
                        OrderEntry oe = new OrderEntry
                        {
                            Amount     = 1,
                            OrderId    = orderid,
                            Product_Id = productid
                        };
                        dbDriver.OrderEntrySet.Add(oe);
                        cust.Money      = cust.Money - product.Price;
                        product.Amount -= 1;
                        dbDriver.SaveChanges();
                        return(oe);
                    }
                    else
                    {
                        orderentry.Amount += 1;
                        cust.Money         = cust.Money - product.Price;
                        product.Amount    -= 1;
                        dbDriver.SaveChanges();
                        return(orderentry);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 8
0
        public List <Product> ProductList()
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                List <Product> productList = new List <Product>();

                var products =
                    from p in dbDriver.ProductSet
                    select p;

                foreach (Product p in products)
                {
                    productList.Add(p);
                }

                return(productList);
            }
        }
Exemplo n.º 9
0
        public List <OrderEntry> OrderEntryList(int orderId)
        {
            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                dbDriver.Configuration.ProxyCreationEnabled = false;
                List <OrderEntry> orderEntryList = new List <OrderEntry>();

                var orderEntries =
                    from oe in dbDriver.OrderEntrySet
                    where oe.OrderId == orderId
                    select oe;

                foreach (OrderEntry oe in orderEntries)
                {
                    orderEntryList.Add(oe);
                }

                return(orderEntryList);
            }
        }
Exemplo n.º 10
0
        public Boolean Login(string username, string password)
        {
            if (username == "" || password == "")
            {
                return(false);
            }

            using (PizzaShopDBEntities dbDriver = new PizzaShopDBEntities())
            {
                try
                {
                    Customer c1 = dbDriver.CustomerSet.Single(c => c.Username == username);
                    return(c1.Password == password);
                }
                catch
                {
                    return(false);
                }
            }
        }