Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#102 #103

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions WatchList.Core/Model/ItemCinema/WatchItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class WatchItem : IEquatable<WatchItem>
{
protected const string FormatDate = "dd.MM.yyyy";

public WatchItem(string title, int sequel, StatusCinema status, TypeCinema type, Guid? id, DateTime? dateWatch = null, int? grade = null)
public WatchItem(string title, int sequel, StatusCinema status, TypeCinema type, Guid? id = null, DateTime? dateWatch = null, int? grade = null)
{
Title = string.IsNullOrEmpty(title) ? throw new ArgumentException("Invalid title format.", nameof(title)) : title;
Sequel = sequel > 0 ? sequel : throw new ArgumentException("The sequel number is greater than zero.", nameof(sequel));
Expand All @@ -26,7 +26,7 @@ protected WatchItem()
Title = string.Empty;
Sequel = 1;
Type = TypeCinema.Movie;
Status = StatusCinema.Look;
Status = StatusCinema.Planned;
Date = null;
Grade = null;
Id = Guid.NewGuid();
Expand Down
24 changes: 24 additions & 0 deletions WatchList.WPF/Component/CustomDataGrid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using System.Windows;
using System.Windows.Controls;

namespace WatchList.WPF.Component
{
public class CustomDataGrid : DataGrid
{
public CustomDataGrid()
=> SelectionChanged += CustomDataGrid_SelectionChanged;

void CustomDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> SelectedItemsList = SelectedItems;

public IList SelectedItemsList
{
get => (IList)GetValue(SelectedItemsListProperty);
set => SetValue(SelectedItemsListProperty, value);
}

public static readonly DependencyProperty SelectedItemsListProperty
= DependencyProperty.Register("SelectedItemsList", typeof(IList), typeof(CustomDataGrid), new PropertyMetadata(null));
}
}
7 changes: 6 additions & 1 deletion WatchList.WPF/Data/ViewModelLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ public MergeDatabaseViewModel MergeDatabaseViewModel

public DataReplaceMessageVM DataReplaceMessageVM
=> _provider!.GetRequiredService<DataReplaceMessageVM>();

public AddCinemaViewModel AddCinemaViewModel
=> _provider!.GetRequiredService<AddCinemaViewModel>();

public EditCinemaViewModel EditCinemaViewModel
=> _provider!.GetRequiredService<EditCinemaViewModel>();

public static IServiceCollection AddViewModels(ServiceCollection serviceCollection)
=> serviceCollection
.AddTransient<CinemaWindowViewModel>()
.AddTransient<CinemaPageViewModel>()
.AddTransient<MergeDatabaseViewModel>()
.AddTransient<DataReplaceMessageVM>()
.AddTransient<AddCinemaViewModel>();
.AddTransient<AddCinemaViewModel>()
.AddTransient<EditCinemaViewModel>();

public static void Init(ServiceProvider provider) => _provider = provider;
}
Expand Down
16 changes: 0 additions & 16 deletions WatchList.WPF/Models/ModelDataLoad/DialogReplaceQuestionManager.cs

This file was deleted.

14 changes: 14 additions & 0 deletions WatchList.WPF/Models/WatchItemModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using WatchList.Core.Model.ItemCinema;

namespace WatchList.WPF.Models
{
public class WatchItemModel : WatchItem
{
public WatchItemModel()
: base()
{
}

public static WatchItem GetDefaultAddItem => new WatchItemModel();
}
}
81 changes: 78 additions & 3 deletions WatchList.WPF/ViewModel/CinemaPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections;
using System.Collections.ObjectModel;
using System.Windows;
using DevExpress.Mvvm;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WatchList.Core.Model.ItemCinema;
using WatchList.Core.PageItem;
Expand All @@ -13,27 +15,35 @@
using WatchList.WPF.Models;
using WatchList.WPF.Models.Filter;
using WatchList.WPF.Models.Sorter;
using WatchList.WPF.ViewModel.ItemsView;
using WatchList.WPF.Views;
using WatchList.WPF.Views.CinemaView;

namespace WatchList.WPF.ViewModel
{
public class CinemaPageViewModel : BindableBase
{
private const string HighlightTheDesiredLine = "No items selected.";
private const string NotSelectSingleItemLine = "Select one item.";

private readonly WatchItemService _itemService;
private readonly IMessageBox _messageBox;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<WatchItemRepository> _logger;
private readonly PageService _pageService;

private readonly SortWatchItemModel _sortField;
private readonly FilterItemModel _filterItem;
private readonly ItemSearchRequest _searchRequests;

private readonly bool _isAscending = true;

private ObservableCollection<WatchItem> _watchItems = new ObservableCollection<WatchItem>();

private PagedList<WatchItem> _pagedList;
private readonly bool _isAscending = true;

private WatchItem _selectItem;
private IList _selectItems = new ArrayList();
private int _curPage;

private int CurPage
Expand All @@ -44,11 +54,13 @@ private int CurPage

public CinemaPageViewModel(IMessageBox messageBox,
ILogger<WatchItemRepository> logger,
IServiceProvider serviceProvider,
WatchItemService watchItemService,
SortWatchItemModel sortField,
FilterItemModel filterItem,
PageService pageService)
{
_serviceProvider = serviceProvider;
_messageBox = messageBox;
_logger = logger;
_itemService = watchItemService;
Expand All @@ -61,6 +73,18 @@ public CinemaPageViewModel(IMessageBox messageBox,
LoadDataAsync();
}

public WatchItem SelectItem
{
get => _selectItem;
set => SetValue(ref _selectItem, value);
}

public IList SelectItems
{
get => _selectItems;
set => SetValue(ref _selectItems, value);
}

public ObservableCollection<WatchItem> WatchItems
{
get => _watchItems;
Expand All @@ -85,13 +109,19 @@ public RelayCommandApp MoveToLastPage

public RelayCommandApp AddItemCommand
=> new RelayCommandApp(async async => await MoveAddItem());

public RelayCommandApp EditItemCommand
=> new RelayCommandApp(async async => await EditItem());
public RelayCommandApp DeleteItemsCommand
=> new RelayCommandApp(async async => await DeleteItems());
public RelayCommandApp AddDataDBCommand
=> new RelayCommandApp(async async => await MoveAddData());

private async Task MoveAddItem()
{
var addWindow = new AddCinemaWindow();
var viewModel = _serviceProvider.GetRequiredService<AddCinemaViewModel>();
viewModel.InitializeDefaultValue();
var addWindow = new WatchCinemaWindow(viewModel);

if (addWindow.ShowDialog() != true)
{
return;
Expand All @@ -100,6 +130,51 @@ private async Task MoveAddItem()
await LoadDataAsync();
}

private async Task EditItem()
{
if (SelectItems.Count != 1)
{
await _messageBox.ShowInfo(NotSelectSingleItemLine);
return;
}

var viewModel = _serviceProvider.GetRequiredService<EditCinemaViewModel>();
viewModel.InitializeDefaultValue(SelectItem);
var editWindow = new WatchCinemaWindow(viewModel);

if (editWindow.ShowDialog() != true)
{
return;
}

await LoadDataAsync();
}

private async Task DeleteItems()
{
if (SelectItems.Count == 0)
{
await _messageBox.ShowInfo(HighlightTheDesiredLine);
return;
}

if (!await _messageBox.ShowQuestion("Delete select items?"))
{
return;
}

foreach (var item in SelectItems)
{
var isWatchItem = item as WatchItem;
if (isWatchItem != null)
{
_itemService.Remove(isWatchItem.Id);
}
}

await LoadDataAsync();
}

private async Task MoveAddData()
{
var addDataWindow = new MergeDatabaseWindow();
Expand Down
18 changes: 7 additions & 11 deletions WatchList.WPF/ViewModel/DataReplaceMessageVM.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using WatchList.Core.Model.QuestionResult;
using WatchList.WPF.Models.ModelDataLoad;

namespace WatchList.WPF.ViewModel
{
Expand All @@ -11,16 +10,13 @@ public class DataReplaceMessageVM

private readonly string _titleLabel;

public DataReplaceMessageVM(string titleItem, DialogReplaceQuestionManager questionResult)
{
_titleLabel = titleItem;
ResultQuestion = questionResult;
}
public DataReplaceMessageVM(string titleItem)
=> _titleLabel = titleItem;

public string QuestionLabel => Question;
public string TitleLabel => _titleLabel;

public DialogReplaceQuestionManager ResultQuestion { get; private set; }
public DialogReplaceItemQuestion ResultQuestion { get; private set; } = DialogReplaceItemQuestion.Unknown;

public RelayCommand<Window> MoveYesCommand => new(MoveYesClick);
public RelayCommand<Window> MoveAllYesCommand => new(MoveAllYesClick);
Expand All @@ -29,28 +25,28 @@ public DataReplaceMessageVM(string titleItem, DialogReplaceQuestionManager quest

private void MoveYesClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.Yes);
ResultQuestion = DialogReplaceItemQuestion.Yes;
window.DialogResult = true;
window?.Close();
}

private void MoveAllYesClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllYes);
ResultQuestion = DialogReplaceItemQuestion.AllYes;
window.DialogResult = true;
window?.Close();
}

private void MoveNoClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.No);
ResultQuestion = DialogReplaceItemQuestion.No;
window.DialogResult = true;
window?.Close();
}

private void MoveAllNoClick(Window window)
{
ResultQuestion.UpdateData(DialogReplaceItemQuestion.AllNo);
ResultQuestion = DialogReplaceItemQuestion.AllNo;
window.DialogResult = true;
window?.Close();
}
Expand Down
Loading
Loading