ADD : dependencies model & VM + Start Manager part

commands-19-09
Lou BRODA 2 years ago
parent 4971951d45
commit 781604b8bb

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

@ -1,4 +1,5 @@
using System; using Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -8,25 +9,25 @@ namespace LivreLand.ViewModel
{ {
class BookVM class BookVM
{ {
//public Book Model public Book Model
//{ {
// get => model; get => model;
// set => model = value; set => model = value;
//} }
//private Book model; private Book model;
//public BookVM() public BookVM()
//{ {
// Model = model; Model = model;
//} }
//public string Title public string Title
//{ {
// get => model.Title; get => model.Title;
// set set
// { {
// model.Title = value; 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 namespace ViewModels
{ {
public class ManagerVM public class ManagerVM
{ {
//public Manager Model
//{ #region Properties
// get => model;
// private set => model = value; public Manager Model
//} {
//private Manager model; get => model;
private set => model = value;
//public ICommand GetBooksByTitleCommand; }
private Manager model;
//public ManagerVM(Manager model)
//{ public ICommand GetBooksByTitleCommand;
// Model = model;
// GetBooksByTitleCommand = new Command(async () => #endregion
// )
//} #region Constructor
public ManagerVM(Manager model)
{
Model = model;
//GetBooksByTitleCommand = new Command(async () =>)
}
#endregion
} }
} }

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

Loading…
Cancel
Save