如何判断一个用户是否有'read notification' in asp.net身份?
How to decide if a user has 'read notification' in asp.net identity?
我在算法或在我的网站中实现特定 'notification' 功能的最佳方法方面遇到了一些麻烦。
目前,我正在使用 asp.net 身份允许用户在我的网站上注册(我知道这不是什么新鲜事)。
但从功能的角度来看,我认为添加一个通知部分会很有用。但是,我对如何确保 'this user has seen this' 在从数据库中删除它之前感到有些困惑...
我有一个 table 喜欢:
+------------------------------------------------+
| NotificationID | Notification | remove |
| <int, auto | <text> | <bit> |
| increment> | | |
+------------------------------------------------+
| | | |
+------------------------------------------------+
我正在使用 ajax 将其添加到我的 _layout.cshtml
页面中..
我渲染的 html 看起来像:
$(document).ready(function () {
$('.navbar').click(function () {
$(this).toggleClass("openNav");
});
updateSideBar();
$(document).on('click', '.rightSidebar .close', function (e) {
var val = parseInt($('.rightSidebar .tog').attr("data-cont"));
val = val - 1;
$('.rightSidebar .tog').attr("data-cont", val);
$(this).parent().remove();
var countthi = $('.rightSidebar .right-content').size();
$('.rightSidebar .tog').attr("data-cont", countthi);
if(countthi < 1)
{
$('.rightSidebar .tog').attr("data-cont", "");
$('.rightSidebar').removeClass("sidebaractive");
}
});
function updateSideBar() {
var countthi = $('.rightSidebar .right-content').size();
$('.rightSidebar .tog').attr("data-cont", countthi);
}
$('.rightSidebar .tog').click(function () {
$('.rightSidebar').toggleClass("sidebaractive");
});
});
.rightSidebar {
position:absolute;
top:100px;
right:-190px;
background:rgba(34,34,34,1);
transition:all 0.6s;
width:200px;
z-index:10;
height:0px;
border:5px double cornflowerblue;
border-right:none;
}
.right-content {
width:90%;
padding-bottom:10px;
padding-top:10px;
margin-left:-webkit-calc(10% - 5px);
margin-left:calc(10% - 5px);
position:relative;
margin-top:10px;
transition:all 0.6s;
border-left:5px double rgba(255, 255, 255, 0.1);
}
.right-content:hover{
background:rgba(255,255,255,0.1)
}
.close {
display:inline-block;
position:absolute;
top:0;
right:0;
height:20px;
width:20px;
cursor:pointer;
border-radius:50%;
z-index:10;
}
.close:before, .close:after {
content:"";
position:absolute;
top:0;
left:-webkit-calc(50% - 2px);
left:calc(50% - 2px);
width:4px;
height:100%;
cursor:pointer;
background:rgba(255, 255, 255, 0.2);
}
.close:before {
-webkit-transform:rotate(45deg);
transform:rotate(45deg);
}
.close:after {
-webkit-transform:rotate(-45deg);
transform:rotate(-45deg);
}
.sidebaractive {
right:0px;
height:50vh;
}
.tog{
position:absolute;
top:-30px;
left:-30px;
height:40px;
width:40px;
border-radius:50%;
transition:all 0.6s;
background:rgba(34,34,34,1);
border:5px double rgba(255,255,255,0.1);
overflow:hidden;
color:gold;
}
.tog:hover:before{
background:rgba(255,255,255,0.1);
}
.tog:before{
content:attr(data-cont);
top:0px;
left:0px;
height:40px;
width:40px;
position:absolute;
text-align:center;
line-height:40px;
}
.sidebaractive .tog{
border:5px double lightgray;
}
.sidebaractive:before{
content:"";
position:absolute;
bottom:-30px;
left:-30px;
height:40px;
width:40px;
border-radius:50%;
transition:all 0.6s;
background:rgba(34,34,34,1);
border:5px double cornflowerblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="rightSidebar" data-cont="">
<div class="tog"></div>
<div id="divResult"></div>
</div>
呈现的标记:
但是,我的问题是我在 table 中显示所有 'notifications',随后当我从我的视图中删除时,它从其他所有人中删除..
我的问题是:我将如何设计它,以便我知道 'user A' 已经删除了它,'user B' 也删除了它(因此它们不再出现)。
但是,用户C暂时没有登录,所以我不想让他们错过。
所以在这种情况下,用户 A 和 B 已经从他们的视图中删除了 it/removed,但是当用户 C 登录时,他们仍然可以看到它,直到他们也删除它?
有没有办法迭代和选择还没有删除的用户?
我正在考虑包括一个“没有看过它的每个人的数组”,并将其保存在数据库中的单独列中。一旦他们 'delete it',将他们从列表中删除。但这似乎 非常 效率低下,尤其是当网站随着用户的增长而增长时。
有人可以就如何实现这一目标提出建议吗?
我在我的应用程序中实现了类似的东西,并且设计符合目的。
我得到了以下数据库 table,它存储了用户和通知之间的映射,并带有一个标志,无论该用户是否已确认。 NotificationId 来自 NotificationMessage table,它存储消息文本、开始日期、结束日期等通知详细信息。
我查询此 table 以检查基于 userId 的已登录用户的待处理通知,并向他们显示 IsAcknowledged = false 的通知。
希望对您有所帮助。
我在算法或在我的网站中实现特定 'notification' 功能的最佳方法方面遇到了一些麻烦。
目前,我正在使用 asp.net 身份允许用户在我的网站上注册(我知道这不是什么新鲜事)。
但从功能的角度来看,我认为添加一个通知部分会很有用。但是,我对如何确保 'this user has seen this' 在从数据库中删除它之前感到有些困惑...
我有一个 table 喜欢:
+------------------------------------------------+
| NotificationID | Notification | remove |
| <int, auto | <text> | <bit> |
| increment> | | |
+------------------------------------------------+
| | | |
+------------------------------------------------+
我正在使用 ajax 将其添加到我的 _layout.cshtml
页面中..
我渲染的 html 看起来像:
$(document).ready(function () {
$('.navbar').click(function () {
$(this).toggleClass("openNav");
});
updateSideBar();
$(document).on('click', '.rightSidebar .close', function (e) {
var val = parseInt($('.rightSidebar .tog').attr("data-cont"));
val = val - 1;
$('.rightSidebar .tog').attr("data-cont", val);
$(this).parent().remove();
var countthi = $('.rightSidebar .right-content').size();
$('.rightSidebar .tog').attr("data-cont", countthi);
if(countthi < 1)
{
$('.rightSidebar .tog').attr("data-cont", "");
$('.rightSidebar').removeClass("sidebaractive");
}
});
function updateSideBar() {
var countthi = $('.rightSidebar .right-content').size();
$('.rightSidebar .tog').attr("data-cont", countthi);
}
$('.rightSidebar .tog').click(function () {
$('.rightSidebar').toggleClass("sidebaractive");
});
});
.rightSidebar {
position:absolute;
top:100px;
right:-190px;
background:rgba(34,34,34,1);
transition:all 0.6s;
width:200px;
z-index:10;
height:0px;
border:5px double cornflowerblue;
border-right:none;
}
.right-content {
width:90%;
padding-bottom:10px;
padding-top:10px;
margin-left:-webkit-calc(10% - 5px);
margin-left:calc(10% - 5px);
position:relative;
margin-top:10px;
transition:all 0.6s;
border-left:5px double rgba(255, 255, 255, 0.1);
}
.right-content:hover{
background:rgba(255,255,255,0.1)
}
.close {
display:inline-block;
position:absolute;
top:0;
right:0;
height:20px;
width:20px;
cursor:pointer;
border-radius:50%;
z-index:10;
}
.close:before, .close:after {
content:"";
position:absolute;
top:0;
left:-webkit-calc(50% - 2px);
left:calc(50% - 2px);
width:4px;
height:100%;
cursor:pointer;
background:rgba(255, 255, 255, 0.2);
}
.close:before {
-webkit-transform:rotate(45deg);
transform:rotate(45deg);
}
.close:after {
-webkit-transform:rotate(-45deg);
transform:rotate(-45deg);
}
.sidebaractive {
right:0px;
height:50vh;
}
.tog{
position:absolute;
top:-30px;
left:-30px;
height:40px;
width:40px;
border-radius:50%;
transition:all 0.6s;
background:rgba(34,34,34,1);
border:5px double rgba(255,255,255,0.1);
overflow:hidden;
color:gold;
}
.tog:hover:before{
background:rgba(255,255,255,0.1);
}
.tog:before{
content:attr(data-cont);
top:0px;
left:0px;
height:40px;
width:40px;
position:absolute;
text-align:center;
line-height:40px;
}
.sidebaractive .tog{
border:5px double lightgray;
}
.sidebaractive:before{
content:"";
position:absolute;
bottom:-30px;
left:-30px;
height:40px;
width:40px;
border-radius:50%;
transition:all 0.6s;
background:rgba(34,34,34,1);
border:5px double cornflowerblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="rightSidebar" data-cont="">
<div class="tog"></div>
<div id="divResult"></div>
</div>
呈现的标记:
但是,我的问题是我在 table 中显示所有 'notifications',随后当我从我的视图中删除时,它从其他所有人中删除..
我的问题是:我将如何设计它,以便我知道 'user A' 已经删除了它,'user B' 也删除了它(因此它们不再出现)。
但是,用户C暂时没有登录,所以我不想让他们错过。
所以在这种情况下,用户 A 和 B 已经从他们的视图中删除了 it/removed,但是当用户 C 登录时,他们仍然可以看到它,直到他们也删除它?
有没有办法迭代和选择还没有删除的用户?
我正在考虑包括一个“没有看过它的每个人的数组”,并将其保存在数据库中的单独列中。一旦他们 'delete it',将他们从列表中删除。但这似乎 非常 效率低下,尤其是当网站随着用户的增长而增长时。
有人可以就如何实现这一目标提出建议吗?
我在我的应用程序中实现了类似的东西,并且设计符合目的。
我得到了以下数据库 table,它存储了用户和通知之间的映射,并带有一个标志,无论该用户是否已确认。 NotificationId 来自 NotificationMessage table,它存储消息文本、开始日期、结束日期等通知详细信息。
我查询此 table 以检查基于 userId 的已登录用户的待处理通知,并向他们显示 IsAcknowledged = false 的通知。
希望对您有所帮助。