/// <summary> /// Checks if the input <see cref="UserKey"/> is authorized to unlock the /// <see cref="SecureArchive"/> and uses it to decrypt the <see cref="ArchiveKey"/>. /// </summary> /// <param name="userKey">The <see cref="UserKey"/> to </param> /// <returns>The data encryption key for the <see cref="SecureArchive"/>.</returns> /// <exception cref="UnauthorizedException">Thrown when the input key is not authorized to unlock the archive.</exception> private ArchiveKey DecryptArchiveKey(UserKey userKey) { const string error = "The user key is not authorized to unlock the archive."; var keyAuthorizationRecord = this.ArchiveMetadata.UserKeyAuthorizations.FirstOrDefault( k => CryptoHelpers.SecureEquals(k.KeyId, userKey.KeyId)); if (keyAuthorizationRecord is null || !keyAuthorizationRecord.TryDecryptArchiveKey(userKey, this.ArchiveMetadata.SecuritySettings, out var archiveKey)) { throw new UnauthorizedException(error); } // Check the auth canary. Guid decryptedCanary; try { decryptedCanary = new Guid(archiveKey.Decrypt(this.CryptoStrategy, this.ArchiveMetadata.AuthCanary)); } catch { throw new UnauthorizedException(error); } if (!CryptoHelpers.SecureEquals(decryptedCanary.ToByteArray(), this.ArchiveMetadata.Id.ToByteArray())) { throw new UnauthorizedException(error); } // Congrats, you're authorized! return(archiveKey); }
public IActionResult Edit(UserViewModel viewModel) { if (ModelState.IsValid) { // Verify not exist on id var key = new UserKey() { Id = viewModel.Id }; var user = _usersService.GetUser(key); if (user != null) { user.Id = viewModel.Id; user.Name = viewModel.Name; user.Email = viewModel.Email; user.Suspended = viewModel.Suspended; //Verify role exist var roleKey = new RoleKey(); roleKey.Id = viewModel.RoleId; var role = _rolesService.GetRole(roleKey); if (role != null) { user.Role = role; user = _usersService.UpdateUser(user); return(RedirectToAction("Index")); } } } // Populate SelectListItem of roles ViewBag.Roles = ControllerUtils.CreateSelectRoleItemList(_rolesService.FindRoles(), viewModel.Id); return(View(viewModel)); }
public Tuple <bool, string, string, UserKey> AddUserKey(string id, UserKey userKey) { string CleanId = id.Trim(); string CleanUsername = userKey.Username.Trim(); if (Usernames.ContainsKey(CleanUsername)) { return(new Tuple <bool, string, string, UserKey>(false, "Username already exists. Pick a different one.", null, null)); } if (UserKeys.ContainsKey(CleanId)) { return(new Tuple <bool, string, string, UserKey>(false, "User ID already exists. Pick a different one.", null, null)); } if (CleanUsername.Length < 3) { return(new Tuple <bool, string, string, UserKey>(false, "Username is too short. Pick a different one.", null, null)); } if (CleanId.Length != 36) { return(new Tuple <bool, string, string, UserKey>(false, "User ID is invalid. Pick a different one.", null, null)); } UserKeys[CleanId] = userKey; Usernames[CleanUsername] = id; return(new Tuple <bool, string, string, UserKey>(true, "Success", CleanId, new UserKey(CleanUsername, userKey.Publickey))); }
public IActionResult Edit(string id) { if (!string.IsNullOrWhiteSpace(id)) { var key = new UserKey() { Id = id }; var user = _usersService.GetUser(key); if (user != null) { var viewModel = new UserViewModel() { Id = user.Id, Name = user.Name, Email = user.Email, RegistrationDate = user.RegistrationDate, LastLoginDate = user.LastLoginDate, Suspended = user.Suspended }; if (user.Role != null) { viewModel.RoleId = user.Role.Id; } // Populate SelectListItem of roles ViewBag.Roles = ControllerUtils.CreateSelectRoleItemList(_rolesService.FindRoles(), user.Id); return(View(viewModel)); } } return(RedirectToAction("Index")); }
public void Two_different_keys() { var one = new UserKey("one"); var two = new UserKey("two"); one.ShouldNotBe(two); }
public void Two_keys_with_different_values_by_case() { var one = new UserKey("one"); var two = new UserKey("ONE"); one.ShouldBe(two); }
public void UpdateToken(DalsaeUserInfo userinfo) { User user = userinfo.user; if (switter.dicUserKey.ContainsKey(user.id) == false) { UserKey key = new UserKey(); key.id = user.id; key.Token = userinfo.Token; key.TokenSecret = userinfo.TokenSecret; key.screen_name = user.screen_name; switter.dicUserKey.Add(user.id, key); switter.selectAccount = key; } else { switter.dicUserKey[user.id].screen_name = user.screen_name; } SaveSwitter(); //string json = JsonConvert.SerializeObject(switter); //if (string.IsNullOrEmpty(json)) return; //using (FileStream fs = new FileStream(userFilePath, FileMode.Create)) //using (StreamWriter writer = new StreamWriter(fs)) //{ // writer.Write(json); // writer.Flush(); //} //File.WriteAllText(userFilePath, json); }
public static void UserTraceEx(UserKey userKey, string msg, EvUserTraceMsgType type) { Yodiwo.YEventRouter.EventRouter.TriggerEvent <EvUserTrace>(null, new EvUserTrace() { Timestamp = DateTime.UtcNow, UserKey = userKey, Msg = msg, MsgType = type }); }
public override async Task <PasswordResetCode> CreatePasswordResetCode(UserKey userKey) { this.CreatePasswordResetCode_InputUserKey = userKey; this.CreatePasswordResetCode_Output = await base.CreatePasswordResetCode(userKey); return(this.CreatePasswordResetCode_Output); }
private async void AuthorizationTokenChanged(object sender, EventArgs e) { string UserKey; string ElementKey; string ExtraThing; UserKey = txtUserKey.Text; ElementKey = txtElementKey.Text; ExtraThing = txtExtraThing.Text; if ((UserKey.Trim().Length > 0) && (ElementKey.Trim().Length > 0)) { APIAuthorization = new Cloud_Elements_API.CloudAuthorization(ElementKey, UserKey); if (ExtraThing.Trim().Length > 0) { APIAuthorization.ExtraValue = ExtraThing; } UIState(false); await PingService(); tsBtnPing.Enabled = true; } else { StatusMsg("Both secrets are required"); } }
private void Seed() { lock (_lock) { if (!_databaseInitialized) { using (var context = CreateContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var firstBook = new Book { Author = "Повар", FileName = "книга повара.txt", Id = 10, Name = "Книга повара" }; var secondBook = new Book { Author = "Повар2", FileName = "книга повара2.txt", Id = 100, Name = "Книга повара2" }; var key = new UserKey { Key = "somesuccesskey", Username = "******" }; context.AddRange(firstBook, secondBook, key); context.SaveChanges(); } _databaseInitialized = true; } } }
public override int GetHashCode() { int hash = 1; if (Id != 0L) { hash ^= Id.GetHashCode(); } if (FieldKey.Length != 0) { hash ^= FieldKey.GetHashCode(); } if (UserKey.Length != 0) { hash ^= UserKey.GetHashCode(); } if (Description.Length != 0) { hash ^= Description.GetHashCode(); } if (FieldSize != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(FieldSize); } if (IsActive != false) { hash ^= IsActive.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private async Task GetUserDetails(IOwinContext context) { var key = new UserKey(context.GetRouteValue("key")); var user = _collectionsReadModel.Users.Single(r => r.Key == key); await context.WriteJson(user, _settings); }
/// <summary> /// Creates a new <see cref="UserKeyAuthorization"/> entry for a user key and a particular archive. /// </summary> /// <param name="friendlyName">A friendly name to help the user identify the key.</param> /// <param name="userKey">The <see cref="UserKey"/> to authorize.</param> /// <param name="archiveKey">The key used to encrypt the archive that the user key is being authorized for.</param> /// <param name="securitySettings">The archive's <see cref="SecuritySettings"/>.</param> /// <returns>The new <see cref="UserKeyAuthorization"/> entry.</returns> public static UserKeyAuthorization CreateNewAuthorization( UserKeyAuthorizationParameters newKeyParams, ReadOnlySpan <byte> keyDerivationSalt, ArchiveKey archiveKey, SecuritySettings securitySettings) { ArgCheck.IsValid(newKeyParams, nameof(newKeyParams)); ArgCheck.NotEmpty(keyDerivationSalt, nameof(keyDerivationSalt)); ArgCheck.NotNull(archiveKey, nameof(archiveKey)); ArgCheck.IsValid(securitySettings, nameof(securitySettings)); using var userKey = UserKey.DeriveFrom( newKeyParams.UserSecret, keyDerivationSalt, securitySettings); // The SecureArchive file format requires that the friendly name and keyId be // checked for tampering when using authenticated cyphers. var additionalData = Encoding.UTF8.GetBytes(newKeyParams.FriendlyName + userKey.KeyId); var cryptoStrategy = CryptoHelpers.GetCryptoStrategy(securitySettings.EncryptionAlgo); var encryptedArchiveKey = userKey.EncryptSecret(cryptoStrategy, archiveKey, additionalData); return(new UserKeyAuthorization { AuthorizationId = Guid.NewGuid(), FriendlyName = newKeyParams.FriendlyName, KeyId = userKey.KeyId, TimeAdded = DateTime.UtcNow, EncryptedArchiveKey = encryptedArchiveKey, SecretMetadata = newKeyParams.SecretMetadata, }); }
public void Two_keys_with_same_value() { var one = new UserKey("one"); var two = new UserKey("one"); one.ShouldBe(two); }
/// <summary> /// 登录凭证校验 /// </summary> /// <param name="code">临时登录凭证code</param> /// <returns></returns> private UserKey _getWxProof(string code) { try { JsonData WeChatConfig = AppConfig.Configs["PrjectConfig"]["WeChat"]; string ApiUrl = $"https://api.weixin.qq.com/sns/jscode2session?appid={WeChatConfig["AppID"]}&secret={WeChatConfig["AppSecret"]}&js_code={code}&grant_type={WeChatConfig["GrantType"]}"; //请求失败重试,三次后放弃 string GetResult = ""; for (int i = 0; i < 3; i++) { try { GetResult = HttpHelper.Request(ApiUrl); if (!string.IsNullOrEmpty(GetResult)) { break; } } catch (Exception) { continue; } } UserKey Result = JsonHelper.ParseFormJson <UserKey>(GetResult); if (Result != null) { return(Result); } throw new Exception("获取用户信息失败"); } catch (Exception e) { throw e; } }
private void Delete() { var keys = UserContext.Current.ApiKeys; if (UserKey == null) { return; } if (!UserKey.Delete(UserContext.Current).IsSuccess) { StatusText = "Unable to remove this key."; StatusResult = false; return; } keys.Remove(UserKey); UserKey = null; ApiKey = null; ApiSecret = null; ApiExtra1 = null; ApiName = null; StatusText = "Key removed."; StatusResult = true; }
protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken) { // Inputs var timeout = TimeoutMS.Get(context); var orchestratorName = OrchestratorName.Get(context); var clientID = ClientID.Get(context); var userKey = UserKey.Get(context); var tenantName = TenantName.Get(context); var existingAccessToken = ExistingAccessToken.Get(context); // Set a timeout on the execution var task = ExecuteWithTimeout(context, cancellationToken); if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task) { throw new TimeoutException(Resources.Timeout_Error); } await task; return((ctx) => { // Schedule child activities if (Body != null) { ctx.ScheduleAction <IObjectContainer>(Body, _objectContainer, OnCompleted, OnFaulted); } // Outputs AccessToken.Set(ctx, null); }); }
public UserCreatedEvent(Operator @operator, Guid id, UserKey key, string name) : base(@operator) { ID = id; Key = key; Name = name; }
/// <summary> /// Gets a specific access for a user. /// </summary> /// <param name="aUserKey">A user key composite.</param> /// <param name="aFunction">A function.</param> /// <returns></returns> public static Access GetAccess(UserKey aUserKey, string aFunction) { UserFunctionAccess vUserFunctionAccess = new UserFunctionAccess() { UsrKey = aUserKey.UsrKey }; vUserFunctionAccess.FunctionAccess.Function = aFunction; Load(vUserFunctionAccess); return vUserFunctionAccess.FunctionAccess.Access; }
public void UserKeyTest() { var store = CreateStore(); var user = CreateTestUser(); try { var item = new UserKey(); item.EventDateDateTime = new DateTime(2015, 12, 23, 1, 2, 3); item.Number = "Number"; item.PrivateKeyData = "PrivateKeyData"; item.PublicKeyData = "PublicKeyData"; item.UserIDGuid = user.UserIDGuid; item.IsActivatedBool = true; store.SaveUserKey(item); var savedItem = store.GetUserKey(item.UserKeyIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(item.EventDate, savedItem.EventDate); Assert.AreEqual(item.IsActivated, savedItem.IsActivated); Assert.AreEqual(item.Number, savedItem.Number); Assert.AreEqual(item.PrivateKeyData, savedItem.PrivateKeyData); Assert.AreEqual(item.PublicKeyData, savedItem.PublicKeyData); Assert.AreEqual(item.UserID, savedItem.UserID); item.EventDateDateTime = new DateTime(2016, 11, 15); item.Number = "Number2"; item.PrivateKeyData = "PrivateKeyData3"; item.PublicKeyData = "PublicKeyData4"; item.IsActivatedBool = false; store.SaveUserKey(item); savedItem = store.GetUserKey(item.UserKeyIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(item.EventDate, savedItem.EventDate); Assert.AreEqual(item.Number, savedItem.Number); Assert.AreEqual(item.PrivateKeyData, savedItem.PrivateKeyData); Assert.AreEqual(item.PublicKeyData, savedItem.PublicKeyData); Assert.AreEqual(item.UserID, savedItem.UserID); Assert.AreEqual(item.IsActivated, savedItem.IsActivated); store.DeleteUserKey(savedItem.UserKeyIDGuid); savedItem = store.GetUserKey(item.UserKeyIDGuid); Assert.IsNull(savedItem); } finally { DeleteTestUser(); } }
public async Task WhenCalled_Returns6DigitVerificationToken() { var userKey = new UserKey("1"); var token = await new FakeUserHelper1().CreateEmailVerificationCode(userKey); Assert.Equal(6, token.Value.ToString().Length); }
public async Task ValidUserKey_Returns6CharacterResetCode() { var userKey = new UserKey("key"); var code = await new FakeUserHelper1().CreatePasswordResetCode(userKey); Assert.Equal(6, code.Value.ToString().Length); }
public void When_serializing() { var input = new UserKey("one"); var json = JsonConvert.SerializeObject(input); var output = JsonConvert.DeserializeObject<UserKey>(json); output.ShouldBe(input); }
public async Task ValidUserKey_ReturnsResetCode() { var userKey = new UserKey("key"); var code = await new FakeUserHelper1().CreatePasswordResetCode(userKey); Assert.NotNull(code); }
public virtual Task <bool> ValidateEmailVerificationCode(UserKey userKey, VerificationCode code) { Guard.Null(nameof(userKey), userKey); Guard.Null(nameof(code), code); return(this.SingleUseTokenService.Validate( CreateSingleUseToken("em", userKey, code))); }
public override async Task <VerificationCode> CreateEmailVerificationCode( UserKey userKey) { this.CreateEmailVerificationCode_InputUserKey = userKey; this.CreateEmailVerificationCode_Output = await base.CreateEmailVerificationCode( userKey); return(this.CreateEmailVerificationCode_Output); }
internal User GetUser(UserKey key, bool manageRole = true) { User user = _userModule.Get(key); if(user != null && manageRole) CompleteUserRole(user); return user; }
public virtual Task <bool> ValidatePasswordResetCode(UserKey userKey, PasswordResetCode code) { Guard.Null(nameof(userKey), userKey); Guard.Null(nameof(code), code); return(this.SingleUseTokenService.Validate( CreateSingleUseToken("pw", userKey, code))); }
public async Task WhenCalled_ReturnsVerificationCode() { var helper = new FakeUserHelper1(); var userKey = new UserKey("1"); var token = await helper.CreateEmailVerificationCode(userKey); Assert.NotNull(token); }
public override string ToString() { var sb = new StringBuilder(); sb.Append(UserKey.ToString()); sb.Append(Value.ToString()); sb.Append(Hash); return(sb.ToString()); }
protected virtual SingleUseToken CreateSingleUseToken(string prefix, UserKey userKey, VerificationCode code) { Guard.NullOrWhiteSpace(nameof(prefix), prefix); Guard.Null(nameof(userKey), userKey); Guard.Null(nameof(code), code); return(new SingleUseToken($"{prefix}-{userKey.Value}-{code.Value}")); }
protected override Message CreateFirstMessage() { string Id = UserResourceManager.GetInstance().GetUserId(true); string User = UserResourceManager.GetInstance().Username; UserKey uKey = new UserKey(User, Key); Message m = new RegisterKeyRequest(Id, uKey); return(m); }
public override Task <bool> ValidateEmailVerificationCode(UserKey userKey, VerificationCode code) { this.ValidateEmailVerificationCode_InputUserKey = userKey; this.ValidateEmailVerificationCode_InputCode = code; return(!this.ValidateEmailVerificationCode_OutputOverride.HasValue ? base.ValidateEmailVerificationCode(userKey, code) : Task.FromResult(this.ValidateEmailVerificationCode_OutputOverride.Value)); }
public async Task WhenCalled_SetsExpirationTo7Days() { var helper = new FakeUserHelper1(); var userKey = new UserKey("1"); var code = await helper.CreateEmailVerificationCode(userKey); Assert.Equal(helper.FakeClock.UtcNow.AddDays(7), helper.FakeSingleUseTokenService.Create_InputExpiration); }
/// <summary> /// Unlocks (i.e. decrypts) the archive with the given raw user secret. /// </summary> /// <param name="userSecret">The user secret to use to unlock the archive.</param> public void Unlock(RawUserSecret userSecret) { ArgCheck.NotNull(userSecret, nameof(userSecret)); using var userKey = UserKey.DeriveFrom( userSecret, this.ArchiveMetadata.KeyDerivationSalt.ToArray(), this.ArchiveMetadata.SecuritySettings); this.Unlock(userKey); }
public override Task <bool> ValidatePasswordResetCode(UserKey userKey, PasswordResetCode code) { this.ValidatePasswordResetCode_InputUserKey = userKey; this.ValidatePasswordResetCode_InputCode = code; return(!this.ValidatePasswordResetCode_OutputOverride.HasValue ? base.ValidatePasswordResetCode(userKey, code) : Task.FromResult(this.ValidatePasswordResetCode_OutputOverride.Value)); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { var o = obj as TraderInfo; if (o == null) { return(false); } return(UserKey.Equals(o.UserKey) && MobilePhone.Equals(o.MobilePhone)); }
/// <summary> /// The <c>AddRoleFunction</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="RoleFunction"/> object. /// It invokes the <c>Insert</c> method of <see cref="RoleFunctionBusiness"/> with the newly deserialized <see cref="RoleFunction"/> object. /// Finally, it returns the inserted object (now with an assigned RoleFunction Key) as a serialized <see cref="string"/> of XML. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns><see cref="RoleFunction"/> as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string AddRoleFunction(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddRoleFunction"); } RoleFunction vRoleFunction = new RoleFunction(); vRoleFunction = XmlUtils.Deserialize<RoleFunction>(aXmlArgument); RoleFunctionBusiness.Insert(aUserKey, vRoleFunction); return XmlUtils.Serialize<RoleFunction>(vRoleFunction, true); }
/// <summary> /// The <c>AddUser</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="User"/> object. /// It invokes the <c>Insert</c> method of <see cref="UserBusiness"/> with the newly deserialized <see cref="User"/> object. /// Finally, it returns the inserted object (now with an assigned User Key) as a serialized <see cref="string"/> of XML. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns><see cref="User"/> as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string AddUser(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddUser"); } User vUser = new User(); vUser = XmlUtils.Deserialize<User>(aXmlArgument); UserBusiness.Insert(aUserKey, vUser); return XmlUtils.Serialize<User>(vUser, true); }
/// <summary> /// The <c>AddDocument</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Document"/> object. /// It invokes the <c>Insert</c> method of <see cref="DocumentBusiness"/> with the newly deserialized <see cref="Document"/> object. /// Finally, it returns the inserted object (now with an assigned Document Key) as a serialized <see cref="string"/> of XML. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns><see cref="Document"/> as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string AddDocument(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddDocument"); } Document vDocument = new Document(); vDocument = XmlUtils.Deserialize<Document>(aXmlArgument); DocumentBusiness.Insert(aUserKey, vDocument); return XmlUtils.Serialize<Document>(vDocument, true); }
/// <summary> /// The <c>AddContributor</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Contributor"/> object. /// It invokes the <c>Insert</c> method of <see cref="ContributorBusiness"/> with the newly deserialized <see cref="Contributor"/> object. /// Finally, it returns the inserted object (now with an assigned Contributor Key) as a serialized <see cref="string"/> of XML. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns><see cref="Contributor"/> as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string AddContributor(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddContributor"); } Contributor vContributor = new Contributor(); vContributor = XmlUtils.Deserialize<Contributor>(aXmlArgument); ContributorBusiness.Insert(aUserKey, vContributor); return XmlUtils.Serialize<Contributor>(vContributor, true); }
/// <summary> /// The <c>AddContributorLanguage</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="ContributorLanguage"/> object. /// It invokes the <c>Insert</c> method of <see cref="ContributorLanguageBusiness"/> with the newly deserialized <see cref="ContributorLanguage"/> object. /// Finally, it returns the inserted object (now with an assigned ContributorLanguage Key) as a serialized <see cref="string"/> of XML. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns><see cref="ContributorLanguage"/> as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string AddContributorLanguage(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of AddContributorLanguage"); } ContributorLanguage vContributorLanguage = new ContributorLanguage(); vContributorLanguage = XmlUtils.Deserialize<ContributorLanguage>(aXmlArgument); ContributorLanguageBusiness.Insert(aUserKey, vContributorLanguage); return XmlUtils.Serialize<ContributorLanguage>(vContributorLanguage, true); }
/// <summary> /// Delete data in database /// </summary> /// <param name="key">Primary Key</param> public void Delete(UserKey key) { if (key == null || string.IsNullOrWhiteSpace(key.Id)) return; var row = _dbContext.Users.Where(m => m.Id == key.Id).FirstOrDefault(); if (row != null) { _dbContext.Users.Remove(row); _dbContext.SaveChanges(); } }
/// <summary> /// Insert a <see cref="Client"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Client Key</i>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aClient">A <see cref="Client"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aClient</c> argument is <c>null</c>.</exception> public static void Insert(UserKey aUserKey, Client aClient) { if (aClient == null) { throw new ArgumentNullException("Insert Client Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Client", AccessMode.Create)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Create, "Client"); } ClientData.Insert(aClient); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Document"/> object, with keys in <c>aDocument</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aDocument">A <see cref="Document"/>.</param> /// <exception cref="ArgumentNullException">If <c>aDocument</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, Document aDocument) { if (aDocument == null) { throw new ArgumentNullException("Load Document Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Document", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Document"); } DocumentData.Load(aDocument); }
/// <summary> /// Insert a <see cref="Role"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Role Key</i>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aRole">A <see cref="Role"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aRole</c> argument is <c>null</c>.</exception> public static void Insert(UserKey aUserKey, Role aRole) { if (aRole == null) { throw new ArgumentNullException("Insert Role Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Role", AccessMode.Create)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Create, "Role"); } RoleData.Insert(aRole); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Function"/> object, with keys in <c>aFunction</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aFunction">A <see cref="Function"/>.</param> /// <exception cref="ArgumentNullException">If <c>aFunction</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, Function aFunction) { if (aFunction == null) { throw new ArgumentNullException("Load Function Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Function", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Function"); } FunctionData.Load(aFunction); }
/// <summary> /// The overloaded Load method that will return a <see cref="JobTypeCollection"/>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aJobTypeCollection">A <see cref="JobTypeCollection"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aJobTypeCollection</c> argument is <c>null</c>.</exception> public static void Load(UserKey aUserKey, JobTypeCollection aJobTypeCollection) { if (aJobTypeCollection == null) { throw new ArgumentNullException("Load JobType Business"); } //if (!UserFunctionAccessData.HasModeAccess(aUserKey, "JobType", AccessMode.List)) //{ // throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.List, "JobType"); //} JobTypeData.Load(aJobTypeCollection); }
/// <summary> /// Delete a <see cref="RoleFunction"/> object passed as an argument. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aRoleFunction">A <see cref="RoleFunction"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aRoleFunction</c> argument is <c>null</c>.</exception> public static void Delete(UserKey aUserKey, RoleFunction aRoleFunction) { if (aRoleFunction == null) { throw new ArgumentNullException("Delete RoleFunction Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "RoleFunction", AccessMode.Delete)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Delete, "RoleFunction"); } RoleFunctionData.Delete(aRoleFunction); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="UserRole"/> object, with keys in <c>aUserRole</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aUserRole">A <see cref="UserRole"/>.</param> /// <exception cref="ArgumentNullException">If <c>aUserRole</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, UserRole aUserRole) { if (aUserRole == null) { throw new ArgumentNullException("Load UserRole Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "UserRole", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "UserRole"); } UserRoleData.Load(aUserRole); }
/// <summary> /// Delete a <see cref="JobType"/> object passed as an argument. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aJobType">A <see cref="JobType"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aJobType</c> argument is <c>null</c>.</exception> public static void Delete(UserKey aUserKey, JobType aJobType) { if (aJobType == null) { throw new ArgumentNullException("Delete JobType Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "JobType", AccessMode.Delete)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Delete, "JobType"); } JobTypeData.Delete(aJobType); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="WorkItem"/> object, with keys in <c>aWorkItem</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aWorkItem">A <see cref="WorkItem"/>.</param> /// <exception cref="ArgumentNullException">If <c>aWorkItem</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, WorkItem aWorkItem) { if (aWorkItem == null) { throw new ArgumentNullException("Load WorkItem Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "WorkItem", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "WorkItem"); } WorkItemData.Load(aWorkItem); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Job"/> object, with keys in <c>aJob</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aJob">A <see cref="Job"/>.</param> /// <exception cref="ArgumentNullException">If <c>aJob</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, Job aJob) { if (aJob == null) { throw new ArgumentNullException("Load Job Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Job", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Job"); } JobData.Load(aJob); }
/// <summary> /// The overloaded Load method that will return a <see cref="ClientCollection"/>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aClientCollection">A <see cref="ClientCollection"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aClientCollection</c> argument is <c>null</c>.</exception> public static void Load(UserKey aUserKey, ClientCollection aClientCollection) { if (aClientCollection == null) { throw new ArgumentNullException("Load Client Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Client", AccessMode.List)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.List, "Client"); } ClientData.Load(aClientCollection); }
/// <summary> /// Delete a <see cref="User"/> object passed as an argument. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aUser">A <see cref="User"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aUser</c> argument is <c>null</c>.</exception> public static void Delete(UserKey aUserKey, User aUser) { if (aUser == null) { throw new ArgumentNullException("Delete User Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "User", AccessMode.Delete)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Delete, "User"); } UserData.Delete(aUser); }
/// <summary> /// Insert a <see cref="Contributor"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Contributor Key</i>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aContributor">A <see cref="Contributor"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aContributor</c> argument is <c>null</c>.</exception> public static void Insert(UserKey aUserKey, Contributor aContributor) { if (aContributor == null) { throw new ArgumentNullException("Insert Contributor Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Contributor", AccessMode.Create)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Create, "Contributor"); } ContributorData.Insert(aContributor); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="ContributorLanguage"/> object, with keys in <c>aContributorLanguage</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aContributorLanguage">A <see cref="ContributorLanguage"/>.</param> /// <exception cref="ArgumentNullException">If <c>aContributorLanguage</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, ContributorLanguage aContributorLanguage) { if (aContributorLanguage == null) { throw new ArgumentNullException("Load ContributorLanguage Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "ContributorLanguage", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "ContributorLanguage"); } ContributorLanguageData.Load(aContributorLanguage); }
/// <summary> /// The overloaded Load method that will return a <see cref="LanguageCollection"/>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aLanguageCollection">A <see cref="LanguageCollection"/> object.</param> /// <exception cref="ArgumentNullException">If <c>aLanguageCollection</c> argument is <c>null</c>.</exception> public static void Load(UserKey aUserKey, LanguageCollection aLanguageCollection) { if (aLanguageCollection == null) { throw new ArgumentNullException("Load Language Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Language", AccessMode.List)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.List, "Language"); } LanguageData.Load(aLanguageCollection); }
/// <summary> /// Get data in database /// </summary> /// <param name="key">Primary Key</param> /// <returns>read data</returns> public User Get(UserKey key) { if (key == null || string.IsNullOrWhiteSpace(key.Id)) return null; User user = null; ApplicationUser row = _dbContext.Users.Where(m => m.Id == key.Id).FirstOrDefault(); if (row != null) { user = UserTransformer.ToBean(row); } return user; }