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 void ThemCumRap(CumRap cumRap) { using (var connection = new SqlConnection(connectionString)) { var p = new DynamicParameters(); p.Add("@TENCUMRAP", cumRap.TenCumRap); p.Add("@THONGTIN", cumRap.ThongTin); p.Add("@MAHETHONGRAP", cumRap.MaHeThongRap); connection.Query <CumRap>("CUM_RAP_INSERT", p, commandType: CommandType.StoredProcedure); } }
public async Task <ThongTinCumRapViewModel> LayDanhSachRap(string maCumRap) { using (var connection = new SqlConnection(connectionString)) { CumRap cumRap = connection.QuerySingleOrDefault <CumRap>("SELECT * FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + maCumRap + "'", commandType: CommandType.Text); IEnumerable <Rap> listRap = connection.Query <Rap>("SELECT * FROM [dbo].[RAP] WHERE MaCumRap = '" + maCumRap + "'", commandType: CommandType.Text); List <RapViewModel> DSRap = new List <RapViewModel>(); ThongTinCumRapViewModel cumRapVM = new ThongTinCumRapViewModel(); cumRapVM.MaCumRap = maCumRap; cumRapVM.TenCumRap = cumRap.TenCumRap; cumRapVM.DiaChi = cumRap.ThongTin; cumRapVM.DanhSachRap = connection.Query <RapViewModel>("SELECT * FROM [dbo].[RAP] WHERE MaCumRap = '" + maCumRap + "'", commandType: CommandType.Text); return(cumRapVM); } }
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 <IActionResult> CapNhatCumRap(CumRap cumRapCapNhat) { _cumRapRespository.CapNhatCumRap(cumRapCapNhat); return(Ok()); }
public async Task <IActionResult> ThemCumRap(CumRap cumRap) { _cumRapRespository.ThemCumRap(cumRap); return(Ok()); }
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> 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); } }
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; }