コード例 #1
0
 public bool Insert(tbl_ChiTietHoaDon detail)
 {
     try
     {
         db.tbl_ChiTietHoaDon.Add(detail);
         db.SaveChanges();
         return(true);
     }catch
     {
         return(false);
     }
 }
コード例 #2
0
        public JsonResult JSPayCheck(FormCollection form)
        {
            JsonResult js        = new JsonResult();
            bool       isNumeric = true;
            string     finame    = form["finame"];
            string     miname    = form["miname"];
            string     laname    = form["laname"];
            string     add1      = form["add1"];
            string     add2      = form["add2"];
            string     country   = form["country"];
            string     state     = form["state"];
            string     city      = form["city"];
            string     phone     = form["phone"];

            if (string.IsNullOrEmpty(finame) || string.IsNullOrEmpty(laname) || string.IsNullOrEmpty(add1) || string.IsNullOrEmpty(country) || string.IsNullOrEmpty(state) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(phone))
            {
                js.Data = new
                {
                    status = "EMPTY"
                };
            }
            else
            {
                foreach (char c in phone)
                {
                    if (!Char.IsNumber(c))
                    {
                        isNumeric = false;
                        break;
                    }
                }
                if (isNumeric == false)
                {
                    js.Data = new
                    {
                        status = "ERRPHONE"
                    };
                }
                else
                {
                    if (phone.Length != 10)
                    {
                        js.Data = new
                        {
                            status = "ERRPHONE"
                        };
                    }
                    else
                    {
                        string address = add1 + " " + add2 + " " + state + " " + city + " " + country;
                        string name    = finame + " " + miname + " " + laname;
                        if (Session["Cart"] == null)
                        {
                            Response.Redirect("/Product/Product/1");
                        }
                        Code            code    = new Code();
                        List <CartItem> giohang = Session["Cart"] as List <CartItem>;

                        if (giohang.Count() == 0)
                        {
                            Response.Redirect("/Product/Product/1");
                        }
                        bool status = true;
                        foreach (CartItem item in giohang)
                        {
                            if (item.SoLuong > code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong)
                            {
                                status       = false;
                                item.SoLuong = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong;
                            }
                        }
                        if (status == true)
                        {
                            if (Session["User"] == null)
                            {
                                Response.Redirect("/Login/Login");
                            }
                            else
                            {
                                tbl_KhachHang u  = (tbl_KhachHang)Session["User"];
                                tbl_HoaDon    hd = new tbl_HoaDon();
                                hd.MaKhachHang        = u.MaKhachHang;
                                hd.NgayLap            = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                                hd.MaTrangThaiDonHang = 2;
                                hd.DiaChiNhan         = address;
                                hd.NguoiNhan          = name;
                                hd.SDT                = int.Parse(phone);
                                hd.TongTien           = giohang.Sum(m => m.ThanhTien);
                                hd.TrangThaiThanhToan = 2;
                                code.AddObject(hd);
                                foreach (CartItem item in giohang)
                                {
                                    tbl_ChiTietHoaDon cthd = new tbl_ChiTietHoaDon();
                                    cthd.MaHoaDon  = hd.MaHoaDon;
                                    cthd.MaThietBi = item.SanPhamID;
                                    cthd.SoLuong   = item.SoLuong;
                                    cthd.ThanhTien = item.ThanhTien;
                                    cthd.DonGia    = item.DonGia;
                                    code.AddObject(cthd);
                                    code.Save();
                                    tbl_ThietBi tb = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID);
                                    tb.SoLuong = tb.SoLuong - item.SoLuong;
                                    code.Save();
                                }
                                code.Save();
                                Session.Remove("Cart");
                                js.Data = new
                                {
                                    status = "OK"
                                };
                            }
                        }
                        else
                        {
                            js.Data = new
                            {
                                status = "ER"
                            };
                        }
                    }
                }
            }
            return(Json(js, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Payment(string sTenNguoiNhan, string sEmail, string sSoDienThoai, string sDiaChi, string FormOfPayment, string sBankCode, FormCollection formcollection)
        {
            var    order        = new tbl_HoaDon();
            var    userSession  = (UserLogin)Session[Common.CommonConstants.USER_SESSION];
            var    TenTinhThanh = formcollection["hdnTenTinhThanh"];
            var    TenQuanHuyen = formcollection["hdnTenQuanHuyen"];
            string diachi       = TenQuanHuyen + ", " + TenTinhThanh;

            if (userSession != null)
            {
                order.IDKhachHang = userSession.UserID;
            }
            order.dNgayTao        = DateTime.Now;
            order.sTenNguoiNhan   = sTenNguoiNhan;
            order.sEmailNguoiNhan = sEmail;
            order.sSDTnguoiNhan   = sSoDienThoai;
            order.sDiaChi         = sDiaChi + ", " + TenQuanHuyen + ", " + TenTinhThanh;
            order.sFormOfPayment  = FormOfPayment;
            order.iMaTrangThai    = 1;

            try
            {
                var     id        = new HoaDonDAO().Insert(order);
                var     cart      = (List <GioHangItems>)Session[CartSession];
                var     detailDao = new Model.DAO.ChiTietHoaDonDAO();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var divsp       = new SanPhamDAO();
                    var orderDetail = new tbl_ChiTietHoaDon();
                    orderDetail.IDSanPham = item.SanPham.ID;
                    orderDetail.IDHoaDon  = id;
                    orderDetail.sGhiChu   = item.sGhiChu;
                    orderDetail.iSoLuong  = item.SoLuong;
                    if (item.SanPham.dGiaKhuyenMai != null && item.SanPham.dGiaKhuyenMai != 0)
                    {
                        orderDetail.dDonGia = item.SanPham.dGiaKhuyenMai;
                    }
                    else
                    {
                        orderDetail.dDonGia = item.SanPham.dGiaBan;
                    }
                    detailDao.Insert(orderDetail);
                    if (item.SanPham.dGiaKhuyenMai != null && item.SanPham.dGiaKhuyenMai != 0)
                    {
                        total += (item.SanPham.dGiaKhuyenMai.GetValueOrDefault(0) * item.SoLuong);
                    }
                    else
                    {
                        total += (item.SanPham.dGiaBan.GetValueOrDefault(0) * item.SoLuong);
                    }
                    divsp.divSanPham(item.SanPham.ID, item.SoLuong);
                    //ViewBag.Total = total;
                }
                if (!FormOfPayment.Equals("COD"))
                {
                    RequestInfo info = new RequestInfo();
                    info.Merchant_id       = MerchantID;
                    info.Merchant_password = MerchantPassword;
                    info.Receiver_email    = MerchantEmail;

                    info.cur_code  = "vnd";
                    info.bank_code = sBankCode;

                    info.Order_code        = id.ToString();
                    info.Total_amount      = total.ToString();
                    info.fee_shipping      = "0";
                    info.Discount_amount   = "0";
                    info.order_description = "Thanh toán đơn hàng Myhands Store";
                    info.return_url        = currentLink + "/hoan-thanh";
                    info.cancel_url        = currentLink + "/loi-thanh-toan";

                    info.Buyer_fullname = sTenNguoiNhan;
                    info.Buyer_email    = sEmail;
                    info.Buyer_mobile   = sSoDienThoai;

                    APICheckoutV3 objNLChecout = new APICheckoutV3();
                    ResponseInfo  result       = objNLChecout.GetUrlCheckout(info, FormOfPayment);

                    if (result.Error_code == "00")
                    {
                        Response.Redirect(result.Checkout_url);
                        //return Redirect("/hoan-thanh");
                    }
                    else
                    {
                        return(Redirect("/loi-thanh-toan"));
                    }
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/Templates/MailForm.html"));

                content = content.Replace("{{sTenNguoiNhan}}", sTenNguoiNhan);
                content = content.Replace("{{sSoDienThoai}}", sSoDienThoai);
                content = content.Replace("{{sEmail}}", sEmail);
                content = content.Replace("{{sDiaChi}}", sDiaChi + diachi);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new Mail().SendMail(sEmail, "Đơn hàng mới từ MyHandsStore", content);
                new Mail().SendMail(toEmail, "Đơn hàng mới từ MyHandsStore", content);
            }
            catch (Exception ex)
            {
                string script = "<script>alert('" + ex.Message + "');</script>";

                return(Redirect("/loi-thanh-toan"));
            }
            Session[CartSession] = null;
            return(Redirect("/hoan-thanh"));
        }