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/#100 #101

Merged
merged 4 commits into from
Dec 8, 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
15 changes: 14 additions & 1 deletion WatchList.Core/Model/Load/Components/TypeLoadingCinema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace WatchList.Core.Model.Load.Components
{
public class TypeLoadingCinema : SmartEnumBaseWrapper<TypeCinema?>
public class TypeLoadingCinema : SmartEnumBaseWrapper<TypeCinema?>, IEquatable<TypeLoadingCinema>
{
public static ObservableCollection<TypeLoadingCinema> GetItemsType = GetItems(TypeCinema.List, e => new TypeLoadingCinema(e));

Expand All @@ -13,6 +13,19 @@ public TypeLoadingCinema(TypeCinema? value = null)
public override string Name
=> Value != null ? Value.Name : "All Type";

public bool Equals(TypeLoadingCinema? other)
{
return ReferenceEquals(other, null)
? false
: Value == other.Value && Name == other.Name;
}

public override bool Equals(object? obj)
=> Equals(obj as TypeLoadingCinema);

public override int GetHashCode()
=> HashCode.Combine(Name, Value);

public override string ToString() => Name;
}
}
4 changes: 4 additions & 0 deletions WatchList.Core/Model/Load/Grade.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using Ardalis.SmartEnum;
using WatchList.Core.Enums;

Expand All @@ -23,5 +24,8 @@ public Grade(string name, Grades grade)
}

public static Grade FromValue(Grades grade) => FromValue((int)grade);

public static ObservableCollection<Grade> GetItems()
=> new ObservableCollection<Grade>(List.OrderBy(x => x.Value));
}
}
3 changes: 3 additions & 0 deletions WatchList.WPF/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
12 changes: 6 additions & 6 deletions WatchList.WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public App()
var serviceCollection = new ServiceCollection();
ViewModelLocator.AddViewModels(serviceCollection)
.AppServiceContainer()
.AppServicePageContainer();
.AppServicePageContainer()
.AddSerilog(Log.Logger);
_serviceProvider = serviceCollection.BuildServiceProvider();
}

Expand All @@ -41,14 +42,13 @@ private void OnStartup(object sender, StartupEventArgs e)
{
Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}

private void OnExit(object sender, ExitEventArgs e)
=> _serviceProvider.Dispose();
{
_serviceProvider.Dispose();
Log.CloseAndFlush();
}

private static Logger CreateLogger(string logDirectory = "log")
{
Expand Down
10 changes: 7 additions & 3 deletions WatchList.WPF/Data/ViewModelLocator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using WatchList.WPF.ViewModel;
using WatchList.WPF.ViewModel.ItemsView;

namespace WatchList.WPF.Data
{
Expand All @@ -16,15 +17,18 @@ public CinemaPageViewModel CinemaPageViewModel
public MergeDatabaseViewModel MergeDatabaseViewModel
=> _provider!.GetRequiredService<MergeDatabaseViewModel>();

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

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

public static void Init(ServiceProvider provider) => _provider = provider;
}
Expand Down
9 changes: 5 additions & 4 deletions WatchList.WPF/Extension/AppServiceDIExtension.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using DevExpress.Mvvm.POCO;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using WatchList.Core.Repository;
using WatchList.Core.Service;
using WatchList.Core.Service.Component;
using WatchList.Core.Service.DataLoading;
using WatchList.Migrations.SQLite;
using WatchList.WPF.Data;
using WatchList.WPF.Models;
using WatchList.WPF.Models.Filter;
using WatchList.WPF.Models.ModelDataLoad;
using WatchList.WPF.Models.Sorter;
Expand All @@ -21,15 +22,15 @@ public static IServiceCollection AppServiceContainer(this IServiceCollection ser
.AddScoped(e => e.GetRequiredService<DbContextFactoryMigrator>().Create())
.AddScoped<WatchItemRepository>()
.AddScoped<IMessageBox, MessageWindow>()
.AddScoped<WatchItemCreator>()
.AddScoped<WatchItemService>()
.AddScoped<DownloadDataService>()
.AddScoped<SortWatchItemModel>()
.AddScoped<FilterItemModel>()
.AddSingleton<PageService>()
.AddScoped<ViewModelLocator>()
.AddScoped<FiileLoaderDB>()
.AddLogging()
.AddSerilog();
.AddScoped<FileLoaderDB>()
.AddLogging();

public static IServiceCollection AppServicePageContainer(this IServiceCollection serviceCollection)
=> serviceCollection.AddTransient<CinemaWindow>()
Expand Down
100 changes: 0 additions & 100 deletions WatchList.WPF/Models/CinemaModel.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace WatchList.WPF.Models.ModelDataLoad
{
public class FiileLoaderDB
public class FileLoaderDB
{
private readonly DownloadDataService _downloadDataService;
private readonly ILogger<WatchItemRepository> _logger;

public FiileLoaderDB(DownloadDataService downloadDataService, ILogger<WatchItemRepository> logger)
public FileLoaderDB(DownloadDataService downloadDataService, ILogger<WatchItemRepository> logger)
{
_downloadDataService = downloadDataService;
_logger = logger;
Expand Down

This file was deleted.

This file was deleted.

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

namespace WatchList.WPF.Models
{
public class WatchItemCreator
{
public WatchItemCreator()
{
}

public WatchItem CreateNonPlanned(
string title,
int sequel,
StatusCinema status,
TypeCinema type,
DateTime? date = null,
int? grade = null,
Guid? id = null)
=> new WatchItem(title, sequel, status, type, id, date, grade);

public WatchItem CreatePlanned(
string title,
int sequel,
StatusCinema status,
TypeCinema type,
Guid? id)
=> new WatchItem(title, sequel, status, type, id, null, null);
}
}
17 changes: 16 additions & 1 deletion WatchList.WPF/ViewModel/CinemaPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using WatchList.WPF.Models.Filter;
using WatchList.WPF.Models.Sorter;
using WatchList.WPF.Views;
using WatchList.WPF.Views.CinemaView;

namespace WatchList.WPF.ViewModel
{
Expand Down Expand Up @@ -70,7 +71,7 @@ public ObservableCollection<WatchItem> WatchItems

public string PageDisplayText => $"Page {CurPage} of {_pagedList.PageCount}";

public List<CinemaModel> PageWatchItems { get; set; }
public List<WatchItemCreator> PageWatchItems { get; set; }

public RelayCommandApp MoveToPreviousPage
=> new RelayCommandApp(async _ => await LoadDataAsyncPage(--Page.Number), _ => _pagedList.HasPreviousPage);
Expand All @@ -82,9 +83,23 @@ public RelayCommandApp MoveToNextPage
public RelayCommandApp MoveToLastPage
=> new RelayCommandApp(async _ => await LoadDataAsyncPage(_pagedList.PageCount), _ => _pagedList.HasNextPage);

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

public RelayCommandApp MoveAddDataDB
=> new RelayCommandApp(_ => new MergeDatabaseWindow().Show());

private async Task MoveAddItem()
{
var addWindow = new AddCinemaWindow();
if (addWindow.ShowDialog() != true)
{
return;
}

await LoadDataAsync();
}

/// <summary>
/// Load data in table.
/// </summary>
Expand Down
Loading
Loading