public async Task <ActionResult> DatHang(HoaDonOutput hoaDon)
        {
            var gioHang = Session["GioHang"] as GioHangModel;

            if (gioHang == null || gioHang.TongSanPham == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            try
            {
                string urlHoaDon        = "hoa-don/them-moi";
                string urlHoaDonChiTiet = "hoa-don-chi-tiet/them-moi";
                hoaDon.NgayDatHang = DateTime.Now;
                hoaDon.TongTien    = gioHang.TongTriGia;
                HoaDonInput resultHoaDon = await ApiHelper <HoaDonInput> .RunPostAsync(urlHoaDon, hoaDon);

                foreach (var item in gioHang.DanhSach)
                {
                    HoaDonChiTietInput ct = new HoaDonChiTietInput();
                    ct.HoaDonID  = hoaDon.ID;
                    ct.HangHoaID = item.HangHoa.ID;
                    ct.SoLuong   = item.SoLuong;
                    ct.DonGia    = item.HangHoa.GiaBan;
                    ct.ThanhTien = item.HangHoa.GiaBan * item.SoLuong;
                    HoaDonChiTietInput resultHoaDonChiTiet = await ApiHelper <HoaDonChiTietInput> .RunPostAsync(urlHoaDonChiTiet, ct);
                }
                gioHang.XoaTatCa();
                return(View("DatHangThanhCong", hoaDon));
            }
            catch (Exception ex)
            {
                TempData["LoiDatHang"] = "Đặt hàng không thành công. <br>" + ex.Message;
                return(RedirectToAction("Index"));
            }
        }
Exemple #2
0
 public frmView()
 {
     InitializeComponent();
     hoaDonOutput = new HoaDonOutput();
 }