You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.5 KiB
79 lines
1.5 KiB
using System.ComponentModel.DataAnnotations; |
|
using DataType = Model.Entity.Data.DataType; |
|
|
|
namespace Services.Website; |
|
|
|
//TODO Move to a database folder, with EntityService, EntityFilterService |
|
public class EntityDialogService : IEntityDialogService |
|
{ |
|
private string? entityId = null; |
|
|
|
private List<string> history = new List<string>(); |
|
|
|
private event Action OnChange = null!; |
|
|
|
private void NotifyDataChanged() { |
|
OnChange?.Invoke(); |
|
} |
|
|
|
public void Subscribe(Action action) { |
|
OnChange += action; |
|
} |
|
|
|
public void Unsubscribe(Action action) { |
|
OnChange += action; |
|
} |
|
|
|
public void AddDialog(string id) |
|
{ |
|
entityId = id; |
|
history.Add(id); |
|
|
|
NotifyDataChanged(); |
|
} |
|
|
|
public void CloseDialog() |
|
{ |
|
entityId = null; |
|
history.Clear(); |
|
|
|
NotifyDataChanged(); |
|
} |
|
|
|
public void BackDialog() |
|
{ |
|
if (history.Count > 1) |
|
{ |
|
history.RemoveAt(history.Count - 1); |
|
|
|
if (history.Count == 0) |
|
{ |
|
entityId = null; |
|
NotifyDataChanged(); |
|
|
|
return; |
|
} |
|
|
|
entityId = history.Last(); |
|
NotifyDataChanged(); |
|
} |
|
} |
|
|
|
|
|
public bool HasDialog() |
|
{ |
|
return entityId != null; |
|
} |
|
|
|
public bool HasHistory() |
|
{ |
|
return history.Count > 1; |
|
} |
|
|
|
public string? GetEntityId() |
|
{ |
|
return entityId; |
|
} |
|
} |
|
|
|
|
|
|