initial load
This commit is contained in:
28
YouTubeViewers.WPF/Stores/ModalNavigationStore.cs
Normal file
28
YouTubeViewers.WPF/Stores/ModalNavigationStore.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Stores
|
||||
{
|
||||
public class ModalNavigationStore
|
||||
{
|
||||
private ViewModelBase _currentViewModel;
|
||||
|
||||
public ViewModelBase CurrentViewModel
|
||||
{
|
||||
get { return _currentViewModel; }
|
||||
set {
|
||||
_currentViewModel = value;
|
||||
CurrentViewModelChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOpen => CurrentViewModel != null;
|
||||
|
||||
public event Action CurrentViewModelChanged;
|
||||
|
||||
public void Close()
|
||||
{
|
||||
CurrentViewModel = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
YouTubeViewers.WPF/Stores/SelectedYouTubeViewerStore.cs
Normal file
43
YouTubeViewers.WPF/Stores/SelectedYouTubeViewerStore.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
|
||||
namespace YouTubeViewers.WPF.Stores
|
||||
{
|
||||
public class SelectedYouTubeViewerStore
|
||||
{
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
|
||||
public SelectedYouTubeViewerStore(YouTubeViewersStore youTubeViewersStore)
|
||||
{
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
_youTubeViewersStore.YouTubeViewerUpdated += YouTubeViewersStore_YouTubeViewerUpdated;
|
||||
}
|
||||
|
||||
private void YouTubeViewersStore_YouTubeViewerUpdated(YouTubeViewer youTubeViewer)
|
||||
{
|
||||
if (youTubeViewer.Id == SelectedYouTubeViewer?.Id)
|
||||
{
|
||||
SelectedYouTubeViewer = youTubeViewer;
|
||||
}
|
||||
}
|
||||
|
||||
private YouTubeViewer _selectedYouTubeViewer;
|
||||
|
||||
public YouTubeViewer SelectedYouTubeViewer
|
||||
{
|
||||
get { return _selectedYouTubeViewer; }
|
||||
set
|
||||
{
|
||||
_selectedYouTubeViewer = value;
|
||||
SelectedYouTubeViewerChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public event Action SelectedYouTubeViewerChanged;
|
||||
|
||||
}
|
||||
}
|
||||
88
YouTubeViewers.WPF/Stores/YouTubeViewersStore.cs
Normal file
88
YouTubeViewers.WPF/Stores/YouTubeViewersStore.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Commands;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.Domain.Queries;
|
||||
|
||||
namespace YouTubeViewers.WPF.Stores
|
||||
{
|
||||
public class YouTubeViewersStore
|
||||
{
|
||||
private readonly IGetAllYouTubeViewersQuery _getAllYouTubeViewersQuery;
|
||||
private readonly ICreateYouTubeViewerCommand _createYouTubeViewerCommand;
|
||||
private readonly IUpdateYouTubeViewerCommand _updateYouTubeViewerCommand;
|
||||
private readonly IDeleteYouTubeViewerCommand _deleteYouTubeViewerCommand;
|
||||
private readonly List<YouTubeViewer> _youTubeViewers;
|
||||
|
||||
public IEnumerable<YouTubeViewer> YouTubeViewers => _youTubeViewers;
|
||||
|
||||
public event Action YouTubeViewersLoaded;
|
||||
public event Action<YouTubeViewer> YouTubeViewerAdded;
|
||||
public event Action<YouTubeViewer> YouTubeViewerUpdated;
|
||||
public event Action<Guid> YouTubeViewerDeleted;
|
||||
|
||||
|
||||
public YouTubeViewersStore(
|
||||
IGetAllYouTubeViewersQuery getAllYouTubeViewersQuery,
|
||||
ICreateYouTubeViewerCommand createYouTubeViewerCommand,
|
||||
IUpdateYouTubeViewerCommand updateYouTubeViewerCommand,
|
||||
IDeleteYouTubeViewerCommand deleteYouTubeViewerCommand)
|
||||
{
|
||||
_getAllYouTubeViewersQuery = getAllYouTubeViewersQuery;
|
||||
_createYouTubeViewerCommand = createYouTubeViewerCommand;
|
||||
_updateYouTubeViewerCommand = updateYouTubeViewerCommand;
|
||||
_deleteYouTubeViewerCommand = deleteYouTubeViewerCommand;
|
||||
|
||||
_youTubeViewers = new List<YouTubeViewer>();
|
||||
}
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
IEnumerable<YouTubeViewer> youTubeViewers = await _getAllYouTubeViewersQuery.Execute();
|
||||
_youTubeViewers.Clear();
|
||||
_youTubeViewers.AddRange(youTubeViewers);
|
||||
|
||||
YouTubeViewersLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public async Task Add(YouTubeViewer youTubeViewer)
|
||||
{
|
||||
await _createYouTubeViewerCommand.Execute(youTubeViewer);
|
||||
|
||||
_youTubeViewers.Add(youTubeViewer);
|
||||
|
||||
YouTubeViewerAdded?.Invoke(youTubeViewer);
|
||||
}
|
||||
|
||||
public async Task Update(YouTubeViewer youTubeViewer)
|
||||
{
|
||||
await _updateYouTubeViewerCommand.Execute(youTubeViewer);
|
||||
|
||||
int currentIndex = _youTubeViewers.FindIndex(y => y.Id == youTubeViewer.Id);
|
||||
|
||||
if(currentIndex != -1)
|
||||
{
|
||||
_youTubeViewers[currentIndex] = youTubeViewer;
|
||||
}
|
||||
else
|
||||
{
|
||||
_youTubeViewers.Add(youTubeViewer);
|
||||
}
|
||||
|
||||
YouTubeViewerUpdated?.Invoke(youTubeViewer);
|
||||
}
|
||||
|
||||
public async Task Delete(Guid id)
|
||||
{
|
||||
await _deleteYouTubeViewerCommand.Execute(id);
|
||||
|
||||
_youTubeViewers.RemoveAll(y => y.Id == id);
|
||||
|
||||
YouTubeViewerDeleted?.Invoke(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user