ADD : dependencies model & VM + Start Manager part

commands-19-09
Lou BRODA 1 year ago
parent 4971951d45
commit 781604b8bb

@ -53,6 +53,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
<ItemGroup>
<MauiXaml Update="View\ALirePlusTardView.xaml">
<Generator>MSBuild:Compile</Generator>

@ -1,4 +1,5 @@
using System;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,25 +9,25 @@ namespace LivreLand.ViewModel
{
class BookVM
{
//public Book Model
//{
// get => model;
// set => model = value;
//}
//private Book model;
public Book Model
{
get => model;
set => model = value;
}
private Book model;
//public BookVM()
//{
// Model = model;
//}
public BookVM()
{
Model = model;
}
//public string Title
//{
// get => model.Title;
// set
// {
// model.Title = value;
// }
//}
public string Title
{
get => model.Title;
set
{
model.Title = value;
}
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public interface ILibraryManager
{
Task<Book> GetBookById(string id);
Task<Book> GetBookByISBN(string isbn);
Task<Tuple<long, IEnumerable<Book>>> GetBooksByTitle(string title, int index, int count, string sort = "");
Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthorId(string authorId, int index, int count, string sort = "");
Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthor(string author, int index, int count, string sort = "");
Task<Author> GetAuthorById(string id);
Task<Tuple<long, IEnumerable<Author>>> GetAuthorsByName(string substring, int index, int count, string sort = "");
}
}

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Manager
{
private ILibraryManager LibraryManager { get; set; }
public ReadOnlyCollection<Book> Books { get; private set; }
private List<Book> books = new();
public Manager(ILibraryManager libMgr)
{
LibraryManager = libMgr;
Books = new ReadOnlyCollection<Book>(books);
}
public async Task<Book> GetBookById(string id)
=> await LibraryManager.GetBookById(id);
public async Task<Book> GetBookByISBN(string isbn)
=> await LibraryManager.GetBookByISBN(isbn);
public async Task<(long count, IEnumerable<Book> books)> GetBooksByTitle(string title, int index, int count, string sort = "")
{
var result = await LibraryManager.GetBooksByTitle(title, index, count, sort);
return (result.Item1, result.Item2);
}
public async Task<(long count, IEnumerable<Book> books)> GetBooksByAuthorId(string authorId, int index, int count, string sort = "")
{
var result = await LibraryManager.GetBooksByAuthorId(authorId, index, count, sort);
return (result.Item1, result.Item2);
}
public async Task<(long count, IEnumerable<Book> books)> GetBooksByAuthor(string author, int index, int count, string sort = "")
{
var result = await LibraryManager.GetBooksByAuthor(author, index, count, sort);
return (result.Item1, result.Item2);
}
public async Task<Author> GetAuthorById(string id)
=> await LibraryManager.GetAuthorById(id);
public async Task<(long count, IEnumerable<Author> authors)> GetAuthorsByName(string substring, int index, int count, string sort = "")
{
var result = await LibraryManager.GetAuthorsByName(substring, index, count, sort);
return (result.Item1, result.Item2);
}
}
}

@ -1,23 +1,32 @@
using System.Windows.Input;
using Model;
using System.Windows.Input;
namespace ViewModels
{
public class ManagerVM
{
//public Manager Model
//{
// get => model;
// private set => model = value;
//}
//private Manager model;
//public ICommand GetBooksByTitleCommand;
//public ManagerVM(Manager model)
//{
// Model = model;
// GetBooksByTitleCommand = new Command(async () =>
// )
//}
#region Properties
public Manager Model
{
get => model;
private set => model = value;
}
private Manager model;
public ICommand GetBooksByTitleCommand;
#endregion
#region Constructor
public ManagerVM(Manager model)
{
Model = model;
//GetBooksByTitleCommand = new Command(async () =>)
}
#endregion
}
}

@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save