/// <summary> /// AddRolesToUserAsync /// </summary> /// <param name="userId"></param> /// <param name="roleId"></param> /// <param name="lastUser"></param> /// <returns></returns> /// <exception cref="IdentityException"></exception> /// <exception cref="DatabaseException"></exception> public async Task AddRolesToUserAsync(long userId, long roleId, string lastUser) { ThrowIf.NotLongId(userId, nameof(userId)); ThrowIf.NotLongId(roleId, nameof(roleId)); TransactionContext trans = await _transaction.BeginTransactionAsync <RoleOfUser>().ConfigureAwait(false); try { //查重 long count = await _roleOfUserRepo.CountByUserIdAndRoleIdAsync(userId, roleId, trans).ConfigureAwait(false); if (count != 0) { throw Exceptions.FoundTooMuch(userId: userId, roleId: roleId, cause: "已经有相同的角色"); } RoleOfUser ru = new RoleOfUser(userId, roleId); await _roleOfUserRepo.UpdateAsync(ru, lastUser, trans).ConfigureAwait(false); await trans.CommitAsync().ConfigureAwait(false); } catch { await trans.RollbackAsync().ConfigureAwait(false); throw; } }
public bool RemoveRole([FromBody] RoleOfUser userRoleEntity) { return(dc.DbTran(delegate { var userRole = dc.Table <RoleOfUser>() .First(x => x.UserId == userRoleEntity.UserId && x.RoleId == userRoleEntity.RoleId); dc.Table <RoleOfUser>().Remove(userRole); }) > 0); }
public Users(string firstName, string lastName, string email, string hash, string salt, RoleOfUser roleOfUser) { FirstName = firstName; LastName = lastName; Email = email; HashPassword = hash; Salt = salt; DateCreated = DateTime.Now; RoleOfUser = roleOfUser; StatusOfVerification = "Processing"; CodeOfVerification = GetRandomString(256); }
public bool AddRole([FromBody] RoleOfUser userRoleEntity) { dc.Table <RoleOfUser>().Add(userRoleEntity); return(true); }