Пример #1
0
        //public string BuyProduct(Customer u, Product p, int amount) {
        //    if (p.Amount == 0) {
        //        return "Product " + p.Name + " is no longer available";
        //    }
        //    else if (amount <= p.Amount) {
        //        if (u.Balance >= (p.Price * amount)) {
        //            u.Balance = u.Balance - (p.Price * amount);
        //            p.Amount = p.Amount - amount;
        //            // bought product has yet to be added to BoughtProducts

        //            return "You have bought " + p.Name + " for €" + (p.Price * amount) + ".\n" +
        //                "Your new balance is €" + u.Balance;
        //        }
        //        else {
        //            return "Your balance is insufficient";
        //        }
        //    }
        //    else {
        //        return p.Name + " is sold out.";
        //    }
        //}

        // Methods related to users.
        public string Register(string username)
        {
            char[] passwordArray = username.ToArray();
            Array.Reverse(passwordArray);
            string password = new string(passwordArray);

            using (shopDBEntities1 ctx = new shopDBEntities1()) {
                CustomerSet newCustomer = new CustomerSet {
                    Balance  = 50.0,
                    Username = username,
                    Password = password
                };
            }
            return(new string(passwordArray));
            //TODO password generation needs to be added.
        }
Пример #2
0
        // Methods related to products.
        public List <ProductSet> GetAllProducts()
        {
            using (shopDBEntities1 ctx = new shopDBEntities1()) {
                var products = from p in ctx.ProductSet
                               where p.amount > 0
                               select p;

                List <ProductSet> pList = new List <ProductSet>();
                foreach (ProductSet p in products)
                {
                    pList.Add(new ProductSet {
                        amount      = p.amount,
                        ProductName = p.ProductName,
                        Price       = p.Price,
                        ProductId   = p.ProductId
                    });
                }

                return(pList);
            }
        }