Example #1
0
        public IActionResult BinhLuan(string binhluan, int mahh)
        {
            if (HttpContext.Session.Get <KhachHang>("Username") != null)
            {
                BinhLuanSp binhluanSP = new BinhLuanSp
                {
                    NoiDung = binhluan,
                    MaKh    = HttpContext.Session.Get <KhachHang>("Username").MaKh,
                    MaHh    = mahh,
                    NgayBl  = DateTime.Now
                };
                HangHoa hanghoa = db.HangHoa.SingleOrDefault(p => p.MaHh == mahh);

                db.BinhLuanSp.Add(binhluanSP);
                db.SaveChanges();

                return(View("ChiTiet", hanghoa));
            }
            else
            {
                ViewBag.UserExit = false;
                HangHoa hanghoa = db.HangHoa.SingleOrDefault(p => p.MaHh == mahh);
                return(View("ChiTiet", hanghoa));
            }
        }
        public IActionResult ChangeStatus(int id)
        {
            var hd = _context.HoaDon.Find(id);

            if (hd != null)
            {
                if (hd.MaTrangThai == 0)
                {
                    hd.MaTrangThai = 1;
                    _context.SaveChanges();
                }
                else if (hd.MaTrangThai == 1)
                {
                    hd.MaTrangThai = 0;
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult Index(string phanhoikh, string submit)
        {
            if (HttpContext.Session.Get <KhachHang>("Username") != null)
            {
                LienHe lh = new LienHe
                {
                    MaKh    = HttpContext.Session.Get <KhachHang>("Username").MaKh,
                    CauHoi  = phanhoikh,
                    NgayGui = DateTime.Now
                };
                db.LienHe.Add(lh);
                db.SaveChanges();
                ViewBag.Exit = true;
            }
            else
            {
                ViewBag.Exit = false;
            }

            return(View());
        }
Example #4
0
        public IActionResult Register(string tendangnhap, string matkhau, string hoten, string gioitinh, string diachi, string dienthoai, string email)
        {
            KhachHang username_kh = db.KhachHang.SingleOrDefault(p => p.TaiKhoan == tendangnhap);
            KhachHang email_kh    = db.KhachHang.SingleOrDefault(p => p.Email == email);

            if (username_kh != null)
            {
                ViewBag.AccExit = false;
                if (email_kh != null)
                {
                    ViewBag.EmailExit = false;
                }
                return(View("Index"));
            }
            else if (email_kh != null)
            {
                ViewBag.EmailExit = false;
                return(View("Index"));
            }
            else
            {
                KhachHang new_khach_hang = new KhachHang
                {
                    TaiKhoan  = tendangnhap,
                    MatKhau   = Encryptor.MD5Hash(matkhau),
                    HoTen     = hoten,
                    GioiTinh  = gioitinh,
                    DiaChi    = diachi,
                    DienThoai = dienthoai,
                    Email     = email
                };
                db.KhachHang.Add(new_khach_hang);
                db.SaveChanges();

                //ViewBag.RegisterSuccess = true;
                return(RedirectToAction("Index", "Login"));
            }
        }
        public IActionResult HoaDonTV(string ghichu)
        {
            KhachHang kh = HttpContext.Session.Get <KhachHang>("Username");
            HoaDon    hd = new HoaDon
            {
                MaKh                = kh.MaKh,
                HoTen               = kh.HoTen,
                DiaChi              = kh.DiaChi,
                GhiChu              = ghichu,
                NgayDat             = DateTime.Now,
                MaTrangThai         = 0,
                PhuongThucThanhToan = 0,
                TinhTrangThanhToan  = 0,
                PhiVanChuyen        = 0
            };

            db.HoaDon.Add(hd);
            double tongtien   = 0;
            double tonghoadon = 0;

            foreach (var i in Carts)
            {
                tongtien = tongtien + i.ThanhTien;
                HangHoa hh = db.HangHoa.SingleOrDefault(p => p.MaHh == i.MaHh);

                ChiTietHd cthd = new ChiTietHd
                {
                    MaHd    = hd.MaHd,
                    MaHh    = i.MaHh,
                    DonGia  = hh.DonGia,
                    GiamGia = hh.GiamGia,
                    SoLuong = i.SoLuong
                };
                db.ChiTietHd.Add(cthd);
                db.SaveChanges();


                if (hh.SoLuong >= cthd.SoLuong)
                {
                    hh.SoLuong = hh.SoLuong - cthd.SoLuong;
                }
                else
                {
                    HangHoa hanghoa = db.HangHoa.SingleOrDefault(p => p.MaHh == cthd.MaHh);
                    string  hethang = "Mặt hàng " + hanghoa.TenHh + " Chỉ còn : " + hh.SoLuong + " sản phẩm";
                    HttpContext.Session.Set("HetHang", hethang);
                    db.ChiTietHd.Remove(cthd);
                    db.HoaDon.Remove(hd);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            tonghoadon      = tongtien + 0;
            hd.TongTienHang = tongtien;
            hd.TongThucThu  = tonghoadon;
            db.SaveChanges();
            HttpContext.Session.Set <string>("OrderSuccess", "Đơn hàng của bạn đã được đặt thành công.");
            //ViewBag.OrderSuccess = true;
            HttpContext.Session.Remove("GioHang");


            return(RedirectToAction("Index"));
        }
Example #6
0
        public async Task <IActionResult> Checkout()
        {
            //SandboxEnvironment(clientId, clientSerect)
            var environment = new SandboxEnvironment("AW0XNlAAqYLVMTbaBJVpAz_DFp2TrHMQgAmZ5WXDPt9Hoyt4Jrrb1ZpdvpI70CIqetpb3yHYV23Z9vsS", "EKqZen_z_GAihIxYgBDxy8mvu2Cola9Pdq09v38SSWn05gaAXgmlPy7H-UK7bhL9tW8CSCrVYM5A7WWv");
            var client      = new PayPalHttpClient(environment);

            //Đọc thông tin đơn hàng từ Session
            var itemList = new ItemList()
            {
                Items = new List <Item>()
            };

            var tongTien = Cart.Sum(p => p.ThanhTien);

            foreach (var item in Cart)
            {
                itemList.Items.Add(new Item()
                {
                    Name     = item.TenHh,
                    Currency = "USD",
                    Price    = item.GiaBan.ToString(),
                    Quantity = item.SoLuong.ToString(),
                    Sku      = "sku",
                    Tax      = "0"
                });
            }

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = tongTien.ToString(),
                            Currency = "USD",
                            Details  = new AmountDetails
                            {
                                Tax      = "0",
                                Shipping = "0",
                                Subtotal = tongTien.ToString()
                            }
                        },
                        ItemList      = itemList,
                        Description   = "Shop online technology products",
                        InvoiceNumber = DateTime.Now.Ticks.ToString()
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://techworld.azurewebsites.net/Paypal/Fail",
                    ReturnUrl = "https://techworld.azurewebsites.net/Paypal/Success"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            KhachHang kh = HttpContext.Session.Get <KhachHang>("Username");
            HoaDon    hd = new HoaDon
            {
                MaKh    = kh.MaKh,
                HoTen   = kh.HoTen,
                DiaChi  = kh.DiaChi,
                NgayDat = DateTime.Now,
                // GhiChu = ghichu,
                SdtNguoinhan        = kh.DienThoai,
                MaTrangThai         = 0,
                PhuongThucThanhToan = 1,
                TinhTrangThanhToan  = 1,
                PhiVanChuyen        = 0
            };

            db.HoaDon.Add(hd);
            double tongtien   = 0;
            double tonghoadon = 0;

            foreach (var i in Cart)
            {
                tongtien = tongtien + i.ThanhTien;
                HangHoa hh = db.HangHoa.SingleOrDefault(p => p.MaHh == i.MaHh);

                ChiTietHd cthd = new ChiTietHd
                {
                    MaHd    = hd.MaHd,
                    MaHh    = i.MaHh,
                    DonGia  = hh.DonGia,
                    GiamGia = hh.GiamGia,
                    SoLuong = i.SoLuong
                };
                db.ChiTietHd.Add(cthd);
                db.SaveChanges();
            }
            tonghoadon      = tongtien + 0;
            hd.TongTienHang = tongtien;
            hd.TongThucThu  = tonghoadon;
            db.SaveChanges();
            HttpContext.Session.Remove("GioHang");

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                var    links             = result.Links.GetEnumerator();
                string paypalRedirectUrl = null;
                while (links.MoveNext())
                {
                    LinkDescriptionObject lnk = links.Current;
                    if (lnk.Rel.ToLower().Trim().Equals("approval_url"))
                    {
                        //saving the payapalredirect URL to which user will be redirected for payment
                        paypalRedirectUrl = lnk.Href;
                    }
                }

                return(Redirect(paypalRedirectUrl));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();

                return(RedirectToAction("Fail"));
            }

            //return View();
        }