public async Task <ActionResult> LayDanhSachPhongVe(LichChieuInsert lich)
        {
            Phim p = db.Phim.SingleOrDefault(n => n.MaPhim == lich.MaPhim);

            if (p == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "MaPhim không hợp lệ"));
            }

            LichChieu lichModel = new LichChieu();

            try
            {
                lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            }
            catch (Exception ex)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
            }
            //DateTime temp;
            //try
            //{

            //    if (DateTime.TryParse(lich.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss!");
            //}

            var ckRap = db.Rap.SingleOrDefault(n => n.MaRap == lich.MaRap);

            if (ckRap == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !"));
            }

            var ckCum = db.CumRap.SingleOrDefault(n => n.MaCumRap == ckRap.MaCumRap);

            if (ckCum == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai cụm rạp!"));
            }
            var ckHeThongRap = db.HeThongRap.SingleOrDefault(n => n.MaHeThongRap == ckCum.MaHeThongRap);

            if (ckHeThongRap == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai hệ thống rạp!"));
            }
            var lichChieu = db.LichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == p.MaPhim && n.MaCumRap == ckCum.MaCumRap && n.MaHeThongRap == ckHeThongRap.MaHeThongRap && n.MaRap == lich.MaRap);

            if (lichChieu.Count() > 0)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng"));
            }

            if (lich.GiaVe > 200000 || lich.GiaVe < 75000)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000"));
            }



            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            lichModel.MaRap        = lich.MaRap;
            lichModel.MaPhim       = lich.MaPhim;
            lichModel.ThoiLuong    = 120;
            lichModel.MaNhom       = p.MaNhom;
            lichModel.MaHeThongRap = ckHeThongRap.MaHeThongRap;
            lichModel.MaCumRap     = ckCum.MaCumRap;
            lichModel.GiaVe        = lich.GiaVe;
            db.LichChieu.Add(lichModel);
            db.SaveChanges();
            return(Ok("Thêm lịch chiếu thành công!"));
        }
        public async Task <ResponseEntity> TaoLichChieu(LichChieuInsert lich)
        {
            Phim p = db.Phim.SingleOrDefault(n => n.MaPhim == lich.MaPhim);

            if (p == null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "MaPhim không hợp lệ", MessageConstant.ERROR));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "MaPhim không hợp lệ");
            }

            LichChieu lichModel = new LichChieu();

            try
            {
                lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !", MessageConstant.ERROR));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
            }
            //DateTime temp;
            //try
            //{

            //    if (DateTime.TryParse(lich.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss!");
            //}

            var ckRap = db.Rap.SingleOrDefault(n => n.MaRap == lich.MaRap);

            if (ckRap == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Mã rạp không tồn tại !", MessageConstant.MESSAGE_ERROR_404));
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !");
            }

            var ckCum = db.CumRap.SingleOrDefault(n => n.MaCumRap == ckRap.MaCumRap);

            if (ckCum == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Chọn sai cụm rạp!", MessageConstant.MESSAGE_ERROR_404));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai cụm rạp!");
            }
            var ckHeThongRap = db.HeThongRap.SingleOrDefault(n => n.MaHeThongRap == ckCum.MaHeThongRap);

            if (ckHeThongRap == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Chọn sai hệ thống rạp!", MessageConstant.MESSAGE_ERROR_404));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai hệ thống rạp!");
            }
            var lichChieu = db.LichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == p.MaPhim && n.MaCumRap == ckCum.MaCumRap && n.MaHeThongRap == ckHeThongRap.MaHeThongRap && n.MaRap == lich.MaRap);

            if (lichChieu.Count() > 0)
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Lịch chiếu đã bị trùng", MessageConstant.BAD_REQUEST));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng");
            }

            if (lich.GiaVe > 200000 || lich.GiaVe < 75000)
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Giá từ 75.000 - 200.000", MessageConstant.BAD_REQUEST));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000");
            }



            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            lichModel.MaRap        = lich.MaRap;
            lichModel.MaPhim       = lich.MaPhim;
            lichModel.ThoiLuong    = 120;
            lichModel.MaNhom       = p.MaNhom;
            lichModel.MaHeThongRap = ckHeThongRap.MaHeThongRap;
            lichModel.MaCumRap     = ckCum.MaCumRap;
            lichModel.GiaVe        = lich.GiaVe;
            db.LichChieu.Add(lichModel);
            db.SaveChanges();
            return(new ResponseEntity(StatusCodeConstants.OK, "Thêm lịch chiếu thành công!", MessageConstant.MESSAGE_SUCCESS_200));

            //return Ok("Thêm lịch chiếu thành công!");
        }