【发布时间】:2020-02-04 19:25:34
【问题描述】:
您好,目前我正在尝试在我的网站上创建一项功能,让管理员可以看到一件事,而普通用户可以看到另一件事。这是我的代码
[RestrictAccess(restriction = AccessRestrictions.ModifySalesOrder)]
public ActionResult ChangeStatus(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
SalesOrder salesOrder = db.SalesOrders.Find(id);
if (salesOrder == null)
{
return HttpNotFound();
}
ViewBag.Invoice = false;
ViewBag.enoughStock = true;
switch (salesOrder.SalesOrderStatus)
{
case SOStatus.Pending:
ViewBag.statusList = new List<Object>
{
new {value = SOStatus.Pending, text = "Pending" },
new {value = SOStatus.Released, text = "Released" },
};
break;
case SOStatus.Released:
ViewBag.Invoice = true;
ViewBag.statusList = new List<Object>
{
new {value = SOStatus.Shipped, text = "Shipped" },
new {value = SOStatus.Close, text = "Close" },
};
break;
这是我的组模型类
public class Groups
{
[Key]
public int ID { get; set; }
[Display(Name = "Group Name")]
public string GroupName { get; set; }
}
public class groupAccess
{
[Key]
public int ID { get; set; }
public AccessRestrictions restriction { get; set; }
public bool allow { get; set; }
public int groupID { get; set; }
}
这是将用户分配给组 ID 的 userAccess 类
public class userAccess
{
[Key]
public int ID { get; set; }
public AccessRestrictions restriction { get; set; }
public bool allow { get; set; }
public int userID { get; set; }
public int groupID { get; set; }
}
我希望管理员能够在它发布时将其切换回待处理状态,但我不希望用户拥有该功能。我有一个组模型,我可以将用户分配为管理员,但我目前的问题是我不知道如何“限制访问”,所以它只是“管理员”组。
谢谢
【问题讨论】:
-
您的组模型是否有方法来检查用户是否在管理员组中?
-
是的,我现在唯一的问题是我不知道如何将其限制为“管理员”组@TravisActon
标签: c# asp.net-mvc