/// <summary> /// 设置用户角色 /// </summary> /// <param name="UserIDs"></param> /// <param name="RoleIDs"></param> /// <returns></returns> public JsonResult SetUserRole(string UserIDs, string RoleIDs) { if (string.IsNullOrWhiteSpace(UserIDs) || string.IsNullOrWhiteSpace(RoleIDs)) { return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet)); } List <int> userIDArr = UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList(); List <int> roleIDArr = RoleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList(); if (!CurrentInfo.IsAdministrator && userIDArr.Contains(1330)) { return(Json(new Result(false, "拒绝修改"), JsonRequestBehavior.AllowGet)); } IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>(); List <RelationUserRole> listRelationUserRole = new List <RelationUserRole>(); int addCount = 0; using (TransactionScope scope = TransactionScopeHelper.GetTran()) { foreach (var userID in userIDArr) { //删除当前人员的所有的权限,然后在添加新的权限 var userRoles = relationUserRoleService.GetEntities(t => t.UserID == userID); relationUserRoleService.DeleteEntities(userRoles.ToList()); foreach (var roleID in roleIDArr) { RelationUserRole model = new RelationUserRole(); model.UserID = userID; model.RoleID = roleID; model.CreateUserID = CurrentInfo.CurrentUser.ID; model.CreateTime = DateTime.Now; listRelationUserRole.Add(model); } } addCount = relationUserRoleService.AddEntities(listRelationUserRole).Count(); scope.Complete(); } return(Json(new Result(addCount > 0, "成功分配用户角色"), JsonRequestBehavior.AllowGet)); }
public static bool Delete(this RelationUserRole model) { return(ServiceHelper.GetRelationUserRoleService.DeleteEntity(model.ID)); }
public static bool Update(this RelationUserRole model) { return(ServiceHelper.GetRelationUserRoleService.UpdateEntity(model)); }
//==================RelationStoresModule拓展结束================== //==================RelationUserRole拓展开始================== public static RelationUserRole Add(this RelationUserRole model) { return(ServiceHelper.GetRelationUserRoleService.AddEntity(model)); }