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 bool ThemRap(string MaRap, string SoDayGhe, string SoLuongGhe, string LoaiRap, ref string err) { try { QuanLyRapPhimDataContext qlR = new QuanLyRapPhimDataContext(); Rap r = new Rap(); r.SoDayGhe = SoDayGhe; r.SoLuongGhe = SoLuongGhe; r.LoaiPhim = LoaiRap; qlR.Raps.InsertOnSubmit(r); qlR.Raps.Context.SubmitChanges(); } catch (SqlException) { MessageBox.Show("Không thêm được. Lỗi rồi!"); } return(true); }
public Rap Generate(int verseCount) { Random rand = new Random(); int rhymeCount = rand.Next(MinRhymes, MaxRhymes); // Generates a list of random verses to the specified verse_count List <string> verses = new List <string>(verseCount); for (int i = 0; i < verseCount; i++) { verses.Add(Templates.ElementAt(rand.Next(Templates.Count))); } List <string> rhymes = new List <string>(); bool baseHit = false; string baseWord = null; string baseType = null; for (int i = 0; i < verseCount; ++i) { string verse = verses.ElementAt(i); List <string> verseWords = verse.Split(' ').ToList(); for (int j = 0; j < verseWords.Count(); ++j) { string word = verseWords.ElementAt(j); if (!baseHit && (word.ElementAt(0) == '<')) { int endIndex = word.IndexOf('>'); baseType = word.Substring(1, endIndex - 1); baseWord = GetBaseWord(baseType); rhymes.Add(baseWord.ToLower()); verseWords[j] = baseWord; // Preserve comma if (word.Contains(',')) { verseWords[j] += ','; } rhymeCount = rand.Next(MinRhymes, MaxRhymes); baseHit = true; } else if (baseHit && (word.ElementAt(0) == '<')) { int endIndex = word.IndexOf('>'); WordType wordType; baseType = word.Substring(1, endIndex - 1); switch (baseType) { case "noun": wordType = WordType.Noun; break; case "adjective": wordType = WordType.Adjective; break; case "verb": wordType = WordType.Verb; break; default: wordType = WordType.Any; break; } string rhyme = null; rhyme = m_RhymeGenerator.GetRhyme(baseWord, wordType); rhymes.Add(rhyme.ToLower()); rhymeCount--; verseWords[j] = rhyme; // Preserve comma if (word.Contains(',')) { verseWords[j] += ','; } } if (rhymeCount < 2) { rhymeCount = rand.Next(MinRhymes, MaxRhymes); baseHit = false; } } // Join the words back into a verse verse = verseWords.Aggregate((a, b) => (a + ' ' + b)); // Make the entire thing lowercase verse = verse.ToLower(); // Make the first letter uppercase verse = char.ToUpper(verse[0]) + verse.Substring(1); // Replace the original verse with the phire one verses[i] = verse; } Rap rap = new Rap { Verses = verses, Rhymes = rhymes }; return(rap); }
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; }