//Đặt vé public async Task <object> DatVe(DanhSachVeDatViewModel danhSachVeDat) { using (var connection = new SqlConnection(connectionString)) { if (connection.State == ConnectionState.Closed) { connection.Open(); } var thanhVien = connection.QuerySingleOrDefault("SELECT TaiKhoan FROM [dbo].[THANHVIEN] " + "WHERE TaiKhoan = '" + danhSachVeDat.TaiKhoan + "'", commandType: CommandType.Text); var maThanhVien = connection.QuerySingleOrDefault <int>("SELECT MaThanhVien FROM [dbo].[THANHVIEN] " + "WHERE TaiKhoan = '" + danhSachVeDat.TaiKhoan + "'", commandType: CommandType.Text); if (thanhVien == null) { return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tài khoản người dùng không tồn tại!")); } if (danhSachVeDat.DanhSachVe == null) { return("Danh sách vé rỗng!"); } else { var p = new DynamicParameters(); p.Add("@MATHANHVIEN", maThanhVien); p.Add("@NGAYDAT", DateTime.Now); p.Add("@TONGTIEN", danhSachVeDat.TongTien); p.Add("@MALICHCHIEU", danhSachVeDat.MaLichChieu); p.Add("@ReturnValue", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); p.Add("@TRANGTHAITHANHTOAN", danhSachVeDat.TrangThaiThanhToan); p.Add("@GIAMGIA", danhSachVeDat.GiamGia); await connection.ExecuteScalarAsync("THANH_TOAN_INSERT", p, commandType : CommandType.StoredProcedure); int returnValue = p.Get <int>("@ReturnValue"); foreach (var veDat in danhSachVeDat.DanhSachVe) { // Ve ve = new Ve(); var param = new DynamicParameters(); param.Add("@MAGHE", veDat.MaGhe); param.Add("@MATHANHTOAN", returnValue); param.Add("@GIAVE", veDat.GiaVe); param.Add("@MALICHCHIEU", danhSachVeDat.MaLichChieu); await connection.QueryAsync <Ve>("VE_INSERT", param, commandType : CommandType.StoredProcedure); } //TheaterHub.FetchTheater(); return(returnValue); //return returnValue; } } }
public async Task <IActionResult> DatVe(DanhSachVeDatViewModel danhSachVeDat) { var result = await _quanLyDatVeRespository.DatVe(danhSachVeDat); return(Ok(result)); }