| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Microsoft.Data.SqlClient;
- using Quadarax.Application.QLiberace.Base;
- using Quadarax.Application.QLiberace.Console.Commands.Base;
- using Quadarax.Foundation.Core.QConsole;
- using Quadarax.Foundation.Core.QConsole.Attributes;
- using Quadarax.Foundation.Core.Value;
- namespace Quadarax.Application.QLiberace.Console.Commands
- {
- [CommandDefinition]
- internal class DbClearCmd : DbContextCommand
- {
- #region *** Properties ***
- public override string Name => Constants.Commands.DbClear.Name;
- public override string Description => Constants.Commands.DbClear.Description;
-
- #endregion
- #region *** Fields ***
- #endregion
- #region *** Constructor ***
- public DbClearCmd(Engine engine) : base(engine)
- {
- }
- #endregion
-
- #region *** EXECUTE ***
- protected override Result OnExecute(QlbrcDbContext context)
- {
- WriteInfo("Connecting database...");
- var resultCode = 0;
- try
- {
- if (context.Database.CanConnect())
- {
- WriteInfo("Deleting database...");
- context.Database.EnsureDeleted();
- }
- WriteInfo("Creating database...");
- context.Database.EnsureCreated();
- }
- catch (SqlException e)
- {
- return HandleConnectionException(e);
- }
- return new Result(resultCode);
- }
-
- #endregion
- #region *** Private operations ***
- #endregion
- }
-
- }
|