예제 #1
0
 public int get_id(FF.ORDER od)
 {
     db.ORDERS.Add(od);
     db.SaveChanges();
     return(od.IDOrders);
 }
예제 #2
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"));
        }