no-more-circle-autorisation-to-file
This commit is contained in:
parent
5f12e17907
commit
6106cd4c7e
17 changed files with 2892 additions and 795 deletions
|
|
@ -16,11 +16,11 @@ namespace cli
|
|||
CommandArgument critCommandArg = null;
|
||||
CommandOption sendHelpOption = null;
|
||||
CommandLineApplication sendMailCommandApp
|
||||
= rootApp.Command("send-monthly",
|
||||
= rootApp.Command("send-email",
|
||||
(target) =>
|
||||
{
|
||||
target.FullName = "Send email";
|
||||
target.Description = "Sends monthly emails using given template from code";
|
||||
target.Description = "Sends emails using given template from code";
|
||||
sendHelpOption = target.HelpOption("-? | -h | --help");
|
||||
critCommandArg = target.Argument(
|
||||
"criteria",
|
||||
|
|
|
|||
|
|
@ -47,11 +47,23 @@ namespace cli.Commands
|
|||
ApplicationDbContext dbContext = app.Services.GetService<ApplicationDbContext>();
|
||||
Func<ApplicationUser, bool> criteria = UserPolicies.Criterias["user-to-remove"];
|
||||
|
||||
if (userManager==null)
|
||||
{
|
||||
logger.LogError("No user manager");
|
||||
throw new Exception("No user manager");
|
||||
}
|
||||
|
||||
logger.LogInformation("Starting emailling");
|
||||
mailer.SendEmailFromCriteria("user-to-remove");
|
||||
foreach (ApplicationUser user in dbContext.ApplicationUser.Where(
|
||||
u => criteria(u)
|
||||
))
|
||||
try {
|
||||
mailer.SendEmailFromCriteria("user-to-remove");
|
||||
}
|
||||
catch (NoMaillingTemplateException ex)
|
||||
{
|
||||
logger.LogWarning(ex.Message);
|
||||
}
|
||||
ApplicationUser [] users = dbContext.ApplicationUser.Where(
|
||||
u => criteria(u)).ToArray();
|
||||
foreach (ApplicationUser user in users)
|
||||
{
|
||||
dbContext.DeviceDeclaration.RemoveRange(dbContext.DeviceDeclaration.Where(g => g.DeviceOwnerId == user.Id));
|
||||
await userManager.DeleteAsync(user);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue