本文整理汇总了C#中UserRole类的典型用法代码示例。如果您正苦于以下问题:C# UserRole类的具体用法?C# UserRole怎么用?C# UserRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserRole类属于命名空间,在下文中一共展示了UserRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteUserRole
public bool DeleteUserRole(UserRole entity)
{
if (entity == null) return false;
_unitOfWork.UserRoleRepository.Delete(entity);
_unitOfWork.Save();
return true;
}
示例2: Edit
public ActionResult Edit(ApplicationUserViewModel user)
{
ApplicationDbContext db = new ApplicationDbContext();
if (ModelState.IsValid)
{
var editedUser = db.Users.FirstOrDefault(x => x.Id == user.Id);
editedUser.DisplayName = user.DisplayName;
editedUser.Avatar = user.Avatar;
editedUser.FacebookProfile = user.FacebookProfile;
var role = db.Roles.FirstOrDefault(x => x.Name == "Admin");
var userRole = new UserRole() { Role = role };
if (user.IsAdmin)
{
editedUser.Roles.Add(userRole);
}
else
{
editedUser.Roles.Clear();
}
db.SaveChanges();
//Db.UsersRepository.Update(editedUser);
//Db.SaveChanges();
return RedirectToAction("Index");
}
return View(user);
}
示例3: IsAuthorized
// authorization check logic
private bool IsAuthorized(UserRole userRoles)
{
var logger = ObjectFactory.GetInstance<Logger>();
bool result;
switch (mode)
{
case RoleMode.Any:
result = (userRoles & roles) == userRoles;
break;
case RoleMode.All:
result = (userRoles & roles) == roles;
break;
default:
logger.Error("[RoleRequiredAttribute].[IsAuthorized] throwing exception ([mode] is unknown).");
throw new InvalidOperationException("Mode is unknown.");
}
if (!result)
{
logger.Debug("[RoleRequiredAttribute].[IsAuthorized] finished work with result = 'false'.");
}
return result;
}
示例4: AuthorizeAttribute
public AuthorizeAttribute(UserRole role)
{
Roles = new[]
{
role
};
}
示例5: LoginCommunication_LoginChanged
void LoginCommunication_LoginChanged(UserRole role)
{
if (role == UserRole.Admin)
{
TiAdmin.IsEnabled = true;
TiEditAdd.IsEnabled = false;
TiSearchView.IsEnabled = false;
}
else if(role == UserRole.Recruiter)
{
TiAdmin.IsEnabled = false;
TiEditAdd.IsEnabled = true;
TiSearchView.IsEnabled = true;
TiRecruits.IsEnabled = true;
}
else if (role == UserRole.Manager)
{
TiAdmin.IsEnabled = false;
TiEditAdd.IsEnabled = true;
TiSearchView.IsEnabled = true;
TiRecruits.IsEnabled = true;
TiManager.IsEnabled = true;
}
else
{
TiAdmin.IsEnabled = false;
TiEditAdd.IsEnabled = false;
TiSearchView.IsEnabled = false;
TiManager.IsEnabled = false;
}
}
示例6: Add
public ActionResult Add(UserRole model)
{
var addRoleResult = _roleAdminService.AddRole(model);
if (!addRoleResult.Success)
TempData.ErrorMessages().Add(addRoleResult.Error);
return RedirectToAction("Index");
}
示例7: Delete_Get
public ActionResult Delete_Get(UserRole role)
{
if (role == null)
return RedirectToAction("Index");
return View(role);
}
示例8: AddUser
/// <summary>
/// 添加新用户。
/// </summary>
/// <param name="username">用户名,此用户名不能已存在。</param>
/// <param name="password">密码</param>
/// <param name="ipLimit">ip绑定地址</param>
/// <param name="role">用户角色</param>
/// <param name="functionModularIDs">用户被赋予的权限列表(使用function_modular表的id组成一个数组。数组中的元素即被赋予的权限。)</param>
/// <returns>是否插入成功。此方法采用事务处理,所以插入失败不会在数据库产生垃圾数据。</returns>
public bool AddUser(String username, String password, String ipLimit, UserRole role, IList<String> functionModularIDs)
{
User newUser = new User();
newUser.name = username;
newUser.password = password;
newUser.ipLimit = ipLimit;
newUser.role = role;
bool result;
//事务处理:插入失败,事务回滚
try
{
sqlMapper.BeginTransaction();
//插入user表
sqlMapper.Insert("InsertUser", newUser);
//循环插入user_function表
foreach (String modularId in functionModularIDs)
{
IDictionary<String, String> dic = new Dictionary<String, String>();
dic.Add("username", username);
dic.Add("functionid", modularId);
sqlMapper.Insert("InsertUserFunctionRelation", dic);
}
sqlMapper.CommitTransaction();
result = true;
}
catch
{
sqlMapper.RollBackTransaction();
result = false;
}
return result;
}
示例9: WebSiteUser
/// <summary>
/// Initializes a new instance of the <see cref="WebSiteUser"/> class.
/// </summary>
/// <param name="loginName">
/// The login name.
/// </param>
/// <param name="customerId">
/// The customer id.
/// </param>
/// <param name="nickName">昵称</param>
/// <param name="role"></param>
public WebSiteUser(string loginName, int customerId, string nickName, UserRole role)
{
this.LoginName = loginName;
this.CustomerId = customerId;
this.NickName = nickName;
Role = role;
}
示例10: DeleteAsync
public async Task DeleteAsync(UserRole role)
{
if (role == null)
throw new ArgumentNullException("role");
await Task.Run((() => _userRoleRepository.Delete(role.Id)));
}
示例11: Get
public IHttpActionResult Get()
{
var result = new UserRole();
result.Users = db.GetAllUsersWithRoles().ToList();
result.Roles = db.GetAllRolesWithUsers().ToList();
return Ok(result);
}
示例12: Run
/// <summary>
/// Run the code example.
/// </summary>
/// <param name="service">An initialized Dfa Reporting service object
/// </param>
public override void Run(DfareportingService service) {
long parentUserRoleId = long.Parse(_T("INSERT_PARENT_USER_ROLE_ID_HERE"));
long permission1Id = long.Parse(_T("INSERT_FIRST_PERMISSION_ID_HERE"));
long permission2Id = long.Parse(_T("INSERT_SECOND_PERMISSIONS_ID_HERE"));
long profileId = long.Parse(_T("INSERT_PROFILE_ID_HERE"));
long subaccountId = long.Parse(_T("INSERT_SUBACCOUNT_ID_HERE"));
String userRoleName = _T("INSERT_USER_ROLE_NAME_HERE");
// Create user role structure.
UserRole userRole = new UserRole();
userRole.Name = userRoleName;
userRole.SubaccountId = subaccountId;
userRole.ParentUserRoleId = parentUserRoleId;
// Create a permission object to represent each permission this user role
// has.
UserRolePermission permission1 = new UserRolePermission();
permission1.Id = permission1Id;
UserRolePermission permission2 = new UserRolePermission();
permission2.Id = permission2Id;
List<UserRolePermission> permissions =
new List<UserRolePermission> { permission1, permission2 };
// Add the permissions to the user role.
userRole.Permissions = permissions;
// Create user role.
UserRole result = service.UserRoles.Insert(userRole, profileId).Execute();
// Display user role ID.
Console.WriteLine("User role with ID {0} was created.", result.Id);
}
示例13: PutUserRole
// PUT api/UserRoles/5
public HttpResponseMessage PutUserRole(int id, UserRole userrole)
{
if (!ModelState.IsValid)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
if (id != userrole.Id)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
db.Entry(userrole).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
示例14: UpdateUser
public ActionResult UpdateUser([DataSourceRequest]DataSourceRequest request, UsersAdminViewModel userVM)
{
if (userVM != null && ModelState.IsValid)
{
var user = this.db.Users.All().FirstOrDefault(u => u.Id == userVM.UserId);
Role selectedRole = db.Roles.All().FirstOrDefault(r => r.Id == userVM.RoleId);
if (user.Roles != null)
{
user.Roles.Clear();
}
var newRole = new UserRole { Role = selectedRole, RoleId = selectedRole.Id, User = user, UserId = user.Id };
user.Roles.Add(newRole);
this.db.SaveChanges();
}
var users = this.db.Users.All().Select(UsersAdminViewModel.FromUser);
DataSourceResult result = users.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);
//return View("Index");
}
示例15: CreateAsync
public async Task CreateAsync(UserRole role)
{
if(role == null)
throw new ArgumentNullException("role");
await Task.Run(() => _userRoleRepository.Insert(role));
}