public async Task ChangePassword(string userName, string currentPassword, string newPassword, bool forceReset)
        {
            AecUser user = await _userManager.FindByNameAsync(userName);

            if (null == user)
            {
                throw new NotFoundException();
            }
            if (user.IsBooking)
            {
                throw new InvalidOperationException("This operation can't be used to change the PIN code of a booking.");
            }

            IdentityResult result;

            if (forceReset)
            {
                var token = await _userManager.GeneratePasswordResetTokenAsync(user.Id);

                result = await _userManager.ResetPasswordAsync(user.Id, token, newPassword);
            }
            else
            {
                result = await _userManager.ChangePasswordAsync(user.Id, currentPassword, newPassword);
            }

            if (!result.Succeeded)
            {
                string message = string.Join(Environment.NewLine, result.Errors);
                throw new InvalidOperationException(message);
            }
        }
Esempio n. 2
0
        public async Task DeleteAsync(Booking booking)
        {
            AecUser user = await _userManager.FindByNameAsync(booking.Reference);

            if (null != user && user.IsBooking)
            {
                await _userManager.DeleteAsync(user);
            }

            await _deletedBookingRepository.CreateAsync(booking);

            using (var db = DbUtil.Open())
                await db.ExecuteAsync("delete from [Booking] where [Id] = @Id", new { Id = booking.Id });
        }