/// <summary> /// Изменение прав для группы /// При этом необходимо всем пользователям этой группы поменять в другой таблице (раньше можно было отдельным пользователям давать отдельные права) /// </summary> /// <param name="groupClaim"></param> /// <returns></returns> public override bool updateGroupClaims(GroupClaims groupClaim) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { cms_resolutions_templates cdGroupResolution = null; if (string.IsNullOrEmpty(groupClaim.GroupAlias) || groupClaim.ContentId == Guid.Empty) { throw new Exception("updateGroupClaims: alias or contentId Is Null Or Empty"); } var query = db.cms_resolutions_templatess .Where(t => t.f_menu_id == groupClaim.ContentId) .Where(t => t.f_user_group == groupClaim.GroupAlias); if (!query.Any()) { cdGroupResolution = new cms_resolutions_templates() { f_user_group = groupClaim.GroupAlias, f_menu_id = groupClaim.ContentId } } ; else { cdGroupResolution = query.SingleOrDefault(); } switch (groupClaim.Claim) { case ClaimType.read: cdGroupResolution.b_read = groupClaim.Checked; break; case ClaimType.write: cdGroupResolution.b_write = groupClaim.Checked; break; case ClaimType.change: cdGroupResolution.b_change = groupClaim.Checked; break; case ClaimType.delete: cdGroupResolution.b_delete = groupClaim.Checked; break; default: return(false); } if (!query.Any()) { db.Insert(cdGroupResolution); } else { db.Update(cdGroupResolution); } //Права пользователей группы var groupUsers = db.cms_userss .Where(p => p.f_group != null) .Where(p => p.f_group == groupClaim.GroupAlias); if (groupUsers.Any()) { foreach (var user in groupUsers.ToArray()) { var userClaims = new UserClaims() { UserId = user.id, ContentId = groupClaim.ContentId, Claim = groupClaim.Claim, Checked = groupClaim.Checked }; updateUserClaims(userClaims); } } tran.Commit(); return(true); } } }
/// <summary> /// Изменение группы, только название группе меняем /// </summary> /// <param name="claim"></param> /// <returns></returns> public override bool updateGroup(GroupModel group) { using (var db = new CMSdb(_context)) { using (var tran = db.BeginTransaction()) { var getGroup = db.cms_users_groups. Where(g => g.c_alias.ToLower() == group.Alias.ToLower()); if (getGroup.Any()) { var cdGroup = getGroup.SingleOrDefault(); cdGroup.c_title = group.GroupName; db.Update(cdGroup); var log = new LogModel() { Site = _domain, Section = LogSection.UserGroup, Action = LogAction.update, PageId = cdGroup.id, PageName = group.GroupName, UserId = _currentUserId, IP = _ip, }; insertLog(log); } else { var cdGroup = new cms_users_group() { id = Guid.NewGuid(), c_alias = group.Alias, c_title = group.GroupName }; db.Insert(cdGroup); //insert claims var templates = db.cms_menus.Select(p => p.id); if (templates != null) { foreach (var template in templates.ToArray()) { var claims = new cms_resolutions_templates() { f_menu_id = template, f_user_group = group.Alias, b_read = false, b_write = false, b_change = false, b_delete = false, }; db.Insert(claims); } } var log = new LogModel() { Site = _domain, Section = LogSection.UserGroup, Action = LogAction.insert, PageId = cdGroup.id, PageName = group.GroupName, UserId = _currentUserId, IP = _ip, }; insertLog(log); } tran.Commit(); return(true); } } }