public async Task <int> AddAsync(AccountRole accountRole) { var cmd = QueriesCreatingHelper.CreateQueryInsert(accountRole); cmd += ";SELECT LAST_INSERT_ID();"; return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First()); }
public DeveloperPageDeveloper( int userId, string firstName, string lastName, Uri photoUri, string role, DateTime registrationDate, int projectCount, Uri vkPageUri, AccountRole accountRole, ConfirmationStatus confirmationStatus, bool isHidden) { Require.Positive(userId, nameof(userId)); Require.NotEmpty(firstName, nameof(firstName)); Require.NotEmpty(lastName, nameof(lastName)); Require.NotEmpty(role, nameof(role)); Require.ZeroOrGreater(projectCount, nameof(projectCount)); UserId = userId; FirstName = firstName; LastName = lastName; PhotoUri = photoUri; Role = role; RegistrationDate = registrationDate; ProjectCount = projectCount; VkPageUri = vkPageUri; AccountRole = accountRole; ConfirmationStatus = confirmationStatus; IsHidden = isHidden; }
public ActionResult Courses() { List <Course> courses = _courseService.GetCourses(); foreach (var course in courses) { course.Prerequisites = _courseService.GetCoursePrereqs(course.Id); } Account account = GetAuthCookieAccount(); AccountRole accountRole = null; if (account != null && account.Id > 0) { accountRole = account.Role; } Account impersonateAccount = Statics.ImpersonateGet(Session); if (impersonateAccount != null) { account = impersonateAccount; } CatalogViewModel model = new CatalogViewModel() { Courses = courses, ActingAccount = account, AccountLoggedInRole = accountRole }; return(View(model)); }
public Account( string firstname, string lastname, MailAddress email, Password password, AccountRole role, ConfirmationStatus confirmationStatus, DateTime registrationTime, Profile profile) { Require.NotEmpty(firstname, nameof(firstname)); Require.NotEmpty(lastname, nameof(lastname)); Require.NotNull(email, nameof(email)); Require.NotNull(password, nameof(password)); Require.NotNull(email, nameof(email)); Require.NotNull(password, nameof(password)); Firstname = firstname; Lastname = lastname; Email = email; Password = password; Role = role; ConfirmationStatus = confirmationStatus; RegistrationTime = registrationTime; Profile = profile; }
public async Task <IActionResult> PutAccountRole([FromRoute] int id, [FromBody] AccountRole accountRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != accountRole.RoleId) { return(BadRequest()); } _context.Entry(accountRole).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountRoleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private SaveResult SaveEdit(AccountRole role) { role.ModifyBy = AccountInfo.Id; role.ModifyTime = DateTime.UtcNow; return(_component.UpdateRole(role)); }
public LodPrincipal(AccountRole accountRole, IIdentity identity) { Require.NotNull(identity, nameof(identity)); _accountRole = accountRole; Identity = identity; }
public void AddRole(AccountRole role, int UserId) { role.CreatedBy = UserId.ToString(); role.CreationDate = DateTime.Now; _dbContext.Add(role); _dbContext.SaveChanges(); }
public void UpdateRole(AccountRole role, int UserId) { role.ModifiedBy = UserId.ToString(); role.ModifiedDate = DateTime.Now; _dbContext.Entry(role).State = EntityState.Modified; _dbContext.SaveChanges(); }
public ActionResult AccountRoleAdd(AccountRoleModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAccountRoles)) return AccessDeniedView(); if (!ModelState.IsValid) { //display the first model error var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return Content(modelStateErrors.FirstOrDefault()); } if (ModelState.IsValid) { var entity = new AccountRole { Name = model.Name, SystemName = model.Name.ToSystemName(), Active = model.Active, IsSystemRole = false }; _accountService.InsertAccountRole(entity); } return List(command); }
public async Task <HttpResponseMessage> RemoveStaffAssignment(AccountRoleRequest accountRoleRequest) { Services.Log.Info("Remove Staff Assignment Request [API]"); string responseText; stranddContext context = new stranddContext(); if (accountRoleRequest.RoleAssignment == null) { responseText = "No Role Assignment Defined"; Services.Log.Warn(responseText); return(this.Request.CreateResponse(HttpStatusCode.BadRequest, responseText)); } AccountRole lookupAccountRole = await context.AccountRoles.Where(a => a.UserProviderID == accountRoleRequest.UserProviderID) .Where(b => b.CompanyGUID == accountRoleRequest.CompanyGUID) .Where(c => c.RoleAssignment == accountRoleRequest.RoleAssignment).SingleOrDefaultAsync(); if (lookupAccountRole == null) { responseText = "Staff Assignment Not Found"; Services.Log.Info(responseText); return(this.Request.CreateResponse(HttpStatusCode.NotFound, responseText)); } else { //Staff Assignment Removal context.AccountRoles.Remove(lookupAccountRole); await context.SaveChangesAsync(); responseText = "Staff Assignment Successfully Removed"; Services.Log.Info(responseText); return(this.Request.CreateResponse(HttpStatusCode.Created, responseText)); } }
public async Task DeleteAsync(AccountRole item) { var query = "delete from account_roles where accountid = @userId and roleid=@roleId"; var param = new { roleId = item.RoleID, userId = item.AccountID }; await Connection.ExecuteAsync(query, param); }
public SaveResult SaveCreate(AccountRole role, int userId, string userName) { var hasSameCode = BoDB.AccountRoleDb.IsAny(t => t.Name == role.Name); if (hasSameCode) { return new SaveResult() { Result = false, Message = string.Format("Rolename {0} is exist", role.Name) } } ; role.CreateTime = DateTime.UtcNow; BoDB.AccountRoleDb.Insert(role); // Create ActionLog ActionLog actionLog = new ActionLog(); actionLog.IPAddress = GetClientIPAddress(); actionLog.AccountId = userId; actionLog.CreateTime = DateTime.UtcNow; actionLog.ModuleCode = typeof(BORoleBLL).FullName + ".SaveCreate"; actionLog.Username = userName; actionLog.LogContent = "Create BORole " + role.Id; ActionLogBLL ab = new ActionLogBLL(); ab.Create(actionLog); return(new SaveResult(true)); }
public AuthorizationTokenInfo(int userId, AccountRole role, string token, DateTime creationTime) { UserId = userId; Role = role; Token = token; CreationTime = creationTime; }
public Account(string login, AccountRole role) : this() { Status = AccountStatus.Active; Login = login; Role = role; Insurance = InsuranceType.None; }
public void Should_Success_Instantiate() { AccountRole category = new AccountRole() { Id = 1, AccountId = 1, UId = "UId", Role = new Role() { Description = "Description", Code = "Code", Name = "Name", AccountRoles = new List <AccountRole>() { new AccountRole() }, Permissions = new List <Permission>() { new Permission() } }, RoleId = 1, }; Assert.Equal(1, category.Id); Assert.Equal(1, category.AccountId); Assert.NotNull(category.Role); Assert.Equal(1, category.RoleId); }
private SaveResult SaveCreate(AccountRole role) { role.CreateBy = AccountInfo.Id; role.CreateTime = DateTime.UtcNow; return(_component.CreateRole(role)); }
public async Task <IHttpActionResult> GetCurrentAccountRoles(string companyGUID) { List <AccountRole> dbRoleCollection = new List <AccountRole>(); // Get the logged-in user. var currentUser = this.User as ServiceUser; Services.Log.Info("Find Company [" + companyGUID + "] Staff Assignments for Current User"); stranddContext context = new stranddContext(); //Loading List of Account Roles from DB Context dbRoleCollection = await context.AccountRoles.Where(a => a.UserProviderID == currentUser.Id) .Where(b => b.CompanyGUID == companyGUID).ToListAsync <AccountRole>(); if (dbRoleCollection.Count > 0) { string responseText = "Returned Company [" + companyGUID + "] Staff Assignments for Account [" + currentUser.Id + "] " + currentUser.Id; Services.Log.Info(responseText); return(Ok(dbRoleCollection)); } else { string responseText = "No Company [" + companyGUID + "] Staff Assignments for Account [" + currentUser.Id + "] " + currentUser.Id; Services.Log.Info(responseText); AccountRole noneRole = new AccountRole { CompanyGUID = companyGUID, RoleAssignment = "NONE", UserProviderID = currentUser.Id }; dbRoleCollection.Add(noneRole); return(Ok(dbRoleCollection)); } }
public void LinkAccountRole(Guid accountCode, Guid roleCode, bool isRKAdmin, Guid clientId) { using (var transaction = Connection.BeginTransaction()) { try { var _accountRole = ValidateField(accountCode, roleCode, isRKAdmin, clientId); if (!_accountRole.IsNull()) { _accountRole.Status = true; _accountRole.UpdateDate = DateTime.Now; } else { _accountRole = new AccountRole() { Code = Guid.NewGuid(), AccountCode = accountCode, RoleCode = roleCode, Status = true, }; } accountRoleRepository.Save(_accountRole); } catch (Exception) { transaction.Rollback(); throw; } } }
public ActionResult ClassHistory() { Account account = GetAuthCookieAccount(); if (account == null) { return(RedirectToAction("Login", "Account")); } AccountRole userAccountRole = null; if (account != null && account.Id > 0) { userAccountRole = account.Role; } Account impersonateAccount = Statics.ImpersonateGet(Session); if (impersonateAccount != null) { account = impersonateAccount; } List <Course> courseHistory = _courseService.GetCourseHistory(account.Id); AccountViewModel model = new AccountViewModel { Account = account, CourseHistory = courseHistory, Impersonating = (impersonateAccount != null), UserAccountRole = userAccountRole }; return(View(model)); }
private void txtbUserName_TextChanged(object sender, EventArgs e) { try { int rowCount = dtgvAccount.SelectedCells.Count; if (rowCount > 0) { int id = (int)dtgvAccount.SelectedCells[0].OwningRow.Cells["Quyền"].Value; AccountRole accountRole = AccountRoleDAO.Instance.GetAccountRoleById(id); cbRole.SelectedItem = accountRole; int index = -1; int i = 1; foreach (AccountRole item in cbRole.Items) { if (item.Id == accountRole.Id) { index = i; break; } i++; } cbRole.SelectedValue = index; } } catch (Exception ex) { MessageBox.Show("Error " + ex, "Warning"); } }
public async Task <IActionResult> PostAccountRole([FromBody] AccountRole accountRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AccountRoles.Add(accountRole); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (AccountRoleExists(accountRole.RoleId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetAccountRole", new { id = accountRole.RoleId }, accountRole)); }
public async Task <IActionResult> Edit(float id, [Bind("Id,RoleId,AccountId")] AccountRole accountRole) { if (id != accountRole.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(accountRole); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountRoleExists(accountRole.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AccountId"] = new SelectList(_context.Account, "Id", "Email", accountRole.AccountId); ViewData["RoleId"] = new SelectList(_context.Role, "Id", "Id", accountRole.RoleId); return(View(accountRole)); }
public AccountRoleChanged(Guid target, Guid actor, AccountRole newRole) : base(EventType.AccountRoleChanged) { this.Target = target; this.Actor = actor; this.NewRole = newRole; }
public async Task <IActionResult> UpdateAdditionalRole([FromBody] UserAdditionalRoleEditModel model) { var accid = AuthMan.GetAccountId(this); Account acc = await _Repository._DbContext.Accounts.Where(x => x.Id == model.UserId).FirstOrDefaultAsync(); //清除之前的角色信息 var originRoles = _Repository._DbContext.AccountRoles.Where(x => x.Account == acc); foreach (var originItem in originRoles) { _Repository._DbContext.Remove(originItem); } await _Repository._DbContext.SaveChangesAsync(); var newRoles = new List <AccountRole>(); var roleIdArr = model.AdditionalRoleIds.Split(",", StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); foreach (var roleId in roleIdArr) { var newRole = new AccountRole(); newRole.Id = GuidGen.NewGUID(); newRole.Account = acc; newRole.UserRoleId = roleId; newRoles.Add(newRole); } acc.AdditionRoles = newRoles; _Repository._DbContext.Update(acc); await _Repository._DbContext.SaveChangesAsync(); return(Ok()); }
public Account( string firstname, string lastname, MailAddress email, Password password, AccountRole role, ConfirmationStatus confirmationStatus, DateTime registrationTime, Profile profile, int redmineUserId, int gitlabUserId) { Require.NotEmpty(firstname, nameof(firstname)); Require.NotEmpty(lastname, nameof(lastname)); Require.NotNull(email, nameof(email)); Require.NotNull(password, nameof(password)); Require.ZeroOrGreater(redmineUserId, nameof(redmineUserId)); Require.ZeroOrGreater(gitlabUserId, nameof(gitlabUserId)); Require.NotNull(email, nameof(email)); Require.NotNull(password, nameof(password)); Firstname = firstname; Lastname = lastname; Email = email; Password = password; Role = role; ConfirmationStatus = confirmationStatus; RegistrationTime = registrationTime; Profile = profile; RedmineUserId = redmineUserId; GitlabUserId = gitlabUserId; }
public ActionResult Edit([Bind(Include = "id,email,password,fullname,phone,gender,dayOfBirth,address,avatar,dateStart,dateEnd,contractSalary,unitSalary,workTime,schedule,createdDate,createdBy,modifyDate,modifyBy,status,activated")] Employee employee, HttpPostedFileBase avatar, string role) { if (ModelState.IsValid) { string path = Server.MapPath("/Assets/Admin/resources/image"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (employee.avatar != null) { avatar.SaveAs(path + "/" + avatar.FileName); employee.avatar = "Assets/Admin/resources/image/" + avatar.FileName; } else { employee.avatar = "Assets/Admin/resources/image/" + "userDefault.jpg"; } AccountRole account = new AccountRole(); account.employeeId = employee.id; account.roleId = Convert.ToInt32(role); employee.modifyDate = DateTime.Now; employee.modifyBy = Session["username_Employee"].ToString(); employee.password = EncryptPassword.EncryptForPassword(employee.password); db.AccountRoles.Add(account); db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(new RedirectResult(url: "/Admin/Employees/Index?message=update_success")); } return(View(employee)); }
public IHttpActionResult PutAccountRole(int id, AccountRole accountRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != accountRole.AccountRole_Pk) { return(BadRequest()); } db.Entry(accountRole).State = EntityState.Modified; db.SaveChanges(); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AccountRoleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static Role CreateRole(AccountRole role) { return(new Role { Id = (int)role, Name = role.ToString() }); }
static private AccountRole MapToDescriptorRole(AccountRole role) { if (role == AccountRole.Control || role == AccountRole.Sectorizada) { return(AccountRole.Detalle); } return(role); }
public static bool IsCompany(this AccountRole role) { if (role == AccountRole.Company || role == AccountRole.Govt || role == AccountRole.Corp) { return(true); } return(false); }
public ActionResult DeleteConfirmed(string id) { AccountRole accountRole = db.IdentityRoles.Find(id); db.IdentityRoles.Remove(accountRole); db.SaveChanges(); return(RedirectToAction("Index")); }
public AuthorizationTokenInfo(int userId, string token, DateTime creationTime, AccountRole role) { Require.Positive(userId, nameof(userId)); Require.NotEmpty(token, nameof(token)); UserId = userId; Token = token; CreationTime = creationTime; Role = role; }
/// <summary> /// Delete a Account role /// </summary> /// <param name="AccountRole">Account role</param> public virtual void DeleteAccountRole(AccountRole accountRole) { if (accountRole == null) throw new ArgumentNullException("AccountRole"); if (accountRole.IsSystemRole) throw new AaronException("System role could not be deleted"); _accountRoleRepository.Delete(accountRole); _cacheManager.RemoveByPattern(ACCOUNTROLES_PATTERN_KEY); //event notification //_eventPublisher.EntityDeleted(accountRole); }
/// <summary> /// 用户登录结果 /// </summary> /// <param name="bOk"></param> /// <param name="strUser"></param> /// <param name="role"></param> public void UserLoginRe(bool bOk, string strUser, AccountRole role) { DisableAllMenu(); HideAllChildFrm(); this.button_WarehouseMonitor.Hide(); this.buttonDeviceMonitor.Hide(); this.buttonProductView.Hide(); // this.buttonReportview.Hide(); if (bOk) { //根据用户级别,显示不同的界面 this.button_WarehouseMonitor.Show(); this.buttonDeviceMonitor.Show(); if(role == AccountRole.ADMINITOR || role == AccountRole.SYSTEM_MANAGER) { this.buttonProductView.Show(); // this.buttonReportview.Show(); //this.MannualHouseOutToolStripMenuItem.Enabled = true; if(role == AccountRole.SYSTEM_MANAGER) { // this.SystemSetToolStripMenuItem.Enabled = true; } } } }
private void AccountRoles_Detach(AccountRole entity) { this.SendPropertyChanging(); entity.Account = null; }
private void AccountRoles_Attach(AccountRole entity) { this.SendPropertyChanging(); entity.SecurityRole = this; }
/// <summary> /// Updates the Account role /// </summary> /// <param name="AccountRole">Account role</param> public virtual void UpdateAccountRole(AccountRole accountRole) { if (accountRole == null) throw new ArgumentNullException("accountRole"); _accountRoleRepository.Update(accountRole); _cacheManager.RemoveByPattern(ACCOUNTROLES_PATTERN_KEY); //event notification //_eventPublisher.EntityUpdated(accountRole); }
/// <summary> /// Authorize permission /// </summary> /// <param name="permissionRecordSystemName">Permission record system name</param> /// <param name="accountRole">Account role</param> /// <returns>true - authorized; otherwise, false</returns> protected virtual bool Authorize(string permissionRecordSystemName, AccountRole accountRole) { if (String.IsNullOrEmpty(permissionRecordSystemName)) return false; string key = string.Format(PERMISSIONS_ALLOWED_KEY, accountRole.Id, permissionRecordSystemName); return _cacheManager.Get(key, () => { foreach (var permission1 in accountRole.PermissionRecords) if (permission1.SystemName.Equals(permissionRecordSystemName, StringComparison.InvariantCultureIgnoreCase)) return true; return false; }); }
/// <summary> /// Install permissions /// </summary> /// <param name="permissionProvider">Permission provider</param> public virtual void InstallPermissions(IPermissionProvider permissionProvider) { //install new permissions var permissions = permissionProvider.GetPermissions(); foreach (var permission in permissions) { var permission1 = GetPermissionRecordBySystemName(permission.SystemName); if (permission1 == null) { //new permission (install it) permission1 = new PermissionRecord() { Name = permission.Name, SystemName = permission.SystemName, Category = permission.Category, }; //default account role mappings var defaultPermissions = permissionProvider.GetDefaultPermissions(); foreach (var defaultPermission in defaultPermissions) { var accountRole = _accountService.GetAccountRoleBySystemName(defaultPermission.AccountRoleSystemName); if (accountRole == null) { //new role (save it) accountRole = new AccountRole() { Name = defaultPermission.AccountRoleSystemName, Active = true, SystemName = defaultPermission.AccountRoleSystemName }; _accountService.InsertAccountRole(accountRole); } var defaultMappingProvided = (from p in defaultPermission.PermissionRecords where p.SystemName == permission1.SystemName select p).Any(); var mappingExists = (from p in accountRole.PermissionRecords where p.SystemName == permission1.SystemName select p).Any(); if (defaultMappingProvided && !mappingExists) { permission1.AccountRoles.Add(accountRole); } } //save new permission InsertPermissionRecord(permission1); } } }
public static bool IsInRole(this IPrincipal principal, AccountRole role) { var lodPrincipal = principal as LodPrincipal; return lodPrincipal?.IsInRole(role) ?? false; }
/// <summary> /// 触发用户角色改变事件 /// </summary> /// <param name="role"></param> private void OnRoleChange(AccountRole role) { LoginEventArg e = new LoginEventArg(); e.CurRole = role; if(role == AccountRole.OPERATOR) { this.textBoxPaswd.Enabled = false; } else { this.textBoxPaswd.Enabled = true; } if(eventRoleChange != null) { eventRoleChange(this, e); } }
public bool IsInRole(AccountRole role) { return _roles.Matches(role); }
public bool IsInRole(AccountRole role) { return (_accountRole == AccountRole.Administrator || _accountRole == role) && !IsEmpty; }
public AuthorizationAttribute(AccountRole accountRole) { _accountRole = accountRole; }
public JsonResult UpdateAccountRoles(int id, string strRoleids) { Core.Business.Account account = Core.Business.Account.Load(id); if (account == null) return Json(new { success = false, message = "系统发生错误,请检查要更新的帐号!" }); if (strRoleids == null) return Json(new { success = false, message = "系统发生错误,请确认要添加的角色!" }); JavaScriptSerializer serializer = new JavaScriptSerializer(); IList<int> roleids = serializer.Deserialize<IList<int>>(strRoleids); HashSet<Role> existRoles = account.Roles.ToHashSet(); foreach (var roleid in roleids) { Role role = Role.Load(roleid); if (role == null) continue; AccountRole accountRole = AccountRole.Load(new AccountRoleKey() { AccountId = account.Id, RoleId = role.Id }); if (accountRole == null) { accountRole = new AccountRole(); accountRole.Id = new AccountRoleKey() { AccountId = account.Id, RoleId = role.Id }; accountRole.Status = 0; accountRole.Save(); } else { existRoles.Remove(role); } } foreach (var role in existRoles) { AccountRole accountRole = AccountRole.Load(new AccountRoleKey() { AccountId = account.Id, RoleId = role.Id }); accountRole.DeleteOnSave(); accountRole.Save(); } return Json(new { success = true, message = "成功更新角色的信息!" }, JsonRequestBehavior.AllowGet); }
public JsonResult UpdateRoles(int id, string strRoleids) { Account account = this.accountRepository.FindBy(id); if (account == null) return Json(new { success = false, message = "系统发生错误,请检查要跟更新的帐号!" }); if (strRoleids == null) return Json(new { success = false, message = "系统发生错误,请确认要添加的角色!" }); JavaScriptSerializer serializer = new JavaScriptSerializer(); IList<int> roleids = serializer.Deserialize<IList<int>>(strRoleids); HashSet<Role> existRoles = this.roleRepository.FindByAccount(account); foreach (var roleid in roleids) { Role role = this.roleRepository.FindBy(roleid); if (role == null) continue; AccountRole accountRole = this.accountRoleRepository.FindBy(new AccountRoleKey() { Account = account, Role = role }); if (accountRole == null) { accountRole = new AccountRole(new AccountRoleKey() { Account = account, Role = role }); this.accountRoleRepository.Add(accountRole); } else { existRoles.Remove(role); } } foreach (var role in existRoles) { AccountRole accountRole = new AccountRole(new AccountRoleKey() { Account = account, Role = role }); this.accountRoleRepository.Remove(accountRole); } this.unitOfWork.Commit(); return Json(new { success = true, message = "成功更新角色的信息!" }, JsonRequestBehavior.AllowGet); }