c# - 不同用户会话的相似记录数
问题描述
在我的 MVC 应用程序中,用户登录是通过会话进行的。存在一个仪表板,显示分配给每个用户的票数。此计数通过 SQL 过程启动。
ALTER PROC [dbo].[Usp_GetTicketCountByUserID]
@UserID int
AS
BEGIN
Select AssignToAdmin,
COUNT(CASE WHEN [Status] = 'A' then 1 else NULL END) openCount,
COUNT(CASE WHEN [Status] = 'C' then 2 else NULL END) ClosedCount
from AssignedRoles
where AssignToAdmin = @UserID
GROUP BY AssignToAdmin
END
GO
当我从 SQL 执行过程时,我得到了正确的结果,但是从应用程序中它显示零(0)。我注意到,当我删除 where 子句时,它会为所有用户显示类似的计数,这不应该是这种情况。
控制器:
var x = _ITimesheet.GetTimeSheetsCountByUserID(Convert.ToInt32(Session["UserID"]));
if (x != null)
{
ViewBag.MyCall = x.OpenCount;
ViewBag.ClosedTicket = x.ClosedCount;
}
else
{
ViewBag.MyCall = 0;
ViewBag.ClosedTicket = 0;
}
班级
public DisplayViewModel GetTimeSheetsCountByUserID(int UserID)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TSC"].ToString()))
{
var param = new DynamicParameters();
param.Add("@UserID", UserID);
return con.Query<DisplayViewModel>("Usp_GetTicketCountByUserID", param, null, true, 0, System.Data.CommandType.StoredProcedure).FirstOrDefault();
}
}
任何有关如何解决此问题的帮助将不胜感激。
解决方案
我想到了。显然我不恰当地分配了该类 [UserID] 而不是 [AdminID]。这是因为我有基于用户角色的各种会话。
推荐阅读
- flutter - 底部溢出 13 个像素的 RenderFlex
- chatbot - 在 Microsoft Teams 中,可配置选项卡可以发送聊天消息吗?
- apache-spark - Spark:无法设置以“spark.sql”开头的表属性以在创建时配置外部表
- .net - PowerShell 核心。相对路径问题
- javascript - 从 HTTP GET 请求中获取数据
- excel - 下拉列表和单元格格式的条件语句
- macos - 在 MacOS 上的屏幕底部(而不是侧面)渲染 swiftui NavigationLink?
- google-apps-script - Google Web App 最大同时用户容量
- python - 如何根据 where 子句创建具有额外维度的 numpy 数组?
- cluster-analysis - 确定给定经纬度点和两个加权变量的最佳位置