Add to EditDevice InputModel.

This commit is contained in:
Jared Goodwin 2020-01-13 21:44:43 -08:00
parent eee02834e5
commit 7c0aba6162
5 changed files with 37 additions and 21 deletions

View File

@ -199,12 +199,12 @@ Below are examples of how to use the API for starting a remote control session.
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
 
$Response = Invoke-WebRequest -Uri "https://localhost:44351/api/Login" -WebSession $WebSession -Method Post -Body "
$Response = Invoke-WebRequest -Uri "https://localhost:44351/api/Login" -WebSession $WebSession -Method Post -Body '
{
'Email': 'email@example.com',
'Password': 'P@ssword1'
"Email": "email@example.com",
"Password": "P@ssword1"
}
" -ContentType "application/json"
' -ContentType "application/json"
if ($Response.StatusCode -eq 200) {

View File

@ -247,9 +247,6 @@ namespace Remotely.Server.Data
public bool DoesUserHaveAccessToDevice(string deviceID, RemotelyUser remotelyUser)
{
var targetDevice = RemotelyContext.Devices
.FirstOrDefault(x => x.ID == deviceID && x.OrganizationID == remotelyUser.OrganizationID);
return RemotelyContext.Devices.Any(x => x.ID == deviceID && x.OrganizationID == remotelyUser.OrganizationID);
}

View File

@ -54,6 +54,19 @@ else
<input type="text" class="form-control" asp-for="Input.Tags" />
</div>
</div>
<h5 class="mt-3">
Monitoring
</h5>
<div class="form-group row">
<label for="device-alias" class="col-sm-4 col-form-label">Alert if offline for:</label>
<div class="col-sm-4">
<input id="device-alias" type="text" class="form-control" asp-for="Input.AlertOfflineMinutes" />
</div>
<div class=" col-sm-2">
<span>minutes</span>
</div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-primary">Save</button>
<button type="submit" class="btn btn-secondary" onclick="window.close()">Close</button>

View File

@ -37,6 +37,19 @@ namespace Remotely.Server.Pages
PopulateViewModel(deviceID);
}
public IActionResult OnPost(string deviceID)
{
if (!ModelState.IsValid)
{
PopulateViewModel(deviceID);
return Page();
}
DataService.UpdateDevice(deviceID, Input.Tags, Input.Alias, Input.DeviceGroupID);
return RedirectToPage("EditDevice", new { deviceID, success = true });
}
private void PopulateViewModel(string deviceID)
{
var user = DataService.GetUserByName(User.Identity.Name);
@ -53,22 +66,14 @@ namespace Remotely.Server.Pages
var groups = DataService.GetDeviceGroupsForUserName(User.Identity.Name);
DeviceGroups.AddRange(groups.Select(x => new SelectListItem(x.Name, x.ID)));
}
public IActionResult OnPost(string deviceID)
{
if (!ModelState.IsValid)
{
PopulateViewModel(deviceID);
return Page();
}
DataService.UpdateDevice(deviceID, Input.Tags, Input.Alias, Input.DeviceGroupID);
return RedirectToPage("EditDevice", new { deviceID, success = true });
}
public class InputModel
{
public double? AlertOfflineMinutes { get; set; }
public double? AlertMemoryPercentage { get; set; }
public double? AlertSystemDrivePercentage { get; set; }
[StringLength(100)]
public string Alias { get; set; }

View File

@ -155,6 +155,7 @@ namespace Remotely.Server
services.AddScoped<IEmailSender, EmailSender>();;
services.AddScoped<DataService>();
services.AddScoped<RemoteControlSessionRecorder>();
services.AddScoped<DeviceAlertService>();
services.AddSingleton<ApplicationConfig>();
services.AddSingleton<RandomGenerator>();
}