Update AddAlert params.

This commit is contained in:
Jared Goodwin 2020-03-25 08:09:37 -07:00
parent e6f32c30b4
commit bfc84be732
3 changed files with 21 additions and 20 deletions

View File

@ -40,14 +40,7 @@ namespace Remotely.Server.API
{
try
{
var alert = new Alert()
{
CreatedOn = DateTimeOffset.Now,
DeviceID = alertOptions.AlertDeviceID,
Message = alertOptions.AlertMessage,
OrganizationID = orgID
};
await DataService.AddAlert(alert);
await DataService.AddAlert(alertOptions, orgID);
}
catch (Exception ex)
{
@ -60,9 +53,9 @@ namespace Remotely.Server.API
try
{
await EmailSender.SendEmailAsync(alertOptions.EmailTo,
alertOptions.EmailSubject,
alertOptions.EmailBody,
orgID);
alertOptions.EmailSubject,
alertOptions.EmailBody,
orgID);
}
catch (Exception ex)
{

View File

@ -34,12 +34,21 @@ namespace Remotely.Server.Services
private ApplicationDbContext RemotelyContext { get; }
private UserManager<RemotelyUser> UserManager { get; }
public async Task AddAlert(Alert alert)
public async Task AddAlert(AlertOptions alertOptions, string organizationID)
{
await RemotelyContext.Users
.Include(x => x.Alerts)
.Where(x => x.OrganizationID == alert.OrganizationID)
.ForEachAsync(x => x.Alerts.Add(alert));
.Where(x => x.OrganizationID == organizationID)
.ForEachAsync(x => {
var alert = new Alert()
{
CreatedOn = DateTimeOffset.Now,
DeviceID = alertOptions.AlertDeviceID,
Message = alertOptions.AlertMessage,
OrganizationID = organizationID
};
x.Alerts.Add(alert);
});
await RemotelyContext.SaveChangesAsync();
}

View File

@ -156,14 +156,13 @@ namespace Remotely.Tests
[DoNotParallelize]
public async Task AddAlert()
{
var alert = new Alert()
var options = new AlertOptions()
{
DeviceID = TestData.Device1.ID,
OrganizationID = TestData.OrganizationID,
Message = "Test Message",
UserID = TestData.Admin1.Id
AlertDeviceID = TestData.Device1.ID,
AlertMessage = "Test Message",
ShouldAlert = true
};
await DataService.AddAlert(alert);
await DataService.AddAlert(options, TestData.OrganizationID);
}
}
}