Exemple #1
0
        public ActionResult AddItems(string product_id, int number)
        {
            var ProDuct = new DAO_Product().ViewDetail(product_id);
            var Cart    = Session[CommonConstant.CartSession];
            List <Cart_items> ListCart = new List <Cart_items>();

            if (Cart != null)
            {
                ListCart = (List <Cart_items>)Cart;
            }
            if (ListCart.Any(a => a.product.IDRobot == product_id))
            {
                ListCart.Single(a => a.product.IDRobot == product_id).Quantity++;
            }
            else
            {
                ListCart.Add(new Cart_items()
                {
                    product = new DAO_Product().ViewDetail(product_id), Quantity = number
                });
            }

            Session[CommonConstant.CartSession] = ListCart;

            return(RedirectToAction("Index"));
        }
Exemple #2
0
 public bool checkID(string id)
 {
     return(DAO_Product.checkID(id));
 }
Exemple #3
0
        public ActionResult ThanhToan(string txt_hoten,
                                      string txt_sdt, string txt_email, string txt_diachi,
                                      string txt_ghichu, string txt_tt, string txt_km = "FCL000000")
        {
            int id;
            var cart = (List <Cart_items>)Session[CommonConstant.CartSession];

            FF.ORDER od = new FF.ORDER();

            try
            {
                foreach (var item in cart)
                {
                    tien   = (int)item.product.Price * item.Quantity;
                    count += 1;
                }

                // long tong = tien * id.Value;

                od.NameCustomer  = txt_hoten;
                od.Phone         = txt_sdt;
                od.ADDRESS       = txt_diachi;
                od.Email         = txt_email;
                od.NumberProduct = count;
                od.IDPromotion   = txt_km;
                od.PriceTotal    = tien;
                od.DATE          = DateTime.Now;
                od.Payment       = txt_tt;
                od.Note          = txt_ghichu;
                od.State         = 1;
                od.Verify        = false;
                id = dc.get_id(od);
                string url = "http://localhost:51852/USER/gio-hang/xac-nhan?ID=" + id;
                dc.sendmail("Xác nhận đơn hàng", url, od.Email);
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            try
            {
                foreach (var item in cart)
                {
                    FF.DETAIL_ORDERS d_od = new FF.DETAIL_ORDERS();
                    d_od.IDOrders = id;
                    d_od.IDRobot  = item.product.IDRobot;
                    d_od.Number   = item.Quantity;
                    d_od.Price    = item.product.Price;
                    db.DETAIL_ORDERS.Add(d_od);
                    db.SaveChanges();

                    DAO_Product dp = new DAO_Product();
                    var         sp = db.PRODUCTs.SingleOrDefault(x => x.IDRobot == d_od.IDRobot);
                    sp.Number = sp.Number - item.Quantity;
                    db.SaveChanges();
                }
            }
            catch (Exception ex) { throw; }
            Session[CommonConstant.CartSession] = null;

            return(RedirectToAction("Index", "Home"));
        }
Exemple #4
0
 public bool deleteProduct(string id)
 {
     return(DAO_Product.delete(id));
 }
Exemple #5
0
 public bool updateQuantityPro(int quantity, string IDpro)
 {
     return(DAO_Product.updateQuantityPro(quantity, IDpro));
 }
Exemple #6
0
 public bool updateProduct(DTO_Product pro)
 {
     return(DAO_Product.updateProduct(pro));
 }
Exemple #7
0
 public bool addProduct(DTO_Product pro)
 {
     return(DAO_Product.addProduct(pro));
 }
Exemple #8
0
 public DataTable loadProByType(string proType)
 {
     return(DAO_Product.loadProByType(proType));
 }
Exemple #9
0
 public DataTable loadProByName(string proName)
 {
     return(DAO_Product.loadProByName(proName));
 }
Exemple #10
0
 public DataTable loadProduct()
 {
     return(DAO_Product.loadProduct());
 }