Skip to content
Open
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: 15 additions & 0 deletions LibraryManager.BLL/Interfaces/ICommentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using LibraryManager.DTO.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace LibraryManager.BLL.Interfaces
{
public interface ICommentService
{
void Create(CommentDTO commentDTO);
void Delete(int id);
IEnumerable<CommentDTO> GetByBook(int id);
void Update(CommentDTO commentDTO);
}
}
57 changes: 57 additions & 0 deletions LibraryManager.BLL/Services/CommentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using AutoMapper;
using LibraryManager.BLL.Interfaces;
using LibraryManager.DAL.Entities;
using LibraryManager.DAL.Interfaces;
using LibraryManager.DTO.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibraryManager.BLL.Services
{
public class CommentService : ICommentService
{
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;

public CommentService(IUnitOfWork unitOfWork,IMapper mapper)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public void Create(CommentDTO commentDTO)
{
var comment = _mapper.Map<Comment>(commentDTO);
_unitOfWork.CommentRepository.Create(comment);
_unitOfWork.Save();
}

public void Delete(int id)
{
_unitOfWork.CommentRepository.Delete(id);
_unitOfWork.Save();
}

public IEnumerable<CommentDTO> GetByBook(int id)
{
var comments = _unitOfWork.CommentRepository.GetAll().Where(x => x.BookId == id);
var commentsDTO = new List<CommentDTO>();

foreach (var comment in comments)
{
commentsDTO.Add(_mapper.Map<CommentDTO>(comment));
}

return commentsDTO;
}

public void Update(CommentDTO commentDTO)
{
var comment = _mapper.Map<Comment>(commentDTO);
_unitOfWork.CommentRepository.Update(comment);
_unitOfWork.Save();
}
}
}
2 changes: 1 addition & 1 deletion LibraryManager.DAL/Context/LibraryManagerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace LibraryManager.DAL.Context
{
public sealed class LibraryManagerContext: IdentityDbContext<User>
{
//public DbSet<Admin> Admins { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Language> Languages { get; set; }
public DbSet<UserBook> UserBooks { get; set; }
public DbSet<Comment> Comments { get; set; }


public LibraryManagerContext() { }
Expand Down
21 changes: 21 additions & 0 deletions LibraryManager.DAL/Entities/Comment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LibraryManager.DAL.Entities
{
public class Comment
{
public int Id { get; set; }

public string Name { get; set; }

public DateTime Date { get; set; }

public string UserId { get; set; }
public User User { get; set; }

public int BookId { get; set; }
public Book Book { get; set; }
}
}
4 changes: 3 additions & 1 deletion LibraryManager.DAL/Interfaces/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public interface IUnitOfWork: IDisposable
IRepository<Language, int> LanguageRepository { get; set; }

IRepository<Genre, int> GenreRepository { get; set; }


IRepository<Comment,int> CommentRepository { get; set; }

IManyToManyRepository<UserBook,string, int> UserBookRepository { get; set; }

IManyToManyRepository<BookGenre, int, int> BookGenreRepository { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions LibraryManager.DAL/LibraryManager.DAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
</Reference>
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>

</Project>
Loading