Ejemplo n.º 1
0
        public static void AddNewMember(Member m)
        {
            var context = new CommerceDbContext();

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

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

            context.Products.Remove(p);
            context.SaveChanges();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        public static int GetTotalNumProducts()
        {
            var context = new CommerceDbContext();

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