Ejemplo n.º 1
0
        //Ajax thêm khách hàng
        public IActionResult ThemKhachHang(KhachHang khachHang)
        {
            string khachHangId = "0";

            if (ModelState.IsValid)
            {
                var khachhang = (from kh in _context.KhachHang
                                 where kh.SoDienThoai == khachHang.SoDienThoai
                                 select kh).FirstOrDefault();

                if (khachhang == null)
                {
                    _context.Add(khachHang);
                    _context.SaveChanges();
                    var khachhanghientai = (from kh in _context.KhachHang
                                            orderby kh.ID descending
                                            select kh).FirstOrDefault();
                    khachHangId = Convert.ToString(khachhanghientai.ID);
                }
                else
                {
                    khachHangId = Convert.ToString(khachhang.ID);
                }
            }
            return(Content(khachHangId));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Tao([Bind("ID,HoTen,Email,SoDienThoai,NoiDung")] BinhLuan binhLuan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(binhLuan);
                await _context.SaveChangesAsync();

                return(RedirectToAction("TrangChu", "TrangChu"));
            }
            return(View("ChiTiet", binhLuan));
        }
Ejemplo n.º 3
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"));
        }
        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));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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));
        }