Beispiel #1
0
        public static void AddNewMember(Member m)
        {
            var context = new CommerceDbContext();

            context.Members.Add(m);
            context.SaveChanges();
        }
Beispiel #2
0
        internal static Product GetProductById(int id)
        {
            CommerceDbContext context = new CommerceDbContext();
            Product           p       = context.Products.Find(id);

            return(p);
        }
Beispiel #3
0
        public static void DeleteProduct(int id)
        {
            var     context = new CommerceDbContext();
            Product p       = context.Products.Find(id);

            context.Products.Remove(p);
            context.SaveChanges();
        }
Beispiel #4
0
        public static void Update(Product p)
        {
            var context = new CommerceDbContext();

            // tells EF this product has only been modified
            context.Entry(p).State = System.Data.Entity.EntityState.Modified;
            // send update querty to the database
            context.SaveChanges();
        }
Beispiel #5
0
        internal static bool UserExists(LoginViewModel login)
        {
            var  db        = new CommerceDbContext();
            bool doesExist =
                (from member in db.Members
                 where member.Username == login.Username &&
                 member.Password == login.Password
                 select member).Any();

            return(doesExist);
        }
Beispiel #6
0
        public static bool IsUserNameTaken(RegistrationViewModel Reg)
        {
            // check if username is in use
            var  db          = new CommerceDbContext();
            bool isNameTaken =
                (from mem in db.Members
                 where mem.Username == Reg.Username
                 select mem).Count() == 1;

            return(isNameTaken);
        }
Beispiel #7
0
        /// <summary>
        /// Add product to the database
        /// </summary>
        /// <param name="p">Product to be added</param>
        public static void AddProduct(Product p)
        {
            //Create instance of DBContext class
            var context = new CommerceDbContext();

            //Prepare insert statement
            context.Products.Add(p);

            //Execute pending insert
            context.SaveChanges();
        }
Beispiel #8
0
        internal static List <Product> GetProductsByPage(int page, byte pageSize)
        {
            CommerceDbContext context  = new CommerceDbContext();
            List <Product>    prodList =
                context
                .Products
                .Take(pageSize)
                .OrderBy(p => p.Name)
                .Skip((page - 1) * pageSize)
                .ToList();

            return(prodList);
        }
Beispiel #9
0
        /// <summary>
        /// Gets all products sorted by product name
        /// </summary>
        /// <returns></returns>
        public static List <Product> GetAllProducts()
        {
            //LINQ (Language Integrated Query)

            var db = new CommerceDbContext();

            //What we are trying to do
            //SELECT * FROM Products ORDER BY Name

            //Method 1: LINQ Query Syntax
            List <Product> products =
                (from p in db.Products
                 orderby p.Name
                 select p).ToList();

            //Method 2: LINQ Method Syntax
            List <Product> products2 =
                db.Products
                .OrderBy(p => p.Name)
                .ToList();

            return(products);
        }
Beispiel #10
0
        public static int GetTotalNumProducts()
        {
            var context = new CommerceDbContext();

            return(context.Products.Count());
        }