-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from CUMGroup/delete-db
Delete db
- Loading branch information
Showing
11 changed files
with
147 additions
and
16 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
PWManager.Application/Abstractions/Interfaces/IDeleteDataContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PWManager.Application.Abstractions.Interfaces; | ||
|
||
public interface IDeleteDataContext { | ||
|
||
void DeleteDataContext(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using PWManager.Application.Abstractions.Interfaces; | ||
using PWManager.Application.Context; | ||
using PWManager.Application.Exceptions; | ||
using PWManager.Application.Services.Interfaces; | ||
using PWManager.CLI.Abstractions; | ||
using PWManager.CLI.Attributes; | ||
using PWManager.CLI.Enums; | ||
using PWManager.CLI.Interfaces; | ||
|
||
namespace PWManager.CLI.Controllers; | ||
|
||
[SessionOnly] | ||
public class DeleteDatabaseController : IController { | ||
|
||
private readonly IDeleteDataContext _dataContextDeleter; | ||
private readonly ILoginService _loginService; | ||
private readonly IUserEnvironment _userEnv; | ||
|
||
public DeleteDatabaseController(IDeleteDataContext dataContextDeleter, ILoginService loginService, IUserEnvironment userEnv) { | ||
_dataContextDeleter = dataContextDeleter; | ||
_loginService = loginService; | ||
_userEnv = userEnv; | ||
} | ||
|
||
public ExitCondition Handle(string[] args) { | ||
|
||
if (!ConfirmPassword()) { | ||
return ExitCondition.CONTINUE; | ||
} | ||
|
||
try { | ||
_dataContextDeleter.DeleteDataContext(); | ||
} | ||
catch(UserFeedbackException ex) { | ||
PromptHelper.PrintColoredText(ConsoleColor.Red, ex.Message); | ||
return ExitCondition.EXIT; | ||
} | ||
|
||
try { | ||
ConfigFileHandler.DeleteDefaultFile(); | ||
} | ||
catch (UserFeedbackException ex) { | ||
PromptHelper.PrintColoredText(ConsoleColor.Red, ex.Message); | ||
} | ||
|
||
PromptHelper.PrintColoredText(ConsoleColor.Cyan, UIstrings.DATABASE_DELETED); | ||
|
||
return ExitCondition.EXIT; | ||
} | ||
|
||
private bool ConfirmPassword() { | ||
if (_userEnv.CurrentUser is null) { | ||
throw new ApplicationException(MessageStrings.NO_ACTIVE_USER); | ||
} | ||
var username = _userEnv.CurrentUser.UserName; | ||
return PromptHelper.ConfirmDeletion(UIstrings.YOUR_DATABASE, (pw) => _loginService.CheckPassword(username, pw)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters