public async Task <ResponseEntity> ThongTinTaiKhoan()
        {
            var       accessToken = Request.Headers[HeaderNames.Authorization];
            userToken tttk        = commonService.getUserByToken(accessToken).Result;

            if (tttk == null)
            {
                return(new ResponseEntity(StatusCodeConstants.AUTHORIZATION, "Token đã hết hạn bạn hãy đăng nhập lại!", MessageConstant.MESSAGE_ERROR_401));
            }

            NguoiDung tt = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == tttk.taiKhoan);

            if (tt == null)
            {
                // I wish to return an error response how can i do that?
                //var response = await tbl.TBLoi(ThongBaoLoi.Loi400, "Tài khoản không hợp lệ!");
                //return response;
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Tài khoản không hợp lệ!", MessageConstant.BAD_REQUEST));
            }
            IEnumerable <DatVe>  lstDatVe         = db.DatVe.Where(n => n.TaiKhoanNguoiDung == tttk.taiKhoan).ToList();
            List <ThongTinDatVe> lstThongTinDatVe = new List <ThongTinDatVe>();

            if (lstDatVe.Count() != 0)
            {
                foreach (var item in lstDatVe.GroupBy(n => n.MaLichChieu))
                {
                    ThongTinDatVe ttdv = new ThongTinDatVe();
                    ttdv.MaVe = item.First().MaVe;
                    foreach (var ghe in item)
                    {
                        Ghe         gheNavigation = ghe.MaGheNavigation;
                        Rap         rap           = ghe.MaGheNavigation.MaRapNavigation;
                        CumRap      cumRap        = rap.MaCumRapNavigation;
                        HeThongRap  heThongRap    = cumRap.MaHeThongRapNavigation;
                        ThongTinGhe ttg           = new ThongTinGhe()
                        {
                            MaCumRap = rap.TenRap, TenCumRap = rap.TenRap, MaGhe = ghe.MaGhe, TenGhe = gheNavigation.TenGhe, MaRap = gheNavigation.MaRap, TenRap = rap.TenRap, MaHeThongRap = heThongRap.MaHeThongRap, TenHeThongRap = cumRap.TenCumRap
                        };
                        ttdv.DanhSachGhe.Add(ttg);
                    }
                    ttdv.NgayDat       = item.First().NgayDat.Value;
                    ttdv.HinhAnh       = DomainImage + item.First().MaLichChieuNavigation.MaPhimNavigation.HinhAnh;
                    ttdv.TenPhim       = item.First().MaLichChieuNavigation.MaPhimNavigation.TenPhim;
                    ttdv.GiaVe         = item.First().GiaVe.Value;
                    ttdv.ThoiLuongPhim = item.First().MaLichChieuNavigation.ThoiLuong.Value;
                    lstThongTinDatVe.Add(ttdv);
                }
            }

            ThongTinTaiKhoanVM ttTK = Mapper.Map <NguoiDung, ThongTinTaiKhoanVM>(tt);

            ttTK.ThongTinDatVe = lstThongTinDatVe;

            return(new ResponseEntity(StatusCodeConstants.OK, ttTK, MessageConstant.MESSAGE_SUCCESS_200));

            //return Ok(ttTK);
        }
        public async Task <ActionResult> ThongTinTaiKhoan(LayThongTinCaNhanVM tttk)
        {
            NguoiDung tt = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == tttk.TaiKhoan);

            if (tt == null)
            {
                // I wish to return an error response how can i do that?
                var response = await tbl.TBLoi(ThongBaoLoi.Loi400, "Tài khoản không hợp lệ!");

                return(response);
            }
            IEnumerable <DatVe>  lstDatVe         = db.DatVe.Where(n => n.TaiKhoanNguoiDung == tttk.TaiKhoan).ToList();
            List <ThongTinDatVe> lstThongTinDatVe = new List <ThongTinDatVe>();

            if (lstDatVe.Count() != 0)
            {
                foreach (var item in lstDatVe.GroupBy(n => n.NgayDat))
                {
                    ThongTinDatVe ttdv = new ThongTinDatVe();
                    ttdv.MaVe = item.First().MaVe;
                    foreach (var ghe in item)
                    {
                        Ghe         gheNavigation = ghe.MaGheNavigation;
                        Rap         rap           = ghe.MaGheNavigation.MaRapNavigation;
                        CumRap      cumRap        = rap.MaCumRapNavigation;
                        HeThongRap  heThongRap    = cumRap.MaHeThongRapNavigation;
                        ThongTinGhe ttg           = new ThongTinGhe()
                        {
                            MaCumRap = rap.TenRap, TenCumRap = rap.TenRap, MaGhe = ghe.MaGhe, TenGhe = gheNavigation.TenGhe, MaRap = gheNavigation.MaRap, TenRap = rap.TenRap, MaHeThongRap = heThongRap.MaHeThongRap, TenHeThongRap = cumRap.TenCumRap
                        };
                        ttdv.DanhSachGhe.Add(ttg);
                    }
                    ttdv.NgayDat       = item.First().NgayDat.Value;
                    ttdv.TenPhim       = item.First().MaLichChieuNavigation.MaPhimNavigation.TenPhim;
                    ttdv.GiaVe         = item.First().GiaVe.Value;
                    ttdv.ThoiLuongPhim = item.First().MaLichChieuNavigation.ThoiLuong.Value;
                    lstThongTinDatVe.Add(ttdv);
                }
            }

            ThongTinTaiKhoanVM ttTK = Mapper.Map <NguoiDung, ThongTinTaiKhoanVM>(tt);

            ttTK.ThongTinDatVe = lstThongTinDatVe;


            return(Ok(ttTK));
        }
        public async Task <object> LayThongTinTaiKhoan(string taiKhoan)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                ThanhVien thanhVien = connection.QuerySingleOrDefault <ThanhVien>("SELECT * FROM dbo.ThanhVien WHERE TaiKhoan = '" + taiKhoan + "'", commandType: CommandType.Text);
                if (thanhVien == null)
                {
                    // I wish to return an error response how can i do that?
                    var response = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi400, "Tài khoản không hợp lệ!");

                    return(response);
                }

                IEnumerable <Ve>     listDatVe         = connection.Query <Ve>("SELECT * FROM dbo.VE WHERE MaThanhVien = ' " + thanhVien.MaThanhVien + "'", commandType: CommandType.Text);
                List <ThongTinDatVe> listThongTinDatVe = new List <ThongTinDatVe>();

                if (listDatVe.Count() != 0)
                {
                    Ghe ghe = new Ghe();
                    foreach (var item in listDatVe.GroupBy(n => new { n.MaThanhToan }))
                    {
                        //, MaGhe = item.MaGhe, TenGhe = ghe.TenGhe, MaRap = ghe.MaRap, TenRap = rap.TenRap,MaHeThongRap = cumRap.MaHeThongRap,TenHeThongRap = connection.QuerySingleOrDefault("SELECT TenHeThongRap FROM dbo.HETHONGRAP WHERE MaHeThongRap = " + cumRap.MaHeThongRap, commandType: CommandType.Text)
                        ThongTinDatVe thongTinDatVe = new ThongTinDatVe();
                        Rap           rap           = new Rap();
                        CumRap        cumRap        = new CumRap();
                        LichChieu     lichChieu     = new LichChieu();

                        thongTinDatVe.MaThanhToan  = item.Key.MaThanhToan;
                        thongTinDatVe.TrangThaiHuy = connection.QuerySingleOrDefault <bool>("SELECT TrangThaiHuy FROM dbo.THANHTOAN WHERE MaThanhToan = " + item.Key.MaThanhToan, commandType: CommandType.Text);

                        foreach (var CTVe in item)
                        {
                            ThongTinGhe thongTinGhe = new ThongTinGhe();
                            lichChieu = connection.QuerySingleOrDefault <LichChieu>("SELECT * FROM dbo.LICHCHIEU WHERE MaLichChieu = " + CTVe.MaLichChieu, commandType: CommandType.Text);
                            //rap = connection.QuerySingleOrDefault<Rap>("SELECT * FROM dbo.RAP WHERE MaRap = " + lichChieu.MaRap, commandType: CommandType.Text);
                            //cumRap = connection.QuerySingleOrDefault<CumRap>("SELECT * FROM dbo.CUMRAP WHERE MaCumRap = '" + rap.MaCumRap + "'", commandType: CommandType.Text);
                            ghe = await connection.QuerySingleOrDefaultAsync <Ghe>("SELECT * FROM dbo.GHE WHERE MaGhe = " + CTVe.MaGhe, commandType : CommandType.Text);

                            thongTinDatVe.MaLichChieu = CTVe.MaLichChieu;
                            thongTinGhe.MaGhe         = ghe.MaGhe;
                            thongTinGhe.TenGhe        = ghe.TenGhe;
                            thongTinGhe.MaVe          = CTVe.MaVe;
                            thongTinGhe.NgayDat       = CTVe.NgayDat.Value;

                            thongTinDatVe.TenPhim           = connection.QuerySingleOrDefault <string>("SELECT TenPhim FROM dbo.Phim WHERE MaPhim = " + lichChieu.MaPhim, commandType: CommandType.Text);
                            thongTinDatVe.GiaVe             = CTVe.GiaVe.Value;
                            thongTinDatVe.NgayChieuGioChieu = lichChieu.NgayChieuGioChieu;
                            thongTinDatVe.MaRap             = lichChieu.MaRap;
                            thongTinDatVe.TenRap            = connection.QuerySingleOrDefault <string>("SELECT TenRap FROM dbo.Rap WHERE MaRap = " + lichChieu.MaRap, commandType: CommandType.Text);
                            thongTinDatVe.MaHeThongRap      = lichChieu.MaHeThongRap;
                            thongTinDatVe.MaCumRap          = lichChieu.MaCumRap;
                            thongTinDatVe.TenCumRap         = connection.QuerySingleOrDefault <string>("SELECT TenCumRap FROM dbo.CumRap WHERE MaCumRap = '" + lichChieu.MaCumRap + "'", commandType: CommandType.Text);
                            thongTinDatVe.DanhSachGhe.Add(thongTinGhe);
                        }
                        listThongTinDatVe.Add(thongTinDatVe);
                        //thongTinDatVe.ThoiLuongPhim = item.MaLichChieuNavigation.ThoiLuong.Value;
                    }
                }


                //ThongTinTaiKhoanVM ttTK = Mapper.Map<NguoiDung, ThongTinTaiKhoanVM>(tt);
                ThongTinTaiKhoanVM thongTinTaiKhoan = new ThongTinTaiKhoanVM();
                thongTinTaiKhoan.MaThanhVien   = thanhVien.MaThanhVien;
                thongTinTaiKhoan.LoaiNguoiDung = await connection.QuerySingleOrDefaultAsync <string>("SELECT TenLoai FROM dbo.LOAITHANHVIEN WHERE MaLoaiThanhVien = " + thanhVien.MaLoaiThanhVien, commandType : CommandType.Text);

                thongTinTaiKhoan.TaiKhoan       = thanhVien.TaiKhoan;
                thongTinTaiKhoan.MatKhau        = thanhVien.MatKhau;
                thongTinTaiKhoan.HoTen          = thanhVien.HoTen;
                thongTinTaiKhoan.Email          = thanhVien.Email;
                thongTinTaiKhoan.SoDT           = thanhVien.SoDienThoai;
                thongTinTaiKhoan.SoLuongVeDaMua = thanhVien.SoLuongVeMua;
                thongTinTaiKhoan.ThongTinDatVe  = listThongTinDatVe;
                return(thongTinTaiKhoan);
            }
        }