删除权限角色
开发工具与关键技术:Visual Studio
作者:胡宁淇
撰写时间:2019年5月5日
要删除权限角色我们要知道被删除那一条数据的ID,我们用int类型来接收页面传过来的用户类型ID
public ActionResult DeleteUserType(int userTypeId) {
实例化提示实体
ReturnJson msg = new ReturnJson();
给一个通道,在这个通道里执行,确保交易的完整性,也就是确保所有的ID都传输过来
using (var scope=new TransactionScope()) {
try
{
根据传输过来的ID查询权限表
List<PW_Jurisdiction> jurisdiction = (from tbJurisdiction in myModel.PW_Jurisdiction
where tbJurisdiction.UserTypeID=userTypeId
select
tbJurisdiction).ToList();
如果查询出来的条数大于0条
if (jurisdiction.Count()>0)
{
就删除上面的集合
myModel.PW_Jurisdiction.RemoveRange(jurisdiction);
}
根据传过来的用户类型进行查询
SYS_UserType dbUserType = (from tbUserType in myModel.SYS_UserType
where
tbUserType.UserTypeID==userTypeId
select
tbUserType).Single();
删除查询出来的数据
myModel.SYS_UserType.Remove(dbUserType);
myModel.SaveChanges();
交易完成
scope.Complete();
状态为true,并提示删除成功
msg.State = true;
msg.Text = "删除成功";
}
catch (Exception)
{
msg.State = false;
msg.Text = "删除失败";
}
}
return Json(msg,JsonRequestBehavior.AllowGet);
}
然后就是在页面写的方法,用的是jQuery中的getJSON异步提交