Пример #1
0
        //Đặt hàng
        public async Task <IActionResult> DatHang([Bind("TenKhachHang,SoDienThoai,Email,DiaChi")] DonHang donHang)
        {
            //DonHang dh = new DonHang { TenKhachHang = donHang.TenKhachHang, SoDienThoai = donHang.SoDienThoai, Email = donHang.Email, DiaChi = donHang.DiaChi, TongTien = 1111 };
            //_context.DonHang.Add(dh);
            if (ModelState.IsValid)
            {
                var cart     = HttpContext.Session.GetSession <List <SanPhamGioHang> >(GioHangSession);
                int?TongTien = 0;
                foreach (var tt in cart)
                {
                    TongTien = TongTien + tt.TongTien;
                }
                donHang.TongTien = TongTien;
                _context.Add(donHang);
                await _context.SaveChangesAsync();

                var dh = (from d in _context.DonHang
                          orderby d.ID descending
                          select d).FirstOrDefault();

                foreach (var sp in cart)
                {
                    ChiDietDonHang ctdh = new ChiDietDonHang {
                        SanPhamID = sp.idSP, DonHangID = dh.ID, Gia = sp.Gia, SoLuong = sp.SoLuong, TongTien = sp.TongTien
                    };
                    _context.ChiDietDonHang.Add(ctdh);
                }
                await _context.SaveChangesAsync();

                HttpContext.Session.SetSession(GioHangSession, null);
                HttpContext.Response.Cookies.SetKookies(GioHangSession, null);
                return(RedirectToAction("GioHang"));
            }
            return(RedirectToAction("GioHang"));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("ID,HoTen,Email,SoDienThoai,NoiDung")] BinhLuan binhLuan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(binhLuan);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(binhLuan));
        }
        public async Task <IActionResult> Create([Bind("ID,SanPhamID,DonHangID,Gia,SoLuong,TongTien")] ChiDietDonHang chiDietDonHang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(chiDietDonHang);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(chiDietDonHang));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("ID,TenLoaiSPCoDau,TenLoaiSPKhongDau")] LoaiSanPham loaiSanPham)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loaiSanPham);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(loaiSanPham));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("ID,TenNSXCoDau,TenNSXKhongDau")] NhaSanXuat nhaSanXuat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nhaSanXuat);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(nhaSanXuat));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("ID,TieuDeKhuyenMai,HinhAnh,NoiDung")] KhuyenMai khuyenMai)
        {
            if (ModelState.IsValid)
            {
                _context.Add(khuyenMai);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(khuyenMai));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("ID,HoTenKhachHang,SoDienThoai,DiaChi")] KhachHang khachHang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(khachHang);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(khachHang));
        }
Пример #8
0
        public async Task <IActionResult> BanHang([Bind("ID,sanPhamID,khachHangID,maBaoHanh")] SanPhamBan SanPhamBan, string TenSP)
        {
            if (ModelState.IsValid)
            {
                var ngayTao = DateTime.Now;
                SanPhamBan.ngayBan = ngayTao;
                _context.Add(SanPhamBan);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            var khachhang = (from kh in _context.KhachHang
                             where kh.ID == SanPhamBan.khachHangID
                             select kh).FirstOrDefault();

            if (khachhang != null)
            {
                ViewBag.tenKH  = khachhang.HoTenKhachHang;
                ViewBag.soDT   = khachhang.SoDienThoai;
                ViewBag.diaChi = khachhang.DiaChi;
            }
            ViewBag.tenSP     = TenSP;
            ViewBag.sanPhamID = SanPhamBan.sanPhamID;
            var dsLoaiSanPham = from lsp in _context.LoaiSanPham
                                select lsp;
            var loaiSanPhamDauTien = await(from lsp in dsLoaiSanPham
                                           select lsp).FirstOrDefaultAsync();
            var dsSanPhamTheoLoai = from sp in _context.SanPham
                                    where sp.LoaiSanPham == loaiSanPhamDauTien.ID
                                    select sp;

            ViewBag.dsLoaiSanPham = await dsLoaiSanPham.ToListAsync();

            ViewBag.dsSanPhamTheoLoai = await dsSanPhamTheoLoai.ToListAsync();

            return(View(SanPhamBan));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("ID,TenKhachHang,SoDienThoai,Email,DiaChi,TongTien")] DonHang donHang)
        {
            if (ModelState.IsValid)
            {
                _context.Add(donHang);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(donHang));
        }