Beispiel #1
0
        /// <summary>
        /// Adds member to the database
        /// </summary>
        /// <param name="m"></param>
        public static void RegisterMember(Member m)
        {
            ECommerceDB db = new ECommerceDB();

            db.Members.Add(m);
            db.SaveChanges(); //MUST call SaveChanges for INSERTS, UPDATES, and DELETES!
        }
Beispiel #2
0
        public static void UpdateProduct(Product p)
        {
            ECommerceDB db = new ECommerceDB();

            db.Entry(p).State = EntityState.Modified;
            db.SaveChanges();
        }
Beispiel #3
0
        /// <summary>
        /// Adds product to database
        /// </summary>
        /// <param name="p"></param>
        public static void AddProduct(Product p)
        {
            var db = new ECommerceDB();

            db.Products.Add(p);
            db.SaveChanges();
        }
Beispiel #4
0
        public static void DeleteProductById(int value)
        {
            ECommerceDB db = new ECommerceDB();
            Product     p  = db.Products.Find(value);

            db.Products.Remove(p);
            db.SaveChanges();
        }
Beispiel #5
0
        public static List <Product> GetAllProducts()
        {
            ECommerceDB db = new ECommerceDB();
            //List<Product> prods = db.Products.ToList();
            List <Product> prods = (from p in db.Products
                                    select p).ToList();

            return(prods);
        }
Beispiel #6
0
        /// <summary>
        /// Finds a member with the supplied credentials
        /// Returns null if there is no match
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static Member FindMember(string username, string password)
        {
            var db = new ECommerceDB();

            //finds users with supplied credentials
            return((from mem in db.Members
                    where mem.Username == username &&
                    mem.Password == password
                    select mem).SingleOrDefault());
        }
Beispiel #7
0
        public static bool DoesUsernameExist(string username)
        {
            ECommerceDB db = new ECommerceDB();

            int count =
                (from u in db.Members
                 where u.Username == username
                 select u).Count();

            return((count == 1) ? true : false);
        }
Beispiel #8
0
        public static Member GetCurrentMember()
        {
            int id = SessionHelper.GetCurrentUserId();

            ECommerceDB db  = new ECommerceDB();
            Member      mem = (from m in db.Members
                               where m.MemberID == id
                               select m).Single();

            return(mem);
        }
Beispiel #9
0
        internal static Product GetProductById(int id)
        {
            ECommerceDB db = new ECommerceDB();
            //Product p = db.Products.Find(id);
            //return p;

            Product p = (from prod in db.Products
                         where prod.ProductID == id
                         select prod).SingleOrDefault();

            return(p);
        }