/// <summary> /// Resets the password for the user related to the password token specified to the newPassword specified /// It'll then remove the password reset token entity specified /// </summary> /// <param name="newPassword">the new password specified</param> /// <param name="passwordResetToken">the reset token. Will be removed in this method if password reset is successful</param> /// <returns>true if successful, false otherwise</returns> public static async Task <bool> ResetPasswordAsync(string newPassword, PasswordResetTokenEntity passwordResetToken) { if (string.IsNullOrWhiteSpace(newPassword) || passwordResetToken == null) { return(false); } using (var adapter = new DataAccessAdapter()) { var q = new QueryFactory().User.Where(UserFields.UserID.Equal(passwordResetToken.UserID)); var user = await adapter.FetchFirstAsync(q).ConfigureAwait(false); if (user == null) { return(false); } user.Password = HnDGeneralUtils.HashPassword(newPassword, performPreMD5Hashing: true); var uow = new UnitOfWork2(); uow.AddForSave(user); uow.AddForDelete(passwordResetToken); var toReturn = await uow.CommitAsync(adapter); return(toReturn == 2); } }
public void Delete(ProductLineEntity productLine) { if (productLine == null) { throw new ArgumentNullException(nameof(productLine), $"{nameof(productLine)} is null."); } // We'll have to delete the whole graph so first the related entities, then the main entity. // Let's use a Unit of work here for that. var uow = new UnitOfWork2(); uow.AddCollectionForDelete(productLine.Products); uow.AddForDelete(productLine); using (var adapter = new DataAccessAdapter()) { uow.Commit(adapter); } }