public List <(bool IsSuccess, string Message)> UpdateUsersPermission(List <long> userIds, long[] roles, string roleOperation) { var response = new List <(bool, string)>(); using (var txn = _entityRepository.BeginTransaction()) { foreach (var userId in userIds) { var user = GetNccUser(userId); if (user != null) { if (roleOperation.Equals("Add")) { foreach (var item in roles) { if (user.Permissions.Where(x => x.PermissionId == item).Count() == 0) { var permission = _nccPermissionRepository.Get(item); if (permission != null) { user.Permissions.Add(new NccUserPermission() { Permission = permission, User = user }); } } } var result = _entityRepository.Edit(user); response.Add((true, "Roles have been successfully assigned into user " + user.UserName + ". Please refresh page to see update.")); } else if (roleOperation.Equals("Remove")) { foreach (var item in roles) { var permission = user.Permissions.Where(x => x.PermissionId == item).FirstOrDefault(); if (permission != null) { user.Permissions.RemoveAt(user.Permissions.IndexOf(permission)); } } var result = _entityRepository.Edit(user); response.Add((true, "Roles have been successfully assigned into user " + user.UserName + ". Please refresh page to see update.")); } } else { response.Add((false, "User not found.")); } } _entityRepository.SaveChange(); txn.Commit(); } return(response); }
public NccUser Save(NccUser entity) { _entityRepository.Add(entity); _entityRepository.SaveChange(); return(entity); }