示例#1
0
        public static void Create(string paymentTypeName)
        {
            PaymentType pay = PaymentTypeFactory.CreatePayment(paymentTypeName);

            db.PaymentTypes.Add(pay);
            db.SaveChanges();
        }
示例#2
0
        public bool checkout(int userID, int paymentID)
        {
            HeaderTransaction header = new HeaderTransaction();

            header.UserID         = userID;
            header.PaymentTypesID = paymentID;
            header.Date           = DateTime.Now;
            var head = db.HeaderTransactions.Add(header);

            if (head == null)
            {
                return(false);
            }

            db.SaveChanges();
            var carts = cartRepository.GetCartByUser(userID);

            foreach (Cart item in carts)
            {
                DetailTransaction detail = new DetailTransaction();
                detail.TransactionID = head.TransactionID;
                detail.ProductID     = item.ProductID.Value;
                detail.Quantity      = item.Quantity.Value;
                db.DetailTransactions.Add(detail);

                decreaseStock(item.ProductID.Value, item.Quantity.Value);

                cartRepository.deleteCart(item.ID);
                db.SaveChanges();
            }
            return(true);
        }
示例#3
0
        public static void Create(int productTypeId, String name, int stock, int price)
        {
            Product prk = ProductFactory.CreateProduct(productTypeId, name, stock, price);

            db.Products.Add(prk);
            db.SaveChanges();
        }
示例#4
0
        public static void Create(String productTypeName, String description)
        {
            ProductType prk = ProductTypeFactory.CreateProduct(productTypeName, description);

            db.ProductTypes.Add(prk);
            db.SaveChanges();
        }
示例#5
0
        public static User InsertUser(int roleid, string name, string email, string password, string gender, string status)
        {
            User u = UserFactory.InsertUser(roleid, name, email, password, gender, status);

            db.Users.Add(u);
            db.SaveChanges();
            return(u);
        }
示例#6
0
        public static Product InsertProduct(int producttypeid, string name, int stock, int price)
        {
            Product p = ProductFactory.InsertProduct(producttypeid, name, stock, price);

            db.Products.Add(p);
            db.SaveChanges();
            return(p);
        }
        public static ProductType InsertProductType(string name, string desc)
        {
            ProductType pt = ProductTypeFactory.GetProductType(name, desc);

            db.ProductTypes.Add(pt);
            db.SaveChanges();
            return(pt);
        }
示例#8
0
        public static HeaderTransaction InsertHeaderTransaction(int userId, int paymentTypeId, DateTime date)
        {
            HeaderTransaction ht = TransactionFactory.GetHeaderTransaction(userId, paymentTypeId, date);

            db.HeaderTransactions.Add(ht);
            db.SaveChanges();

            return(ht);
        }
        public static PaymentType InsertPaymentType(string type)
        {
            PaymentType pt = PaymentFactory.GetPaymentType(type);

            db.PaymentTypes.Add(pt);
            db.SaveChanges();

            return(pt);
        }
示例#10
0
        public static User doInsertUser(string email, string name, string pwd, string gender)
        {
            User users = UserFactory.createUser(email, name, pwd, gender);

            db.Users.Add(users);
            db.SaveChanges();

            return(users);
        }
        public static Product InsertProduct(int productType, string name, int price, int stock)
        {
            Product p = ProductFactory.GetProduct(productType, name, price, stock);

            db.Products.Add(p);
            db.SaveChanges();

            return(p);
        }
示例#12
0
        public static Cart InsertCart(int userId, int productId, int qty)
        {
            Cart c = CartFactory.GetCart(userId, productId, qty);

            db.Carts.Add(c);
            db.SaveChanges();

            return(c);
        }
示例#13
0
 public static void AddToCart(Cart carts)
 {
     bool check = db.Carts.Any(x => x.UserID == carts.UserID && x.ProductID == carts.ProductID);
     if(check == true)
     {
         Cart existingCart = db.Carts.Where(x => x.UserID == carts.UserID && x.ProductID == carts.ProductID).FirstOrDefault();
         existingCart.Quantity += carts.Quantity;
         db.SaveChanges(); 
     }
     else
     {
         db.Carts.Add(carts);
         db.SaveChanges();
     }
     
 }
示例#14
0
        public static void doInsertDetailTransaction(int transactionId, int productId, int qty)
        {
            DetailTransaction dt = DetailTransactionFactory.createDetailTransaction(transactionId, productId, qty);

            db.DetailTransactions.Add(dt);
            db.SaveChanges();
        }
        public static int doInsertTransaction(int userId, int paymentTypeId)
        {
            HeaderTransaction ht = HeaderTransactionFactory.CreateHeaderTransaction(userId, paymentTypeId);

            db.HeaderTransactions.Add(ht);
            db.SaveChanges();

            return(ht.ID);
        }
示例#16
0
        public static User RegisterUser(string email, int roleId, string name, string password, string gender, string status)
        {
            User u = UserFactory.RegisterUser(email, roleId, name, password, gender, status);

            db.Users.Add(u);
            db.SaveChanges();
            return(u);
        }
示例#17
0
        public static void doInsertProductToCart(int productId, int userId, int qty)
        {
            Cart carts = CartFactory.createCart(productId, userId, qty);

            db.Carts.Add(carts);
            db.SaveChanges();
        }
示例#18
0
        public void insertProduct(ProductType productType)
        {
            db.ProductTypes.Add(productType);

            db.SaveChanges();
        }
示例#19
0
        public void insertPayment(PaymentType paymentTypes)
        {
            db.PaymentTypes.Add(paymentTypes);

            db.SaveChanges();
        }
示例#20
0
 public void InsertUser(User newUser)
 {
     db.Users.Add(newUser);
     db.SaveChanges();
 }
示例#21
0
 public static void InsertUser(string Name, string Email, string Password, string Gender)
 {
     db.MsUsers.Add(UserFactory.InitUser(2, Name, Email, Password, Gender, "A"));
     db.SaveChanges();
 }
示例#22
0
 public void InsertPaymentType(PaymentType paymentType)
 {
     db.PaymentTypes.Add(paymentType);
     db.SaveChanges();
 }
示例#23
0
        public void insertProduct(Product product)
        {
            db.Products.Add(product);

            db.SaveChanges();
        }
示例#24
0
        public void insertCart(Cart cart)
        {
            db.Carts.Add(cart);

            db.SaveChanges();
        }
示例#25
0
 public void insertUser(User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
 }
示例#26
0
 public static void DeleteProduct(int ID)
 {
     db.MsProducts.Remove(GetOneProduct(ID).ElementAt(0));
     db.SaveChanges();
 }
示例#27
0
 public void InsertDTransaction(DetailTransaction newDT)
 {
     db.DetailTransactions.Add(newDT);
     db.SaveChanges();
 }
示例#28
0
 public void InsertHTransaction(HeaderTransaction newHT)
 {
     db.HeaderTransactions.Add(newHT);
     db.SaveChanges();
 }