Loading BusinessLayer/BusinessLayer.csproj +0 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,4 @@ <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" /> </ItemGroup> <ItemGroup> <Folder Include="Images\" /> </ItemGroup> </Project> BusinessLayer/Services/BookService.cs +16 −4 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ public class BookService : IBookService public async Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image) { var book = _mapper.Map<Book>(addBookDto); if (image != null) { var imagePath = Path.Combine("images", image.FileName); Loading Loading @@ -67,7 +68,8 @@ public class BookService : IBookService public async Task<ResponseBookDto> UpdateBookAsync( int id, UpdateBookDto updateBookDto, IFormFile image IFormFile image, int? userId ) { var book = await _unitOfWork.BookRepository.GetByIdAsync(id); Loading @@ -77,7 +79,18 @@ public class BookService : IBookService throw new NotFoundException("Book", id); } _mapper.Map(updateBookDto, book); if (userId != null) { if (await _unitOfWork.UserRepository.GetByIdAsync(userId.Value) != null) { book.LastEditorId = userId; book.EditCount += 1; } else { throw new NotFoundException("User", userId.Value); } } if (image != null) { var imagePath = Path.Combine("images", image.FileName); Loading Loading @@ -109,8 +122,7 @@ public class BookService : IBookService private async Task<IEnumerable<ResponseBookDto>> GetBooksAsync(BookFilterDto filter) { var books = await _unitOfWork.BookRepository.GetAllAsync(); var query = books.AsQueryable(); var query = _unitOfWork.BookRepository.GetQueryable(); if (!string.IsNullOrEmpty(filter.Name)) { Loading BusinessLayer/Services/Interfaces/IBookService.cs +6 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,12 @@ public interface IBookService Task<IEnumerable<ResponseBookDto>> GetAllBooksAsync(); Task<ResponseBookDto> GetBookByIdAsync(int id); Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image); Task<ResponseBookDto> UpdateBookAsync(int id, UpdateBookDto updateBookDto, IFormFile image); Task<ResponseBookDto> UpdateBookAsync( int id, UpdateBookDto updateBookDto, IFormFile image, int? userId ); Task DeleteBookAsync(int id); Task<IEnumerable<ResponseBookDto>> GetFilteredBooksAsync(BookFilterDto filter); } Infrastructure/Repositories/IRepository.cs +2 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,6 @@ public interface IRepository<T> void Update(T entity); Task<T?> GetByIdAsync(int id); Task<IEnumerable<T>> GetAllAsync(); IQueryable<T> GetQueryable(); } Infrastructure/Repositories/Repository.cs +5 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,9 @@ public class Repository<T> : IRepository<T> { return await _entities.ToListAsync(); } public IQueryable<T> GetQueryable() { return _entities; } } Loading
BusinessLayer/BusinessLayer.csproj +0 −4 Original line number Diff line number Diff line Loading @@ -16,8 +16,4 @@ <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" /> </ItemGroup> <ItemGroup> <Folder Include="Images\" /> </ItemGroup> </Project>
BusinessLayer/Services/BookService.cs +16 −4 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ public class BookService : IBookService public async Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image) { var book = _mapper.Map<Book>(addBookDto); if (image != null) { var imagePath = Path.Combine("images", image.FileName); Loading Loading @@ -67,7 +68,8 @@ public class BookService : IBookService public async Task<ResponseBookDto> UpdateBookAsync( int id, UpdateBookDto updateBookDto, IFormFile image IFormFile image, int? userId ) { var book = await _unitOfWork.BookRepository.GetByIdAsync(id); Loading @@ -77,7 +79,18 @@ public class BookService : IBookService throw new NotFoundException("Book", id); } _mapper.Map(updateBookDto, book); if (userId != null) { if (await _unitOfWork.UserRepository.GetByIdAsync(userId.Value) != null) { book.LastEditorId = userId; book.EditCount += 1; } else { throw new NotFoundException("User", userId.Value); } } if (image != null) { var imagePath = Path.Combine("images", image.FileName); Loading Loading @@ -109,8 +122,7 @@ public class BookService : IBookService private async Task<IEnumerable<ResponseBookDto>> GetBooksAsync(BookFilterDto filter) { var books = await _unitOfWork.BookRepository.GetAllAsync(); var query = books.AsQueryable(); var query = _unitOfWork.BookRepository.GetQueryable(); if (!string.IsNullOrEmpty(filter.Name)) { Loading
BusinessLayer/Services/Interfaces/IBookService.cs +6 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,12 @@ public interface IBookService Task<IEnumerable<ResponseBookDto>> GetAllBooksAsync(); Task<ResponseBookDto> GetBookByIdAsync(int id); Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image); Task<ResponseBookDto> UpdateBookAsync(int id, UpdateBookDto updateBookDto, IFormFile image); Task<ResponseBookDto> UpdateBookAsync( int id, UpdateBookDto updateBookDto, IFormFile image, int? userId ); Task DeleteBookAsync(int id); Task<IEnumerable<ResponseBookDto>> GetFilteredBooksAsync(BookFilterDto filter); }
Infrastructure/Repositories/IRepository.cs +2 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,6 @@ public interface IRepository<T> void Update(T entity); Task<T?> GetByIdAsync(int id); Task<IEnumerable<T>> GetAllAsync(); IQueryable<T> GetQueryable(); }
Infrastructure/Repositories/Repository.cs +5 −0 Original line number Diff line number Diff line Loading @@ -42,4 +42,9 @@ public class Repository<T> : IRepository<T> { return await _entities.ToListAsync(); } public IQueryable<T> GetQueryable() { return _entities; } }