initial load
This commit is contained in:
50
YouTubeViewers.WPF/Commands/AddYouTubeViewerCommand.cs
Normal file
50
YouTubeViewers.WPF/Commands/AddYouTubeViewerCommand.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class AddYouTubeViewerCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly AddYouTubeViewerViewModel _addYouTubeViewerViewModel;
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public AddYouTubeViewerCommand(AddYouTubeViewerViewModel addYouTubeViewerViewModel, YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_addYouTubeViewerViewModel = addYouTubeViewerViewModel;
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
}
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
YouTubeViewerDetailsFormViewModel formViewModel = _addYouTubeViewerViewModel.YouTubeViewerDetailsFormViewModel;
|
||||
formViewModel.IsSubmitting = true;
|
||||
YouTubeViewer youTubeViewer = new YouTubeViewer(
|
||||
Guid.NewGuid(),
|
||||
formViewModel.UserName,
|
||||
formViewModel.IsSubScribed,
|
||||
formViewModel.IsMember);
|
||||
|
||||
// Add YouTubeViewer to database
|
||||
try
|
||||
{
|
||||
await _youTubeViewersStore.Add(youTubeViewer);
|
||||
_modalNavigationStore.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
formViewModel.IsSubmitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
YouTubeViewers.WPF/Commands/AsyncCommandBase.cs
Normal file
44
YouTubeViewers.WPF/Commands/AsyncCommandBase.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public abstract class AsyncCommandBase : CommandBase
|
||||
{
|
||||
private bool _isExecuting;
|
||||
|
||||
public bool IsExecuting
|
||||
{
|
||||
get { return _isExecuting; }
|
||||
set { _isExecuting = value;
|
||||
OnCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute(object? parameter)
|
||||
{
|
||||
return !_isExecuting && base.CanExecute(parameter);
|
||||
}
|
||||
|
||||
|
||||
public override async void Execute(object? parameter)
|
||||
{
|
||||
IsExecuting = true;
|
||||
|
||||
try
|
||||
{
|
||||
await ExecuteAsync(parameter);
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
IsExecuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Task ExecuteAsync(object? parameter);
|
||||
}
|
||||
}
|
||||
24
YouTubeViewers.WPF/Commands/CloseModalCommand.cs
Normal file
24
YouTubeViewers.WPF/Commands/CloseModalCommand.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class CloseModalCommand : CommandBase
|
||||
{
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public CloseModalCommand(ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
}
|
||||
|
||||
public override void Execute(object? parameter)
|
||||
{
|
||||
_modalNavigationStore.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
26
YouTubeViewers.WPF/Commands/CommandBase.cs
Normal file
26
YouTubeViewers.WPF/Commands/CommandBase.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public abstract class CommandBase : ICommand
|
||||
{
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
|
||||
public virtual bool CanExecute(object? parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void Execute(object? parameter);
|
||||
|
||||
protected virtual void OnCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
YouTubeViewers.WPF/Commands/DeleteYouTubeViewerCommand.cs
Normal file
39
YouTubeViewers.WPF/Commands/DeleteYouTubeViewerCommand.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class DeleteYouTubeViewerCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly YouTubeViewersListingItemViewModel _youTubeViewersListingItemViewModel;
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
|
||||
public DeleteYouTubeViewerCommand(
|
||||
YouTubeViewersListingItemViewModel youTubeViewersListingItemViewModel,
|
||||
YouTubeViewersStore youTubeViewersStore)
|
||||
{
|
||||
_youTubeViewersListingItemViewModel = youTubeViewersListingItemViewModel;
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
YouTubeViewer youTubeViewer = _youTubeViewersListingItemViewModel.YouTubeViewer;
|
||||
try
|
||||
{
|
||||
await _youTubeViewersStore.Delete(youTubeViewer.Id);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
YouTubeViewers.WPF/Commands/EditYouTubeViewerCommand.cs
Normal file
50
YouTubeViewers.WPF/Commands/EditYouTubeViewerCommand.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class EditYouTubeViewerCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly EditYouTubeViewerViewModel _editYouTubeViewerViewModel;
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public EditYouTubeViewerCommand(EditYouTubeViewerViewModel editYouTubeViewerViewModel, YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_editYouTubeViewerViewModel = editYouTubeViewerViewModel;
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
}
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
YouTubeViewerDetailsFormViewModel formViewModel = _editYouTubeViewerViewModel.YouTubeViewerDetailsFormViewModel;
|
||||
formViewModel.IsSubmitting = true;
|
||||
YouTubeViewer youTubeViewer = new YouTubeViewer(
|
||||
_editYouTubeViewerViewModel.YouTubeViewerId,
|
||||
formViewModel.UserName,
|
||||
formViewModel.IsSubScribed,
|
||||
formViewModel.IsMember);
|
||||
|
||||
// Add YouTubeViewer to database
|
||||
try
|
||||
{
|
||||
await _youTubeViewersStore.Update(youTubeViewer);
|
||||
_modalNavigationStore.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
formViewModel.IsSubmitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
YouTubeViewers.WPF/Commands/LoadYouTubeViewersCommand.cs
Normal file
40
YouTubeViewers.WPF/Commands/LoadYouTubeViewersCommand.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class LoadYouTubeViewersCommand : AsyncCommandBase
|
||||
{
|
||||
private readonly YouTubeViewersViewModel _youTubeViewersViewModel;
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
|
||||
public LoadYouTubeViewersCommand(YouTubeViewersViewModel youTubeViewersViewModel, YouTubeViewersStore youTubeViewersStore)
|
||||
{
|
||||
_youTubeViewersViewModel = youTubeViewersViewModel;
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
}
|
||||
|
||||
public override async Task ExecuteAsync(object? parameter)
|
||||
{
|
||||
_youTubeViewersViewModel.IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
await _youTubeViewersStore.Load();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_youTubeViewersViewModel.IsLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
YouTubeViewers.WPF/Commands/OpenAddYouTubeViewerCommand.cs
Normal file
29
YouTubeViewers.WPF/Commands/OpenAddYouTubeViewerCommand.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class OpenAddYouTubeViewerCommand : CommandBase
|
||||
{
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public OpenAddYouTubeViewerCommand(YouTubeViewersStore youTubeViewersStore, ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
}
|
||||
|
||||
public override void Execute(object? parameter)
|
||||
{
|
||||
AddYouTubeViewerViewModel addYouTubeViewerViewModel = new AddYouTubeViewerViewModel(_youTubeViewersStore, _modalNavigationStore);
|
||||
_modalNavigationStore.CurrentViewModel = addYouTubeViewerViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
YouTubeViewers.WPF/Commands/OpenEditYouTubeViewerCommand.cs
Normal file
38
YouTubeViewers.WPF/Commands/OpenEditYouTubeViewerCommand.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YouTubeViewers.Domain.Models;
|
||||
using YouTubeViewers.WPF.Stores;
|
||||
using YouTubeViewers.WPF.ViewModels;
|
||||
|
||||
namespace YouTubeViewers.WPF.Commands
|
||||
{
|
||||
public class OpenEditYouTubeViewerCommand: CommandBase
|
||||
{
|
||||
private readonly YouTubeViewersListingItemViewModel _youTubeViewersListingItemViewModel;
|
||||
private readonly YouTubeViewersStore _youTubeViewersStore;
|
||||
private readonly ModalNavigationStore _modalNavigationStore;
|
||||
|
||||
public OpenEditYouTubeViewerCommand(
|
||||
YouTubeViewersListingItemViewModel youTubeViewersListingItemViewModel,
|
||||
YouTubeViewersStore youTubeViewersStore,
|
||||
ModalNavigationStore modalNavigationStore)
|
||||
{
|
||||
_youTubeViewersListingItemViewModel = youTubeViewersListingItemViewModel;
|
||||
_youTubeViewersStore = youTubeViewersStore;
|
||||
_modalNavigationStore = modalNavigationStore;
|
||||
}
|
||||
|
||||
public override void Execute(object? parameter)
|
||||
{
|
||||
YouTubeViewer youTubeViewer = _youTubeViewersListingItemViewModel.YouTubeViewer;
|
||||
|
||||
EditYouTubeViewerViewModel editYouTubeViewerViewModel = new EditYouTubeViewerViewModel(youTubeViewer,_youTubeViewersStore, _modalNavigationStore);
|
||||
_modalNavigationStore.CurrentViewModel = editYouTubeViewerViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user