Exemple #1
0
        public ActionResult DangKy(DangKyViewModel dangKyViewModel)
        {
            TaiKhoan taiKhoan = Dbcontext.TaiKhoan.Where(m => m.TenTaiKhoan == dangKyViewModel.TaiKhoan.TenTaiKhoan).FirstOrDefault();

            if (taiKhoan == null)
            {
                if (ModelState.IsValid)
                {
                    if (dangKyViewModel.TaiKhoan.MatKhau == dangKyViewModel.NhapLaiMatKhau)
                    {
                        TaiKhoan newUser = new TaiKhoan()
                        {
                            TenTaiKhoan = dangKyViewModel.TaiKhoan.TenTaiKhoan,
                            MatKhau     = dangKyViewModel.TaiKhoan.MatKhau,
                            QuyenHan    = Models.Enum.QuyenHan.Member,
                            KhachHang   = new KhachHang()
                            {
                                TenKhachHang = dangKyViewModel.KhachHang.TenKhachHang,
                                DiaChi       = dangKyViewModel.KhachHang.DiaChi,
                                NamSinh      = dangKyViewModel.KhachHang.NamSinh,
                                SoTaiKhoan   = dangKyViewModel.KhachHang.SoTaiKhoan,
                                CMND         = dangKyViewModel.KhachHang.CMND,
                                NganHang     = dangKyViewModel.KhachHang.NganHang,
                                SoDienThoai  = dangKyViewModel.KhachHang.SoDienThoai,
                            }
                        };
                        Dbcontext.TaiKhoan.Add(newUser);
                        Dbcontext.SaveChanges();
                        return(View("Index"));
                    }
                }
            }
            List <string> listNH = new List <string>()
            {
                "TPBank",
                "VietcomBank",
                "ViettinBank",
                "SeABank",
                "VPBank",
                "SacomBank",
                "TechcomBank",
                "BIDV",
                "DongABank"
            };

            SelectList selectList = new SelectList(listNH);

            ViewBag.listNH = selectList;

            return(View());
        }
        public ActionResult DatHang()
        {
            decimal totalMoney = 0;

            try
            {
                KhachHang            khachHang          = Session[UserSession.USER_SESSION] as KhachHang;
                GioHang              gioHang            = Session[CartSession] as GioHang;
                List <ChiTietHoaDon> listChiTietHoaDons = new List <ChiTietHoaDon>();
                foreach (var item in gioHang.DoTrongGioHangs)
                {
                    ChiTietHoaDon chiTietHoaDon = new ChiTietHoaDon()
                    {
                        SoLuong   = item.Quantity,
                        ThanhTien = item.Xe.GiaNhap * item.Quantity,
                        MaXe      = item.Xe.MaXe
                    };
                    listChiTietHoaDons.Add(chiTietHoaDon);
                    totalMoney += chiTietHoaDon.ThanhTien;
                }
                HoaDon hoaDon = new HoaDon()
                {
                    MaKhachHang       = khachHang.MaKhachHang,
                    NgayNhan          = gioHang.NgayThue.Value,
                    NgayTra           = gioHang.NgayTra.Value,
                    HinhThucThanhToan = Models.Enum.HinhThucThanhToan.ThanhToanTrucTiep,
                    TongThanhTien     = totalMoney,
                    ChiTietHoaDon     = listChiTietHoaDons
                };

                context.HoaDon.Add(hoaDon);
                context.SaveChanges();
                Session[CartSession] = null;
            }
            catch
            {
                return(RedirectToAction("ThanhToan"));
            }
            return(RedirectToAction("Index", "Home"));
        }