48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using ProjectLibrary.Entites;
|
|
using ProjectLibrary.Entities;
|
|
using ProjectLibrary.Repositories;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ProjectLibrary.Repositories.Implementations
|
|
{
|
|
public class LibraryRepository : ILibraryRepository
|
|
{
|
|
private readonly List<Library> _libraries = new List<Library>();
|
|
|
|
public void CreateLibrary(Library library)
|
|
{
|
|
_libraries.Add(library);
|
|
}
|
|
|
|
public void DeleteLibrary(int id)
|
|
{
|
|
var library = _libraries.FirstOrDefault(l => l.Id == id);
|
|
if (library != null)
|
|
{
|
|
_libraries.Remove(library);
|
|
}
|
|
}
|
|
|
|
public Library ReadLibraryById(int id)
|
|
{
|
|
return _libraries.FirstOrDefault(l => l.Id == id) ?? Library.CreateEntity(id, "Unknown Library", "Unknown Address");
|
|
}
|
|
|
|
public IEnumerable<Library> ReadLibraries()
|
|
{
|
|
return _libraries;
|
|
}
|
|
|
|
public void UpdateLibrary(Library library)
|
|
{
|
|
var existingLibrary = _libraries.FirstOrDefault(l => l.Id == library.Id);
|
|
if (existingLibrary != null)
|
|
{
|
|
_libraries.Remove(existingLibrary);
|
|
_libraries.Add(library);
|
|
}
|
|
}
|
|
}
|
|
}
|