本文整理汇总了C#中UserRole类的典型用法代码示例。如果您正苦于以下问题:C# UserRole类的具体用法?C# UserRole怎么用?C# UserRole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserRole类属于命名空间,在下文中一共展示了UserRole类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DeleteUserRole
public bool DeleteUserRole(UserRole entity)
{
if (entity == null) return false;
_unitOfWork.UserRoleRepository.Delete(entity);
_unitOfWork.Save();
return true;
}
开发者ID:edgecomputing,项目名称:cats-hub-module,代码行数:7,代码来源:UserRoleService.cs
示例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);
}
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:31,代码来源:AdminUsersController.cs
示例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;
}
开发者ID:vitalyobukhov,项目名称:SmsToMail,代码行数:28,代码来源:RoleRequiredAttribute.cs
示例4: AuthorizeAttribute
public AuthorizeAttribute(UserRole role)
{
Roles = new[]
{
role
};
}
开发者ID:juanlurie,项目名称:clientele-training,代码行数:7,代码来源:AuthorizeAttribute.cs
示例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;
}
}
开发者ID:Tranzystor,项目名称:MarketingDataBase,代码行数:31,代码来源:MainWindow.xaml.cs
示例6: Add
public ActionResult Add(UserRole model)
{
var addRoleResult = _roleAdminService.AddRole(model);
if (!addRoleResult.Success)
TempData.ErrorMessages().Add(addRoleResult.Error);
return RedirectToAction("Index");
}
开发者ID:neozhu,项目名称:MrCMS,代码行数:7,代码来源:RoleController.cs
示例7: Delete_Get
public ActionResult Delete_Get(UserRole role)
{
if (role == null)
return RedirectToAction("Index");
return View(role);
}
开发者ID:neozhu,项目名称:MrCMS,代码行数:7,代码来源:RoleController.cs
示例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;
}
开发者ID:Brinews,项目名称:Code,代码行数:43,代码来源:UserManageDAO.cs
示例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;
}
开发者ID:ngnono,项目名称:NG.FM,代码行数:18,代码来源:WebSiteUser.cs
示例10: DeleteAsync
public async Task DeleteAsync(UserRole role)
{
if (role == null)
throw new ArgumentNullException("role");
await Task.Run((() => _userRoleRepository.Delete(role.Id)));
}
开发者ID:burtonsmith,项目名称:aspnet-n-tier-applications,代码行数:7,代码来源:UserRoleService.cs
示例11: Get
public IHttpActionResult Get()
{
var result = new UserRole();
result.Users = db.GetAllUsersWithRoles().ToList();
result.Roles = db.GetAllRolesWithUsers().ToList();
return Ok(result);
}
开发者ID:Hunterm267,项目名称:Web-ASPArmaAdmin,代码行数:7,代码来源:UsersApiController.cs
示例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);
}
开发者ID:bigTdiablo,项目名称:googleads-dfa-reporting-samples,代码行数:38,代码来源:CreateUserRole.cs
示例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);
}
开发者ID:nathanfl,项目名称:AAHIPro,代码行数:26,代码来源:UserRolesController.cs
示例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");
}
开发者ID:BobbyBorisov,项目名称:ZealotTicketRewardingSystem,代码行数:25,代码来源:UsersController.cs
示例15: CreateAsync
public async Task CreateAsync(UserRole role)
{
if(role == null)
throw new ArgumentNullException("role");
await Task.Run(() => _userRoleRepository.Insert(role));
}
开发者ID:burtonsmith,项目名称:aspnet-n-tier-applications,代码行数:7,代码来源:UserRoleService.cs
示例16: Save
public int Save(UserRole userRole)
{
UserRoleRepository ur = new UserRoleRepository();
if (userRole.ID > 0)
return ur.Update(userRole);
else return ur.Insert(userRole);
}
开发者ID:yoorke,项目名称:zrchiptuning,代码行数:7,代码来源:UserRoleBL.cs
示例17: Put
// PUT odata/UserRole(5)
public virtual async Task<IHttpActionResult> Put([FromODataUri] int roleId, UserRole userRole)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (roleId != userRole.RoleId)
{
return BadRequest();
}
try
{
await MainUnitOfWork.UpdateAsync(userRole);
}
catch (DbUpdateConcurrencyException)
{
if (!MainUnitOfWork.Exists(roleId))
{
return NotFound();
}
else
{
return Conflict();
}
}
return Ok(userRole);
}
开发者ID:gitter-badger,项目名称:WealthEconomy,代码行数:31,代码来源:UserRolesController.cs
示例18: AddRole
public AddRoleResult AddRole(UserRole model)
{
if (_roleService.GetRoleByName(model.Name) != null)
return new AddRoleResult(false, string.Format("{0} already exists.", model.Name));
_roleService.SaveRole(model);
return new AddRoleResult(true, null);
}
开发者ID:neozhu,项目名称:MrCMS,代码行数:7,代码来源:RoleAdminService.cs
示例19: RoleController_AddPost_ReturnsRedirectToRouteResult
public void RoleController_AddPost_ReturnsRedirectToRouteResult()
{
RoleController roleController = GetRoleController();
var userRole = new UserRole();
roleController.Add(userRole).Should().BeOfType<RedirectToRouteResult>();
}
开发者ID:neozhu,项目名称:MrCMS,代码行数:7,代码来源:RoleControllerTests.cs
示例20: IsAuthorized
public bool IsAuthorized(IRequestContext requestContext, IUserProvider userProvider, UserRole userRole)
{
if (userRole == UserRole.None)
{
userRole = UserRole.ReadOnly;
}
string userName = requestContext.UserName,
password = requestContext.Password;
if (userName == null || password == null)
{
return false;
}
var ip = GetIp(true);
/*
if (ip != requestContext.ClientId)
{
return false;
}
* */
HttpContext.Current.Trace.Write("requestContext.ClientId = " + requestContext.ClientId);
HttpContext.Current.Trace.Write("ip = " + ip);
var result = userProvider.Validate(userName, password);
return result != null && result.Result;
}
开发者ID:girmateshe,项目名称:OAuth,代码行数:30,代码来源:AuthorizationProvider.cs
注:本文中的UserRole类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论