diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs index b41d572..86c3d8c 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Models/Device.cs @@ -1,6 +1,8 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Net; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.AspNetCore.Server.IIS.Core; namespace Elektrifikatsiya.Models; @@ -35,5 +37,17 @@ public class Device Room = room; } + public static Device CopyDevice(Device device) => new Device(device.MacAddress, device.Name, device.IpAddress, device.User, device.Room); + + public void OverwiteDevice(Device overwriter) + { + this.Room = overwriter.Room; + this.Available = overwriter.Available; + this.PowerUsage = overwriter.PowerUsage; + this.Name = overwriter.Name; + this.User = overwriter.User; + this.MacAddress = overwriter.MacAddress; + this.IpAddress = overwriter.IpAddress; + } private Device(){} } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index a09d7f5..70a9522 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -5,6 +5,7 @@ @using Elektrifikatsiya.Services @using Elektrifikatsiya.Utilities @using System.Diagnostics +@using Elektrifikatsiya.Services.Implementations @inject IVersionProvider VersionProvider @inject IDeviceStatusService DeviceStatusService; diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor index 46f8278..60e82b6 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor @@ -2,6 +2,13 @@ @using Blazorise.Components; @using Elektrifikatsiya.Models; @using System.Net +@using System.Text.Json +@using Elektrifikatsiya.Services.Implementations +@using Elektrifikatsiya.Services; +@using FluentResults + +@inject IDeviceManagmentService DeviceManagmentService +
@@ -34,7 +41,7 @@ - User: @context.Item.User + User: @context.Item.User.Name
Room: @context.Item.Room
@@ -43,14 +50,14 @@

- @@ -62,6 +69,9 @@ + + @if (DeviceCopy is not null) + { + } - +
+ @code { - List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "Josne", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; + List plugs = new List(); private bool hideButtonSettings = true; - private void Toggle() + Device? SelectedDevice = null; + Device? DeviceCopy = null; + + protected override void OnInitialized() + { + Result> getDevicesResult = DeviceManagmentService.GetDevices(); + + if (getDevicesResult.IsSuccess) + { + plugs = getDevicesResult.Value; + } + } + + private void Toggle(Device device) { hideButtonSettings = !hideButtonSettings; + SelectedDevice = device; + DeviceCopy = Device.CopyDevice(device); } + + private void OnSave() + { + if (hideButtonSettings || DeviceCopy is null) + { + + } + else + { + SelectedDevice.OverwiteDevice(DeviceCopy); + DeviceManagmentService.UpdateDevice(SelectedDevice); + } + } + + private void Delete(Device contextItem) + { + DeviceManagmentService.UnregisterDevice(contextItem.MacAddress); + } + } \ No newline at end of file