using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using InABox.Clients;
using InABox.Core;
using InABox.DynamicGrid;
namespace PRSDesktop
{
///
/// Interaction logic for SecurityTokenPanel.xaml
///
public partial class GroupTokenPage : UserControl, IDynamicCustomEditorPage
{
public GroupTokenPage()
{
InitializeComponent();
}
public bool Ready { get; set; }
public PageType PageType => PageType.Other;
public DynamicEditorGrid EditorGrid { get; set; }
public bool ReadOnly { get; set; }
public void AfterSave(object item)
{
var updates = new List();
var deletes = new List();
foreach (var token in grid.Tokens)
{
var gti = grid.Items.FirstOrDefault(x => x.Code.Equals(token.Descriptor));
if (gti != null)
{
if (gti.HasValue)
{
if (token.IsChanged())
updates.Add(token);
}
else
{
if (token.ID != Guid.Empty)
deletes.Add(token);
}
}
}
if (updates.Any())
new Client().Save(updates, "");
foreach (var delete in deletes)
new Client().Delete(delete, "");
}
public void BeforeSave(object item)
{
}
public string Caption()
{
return "Security Tokens";
}
public void Load(object item, Func? PageDataHandler)
{
var group = item as SecurityGroup;
grid.GroupID = group.ID;
grid.Refresh(true, true);
Ready = true;
}
public Size MinimumSize()
{
return new Size(300, 600);
}
public int Order()
{
return 0;
}
public event EventHandler? OnChanged;
public void DoChanged()
{
OnChanged?.Invoke(this, EventArgs.Empty);
}
}
}