public async Task <IActionResult> TaoLichChieu(LichChieuInsertVM lichChieuInsert) { var result = await _quanLyDatVeRespository.TaoLichChieu(lichChieuInsert); return(Ok(result)); }
public async Task <object> TaoLichChieu(LichChieuInsertVM lichChieuInsert) { var connection = new SqlConnection(connectionString); if (connection.State == ConnectionState.Closed) { connection.Open(); } Phim phim = connection.QuerySingleOrDefault <Phim>("SELECT * FROM [dbo].[PHIM] WHERE MaPhim = " + lichChieuInsert.MaPhim, commandType: CommandType.Text); if (phim == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã phim không hợp lệ!")); } LichChieu lichModel = new LichChieu(); //DateTime temp; //try //{ // if (DateTime.TryParse(lichChieuInsert.NgayChieuGioChieu, out temp)) // { // lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lichChieuInsert.NgayChieuGioChieu); // } // else // { // return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !"); // } //} //catch (Exception ex) //{ // return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !"); //} lichModel.NgayChieuGioChieu = lichChieuInsert.NgayChieuGioChieu; Rap kiemTraRap = connection.QuerySingleOrDefault <Rap>("SELECT * FROM [dbo].[RAP] WHERE MaRap = " + lichChieuInsert.MaRap, commandType: CommandType.Text); if (kiemTraRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !")); } CumRap kiemTraCumRap = connection.QuerySingleOrDefault <CumRap>("SELECT * FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + kiemTraRap.MaCumRap + "'", commandType: CommandType.Text); if (kiemTraCumRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã cụm rạp không tồn tại !")); } HeThongRap kiemTraHeThongRap = connection.QuerySingleOrDefault <HeThongRap>("SELECT * FROM [dbo].[HETHONGRAP] WHERE MaHeThongRap = '" + kiemTraCumRap.MaHeThongRap + "'", commandType: CommandType.Text); if (kiemTraHeThongRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã hệ thống rạp không tồn tại !")); } var listLichChieu = connection.Query <LichChieu>("SELECT * FROM [dbo].[View_LICH_CHIEU_COMMON]", commandType: CommandType.Text); var kiemTraLichChieu = listLichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == phim.MaPhim && n.MaCumRap == kiemTraCumRap.MaCumRap && n.MaHeThongRap == kiemTraHeThongRap.MaHeThongRap && n.MaRap == lichChieuInsert.MaRap); //Trường hợp thời gian bắt đầu + thời lượng phim int count = 0; DateTime tgBDInsert = lichChieuInsert.NgayChieuGioChieu; DateTime tgKTInsert = lichChieuInsert.NgayChieuGioChieu.AddMinutes(phim.ThoiLuong); foreach (LichChieu lc in listLichChieu) { DateTime thoiGianBatDau = lc.NgayChieuGioChieu; DateTime thoiGianKetThuc = lc.NgayChieuGioChieu.AddMinutes(phim.ThoiLuong); if (lichChieuInsert.MaRap == lc.MaRap) { if ((tgBDInsert == thoiGianBatDau && tgKTInsert == thoiGianKetThuc) || (tgBDInsert > thoiGianBatDau && tgBDInsert < thoiGianKetThuc) || (tgKTInsert > thoiGianBatDau && tgKTInsert < thoiGianKetThuc) || tgBDInsert == thoiGianKetThuc || tgKTInsert == thoiGianBatDau) { count = count + 1; } } } if (count > 0) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng !")); } //if (lichChieuInsert.GiaVe > 200000 || lichChieuInsert.GiaVe <= 45000) //{ // return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Giá từ 45.000 - 200.000"); //} //Lấy mã rạp ngẫu nhiên không có trong lst đó var param = new DynamicParameters(); param.Add("@MARAP", lichChieuInsert.MaRap); param.Add("@MAPHIM", lichChieuInsert.MaPhim); param.Add("@NGAYCHIEUGIOCHIEU", lichModel.NgayChieuGioChieu); param.Add("@GIAVE", lichChieuInsert.GiaVe); param.Add("@GIAMGIA", lichChieuInsert.GiamGia); await connection.QueryAsync("LICH_CHIEU_INSERT", param, commandType : CommandType.StoredProcedure); return("Thêm lịch chiếu thành công !"); //return tgKTInsert; }
public async Task <object> TaoLichChieu(LichChieuInsertVM lichChieuInsert) { var connection = new SqlConnection(connectionString); if (connection.State == ConnectionState.Closed) { connection.Open(); } Phim phim = connection.QuerySingleOrDefault <Phim>("SELECT * FROM [dbo].[PHIM] WHERE MaPhim = " + lichChieuInsert.MaPhim, commandType: CommandType.Text); if (phim == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã phim không hợp lệ!")); } LichChieu lichModel = new LichChieu(); //DateTime temp; //try //{ // if (DateTime.TryParse(lichChieuInsert.NgayChieuGioChieu, out temp)) // { // lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lichChieuInsert.NgayChieuGioChieu); // } // else // { // return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !"); // } //} //catch (Exception ex) //{ // return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !"); //} lichModel.NgayChieuGioChieu = lichChieuInsert.NgayChieuGioChieu; Rap kiemTraRap = connection.QuerySingleOrDefault <Rap>("SELECT * FROM [dbo].[RAP] WHERE MaRap = " + lichChieuInsert.MaRap, commandType: CommandType.Text); if (kiemTraRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !")); } CumRap kiemTraCumRap = connection.QuerySingleOrDefault <CumRap>("SELECT * FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + kiemTraRap.MaCumRap + "'", commandType: CommandType.Text); if (kiemTraCumRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã cụm rạp không tồn tại !")); } HeThongRap kiemTraHeThongRap = connection.QuerySingleOrDefault <HeThongRap>("SELECT * FROM [dbo].[HETHONGRAP] WHERE MaHeThongRap = '" + kiemTraCumRap.MaHeThongRap + "'", commandType: CommandType.Text); if (kiemTraHeThongRap == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã hệ thống rạp không tồn tại !")); } var listLichChieu = connection.Query <LichChieu>("SELECT * FROM [dbo].[LICHCHIEU]", commandType: CommandType.Text); var kiemTraLichChieu = listLichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == phim.MaPhim && n.MaCumRap == kiemTraCumRap.MaCumRap && n.MaHeThongRap == kiemTraHeThongRap.MaHeThongRap && n.MaRap == lichChieuInsert.MaRap); if (kiemTraLichChieu.Count() > 0) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng !")); } if (lichChieuInsert.GiaVe > 200000 || lichChieuInsert.GiaVe < 75000) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000")); } //Lấy mã rạp ngẫu nhiên không có trong lst đó var param = new DynamicParameters(); param.Add("@MARAP", lichChieuInsert.MaRap); param.Add("@MAPHIM", lichChieuInsert.MaPhim); param.Add("@NGAYCHIEUGIOCHIEU", lichModel.NgayChieuGioChieu); param.Add("@GIAVE", lichChieuInsert.GiaVe); param.Add("@MAHETHONGRAP", kiemTraHeThongRap.MaHeThongRap); param.Add("@MACUMRAP", kiemTraCumRap.MaCumRap); await connection.QueryAsync("LICH_CHIEU_INSERT", param, commandType : CommandType.StoredProcedure); return("Thêm lịch chiếu thành công !"); //return lichModel.NgayChieuGioChieu.Date; }