Skip to content

Commit

Permalink
modifing the database, repos, adding some Serivces, and start servic…
Browse files Browse the repository at this point in the history
…e implementation
  • Loading branch information
Abdullah Ahmed committed Oct 10, 2024
1 parent 6fce5c7 commit 2a2a652
Show file tree
Hide file tree
Showing 47 changed files with 915 additions and 965 deletions.
91 changes: 87 additions & 4 deletions src/Application.BLL/Services/Implementation/BookService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,95 @@
using System;
using Application.DAL;
using Application.DAL.UnitOfWork;
using Application.Shared;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Threading.Tasks;
namespace Application.BLL
{
public class BookService
public class BookService : IBookService
{

private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;

public async Task AddBook(CreateBookDto createBookDto)
{
/// Get Category using its Id
/// Id will based through drop down list the display is category_name, and the value is category_id
var Category = await _unitOfWork.CategoryRepository.GetByIdAsync(createBookDto.CategoryId);

/// Category Validation
if (Category != null)
{
/// get Authors via search by names
List<ApplicationUser> authors = new List<ApplicationUser>();
foreach(var AuthorName in createBookDto.AuthorNames)
{
ApplicationUser Author = await _unitOfWork.UserRepository.GetUserByNameAsync(AuthorName);

/// Author Existence validation
if (Author == null)
throw new Exception($"Author {AuthorName} Doesn't Exists");
authors.Add(Author);

}

if (createBookDto.PublicationYear > DateTime.UtcNow.Year)
throw new Exception("PublicationYear Not Valid");

var Book = new Book()
{
Title = createBookDto.Title,
ISBN = createBookDto.ISBN,
IsDeleted = false,
CoverUrl = createBookDto.CoverUrl,
Category = Category,
CategoryId = Category.CategoryId,
Loans = new List<Loan>(),
AvailableCopies = createBookDto.AvailableCopies,
Authors = authors,
PublicationYear = createBookDto.PublicationYear
};


await _unitOfWork.BookRepository.AddAsync(Book);
await _unitOfWork.CompleteAsync();
}
throw new Exception("Category Not Found");

}

public Task<IEnumerable<ReadBookDto>> AllBooks()
{
throw new NotImplementedException();
}

public Task DeleteBook(Guid bookId)
{
throw new NotImplementedException();
}

public Task<ReadBookDto> GetBookById(Guid bookId)
{
throw new NotImplementedException();
}

public Task<bool> IsBookAvailable(Guid bookId)
{
throw new NotImplementedException();
}

public Task<bool> IsBookExists(string name)
{
throw new NotImplementedException();
}

public Task UpdateBook(UpdateBookDto updateBookDto)
{
throw new NotImplementedException();
}
}
}
34 changes: 32 additions & 2 deletions src/Application.BLL/Services/Implementation/CategoryService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BLL
{
public class CategoryService
public class CategoryService : ICategoryService
{
public Task AddCategory(CreateCategoryDto createCategoryDto)
{
throw new NotImplementedException();
}

public Task<IEnumerable<ReadCategoryDto>> AllCategories()
{
throw new NotImplementedException();
}

public Task DeleteCategory(Guid CategoryId)
{
throw new NotImplementedException();
}

public Task<ReadCategoryDto> GetCategoryById(Guid CategoryId)
{
throw new NotImplementedException();
}

public Task<bool> IsCategoryExists(string name)
{
throw new NotImplementedException();
}

public Task UpdateCategory(UpdateCategoryDto updateCategoryDto)
{
throw new NotImplementedException();
}
}
}
62 changes: 60 additions & 2 deletions src/Application.BLL/Services/Implementation/LoanService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,70 @@
using System;
using Application.DAL;
using Application.DAL.UnitOfWork;
using Application.Shared;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BLL
{
public class LoanService
public class LoanService : ILoanService
{

private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public LoanService(IUnitOfWork unitOfWork, IMapper mapper)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public async Task AddLoan(CreateLoanDto createLoanDto)
{
/// check book exists -> book reposiotry
/// user -> userrepos
/// loan -> loan
var bookid = Guid.NewGuid();
var book = await _unitOfWork.BookRepository.GetByIdAsync(bookid);
if(book != null)
{
var user = await _unitOfWork.UserRepository.GetByIdAsync();
if (user != null)
{
await _unitOfWork.LoanRepository.AddAsync(_mapper.Map<Loan>(createLoanDto));

book.AvailableCopies -= 1;
await _unitOfWork.BookRepository.UpdateAsync(book);
await _unitOfWork.CompleteAsync();

}
}

throw new NotImplementedException();
}

public Task<IEnumerable<ReadLoanDto>> AllLoans()
{
throw new NotImplementedException();
}



public Task<ReadLoanDto> GetBookById(Guid LoanId)
{
throw new NotImplementedException();
}

public Task ReturnLoan(Guid LoanId)
{
throw new NotImplementedException();
}

public Task UpdateLoan(UpdateLoanDto updateLoanDto)
{
throw new NotImplementedException();
}
}
}
29 changes: 27 additions & 2 deletions src/Application.BLL/Services/Implementation/PenaltyService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BLL
{
public class PenaltyService
public class PenaltyService : IPenaltyService
{
public Task<IEnumerable<ReadPenaltyDto>> AllPenalties()
{
throw new NotImplementedException();
}

public Task DeletePenalty(Guid PenaltyId)
{
throw new NotImplementedException();
}

public Task<ReadPenaltyDto> GetLByPenaltiesByMember(Guid MemberId)
{
throw new NotImplementedException();
}

public Task<bool> IsPenaltyPaid(Guid PenaltyId)
{
throw new NotImplementedException();
}

public Task UpdatePenalty(UpdatePenaltyDto updatePenaltyto)
{
throw new NotImplementedException();
}
}
}
29 changes: 27 additions & 2 deletions src/Application.BLL/Services/Implementation/UserService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BLL
{
public class UserService
public class UserService : IUserService
{
public Task BlockUserAsync(Guid id)
{
throw new NotImplementedException();
}

public Task<IEnumerable<ReadUserDto>> GetAllUsersAsync()
{
throw new NotImplementedException();
}

public Task<ReadUserDto> GetUserByIdAsync(Guid id)
{
throw new NotImplementedException();
}

public Task<IEnumerable<ReadUserDto>> GetUsersByRoleAsync(string role)
{
throw new NotImplementedException();
}

public Task SoftDeleteUserAsync(Guid id)
{
throw new NotImplementedException();
}
}
}
11 changes: 10 additions & 1 deletion src/Application.BLL/Services/Interfaces/IBookService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +9,13 @@ namespace Application.BLL
{
public interface IBookService
{
Task AddBook(CreateBookDto createBookDto);
Task<IEnumerable<ReadBookDto>> AllBooks();
Task<ReadBookDto> GetBookById(Guid bookId);
Task UpdateBook(UpdateBookDto updateBookDto);
Task DeleteBook(Guid bookId);
Task<bool> IsBookAvailable(Guid bookId);
Task<bool> IsBookExists(string name); // Check if book deleted or not

}
}
9 changes: 8 additions & 1 deletion src/Application.BLL/Services/Interfaces/ICategoryService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +9,11 @@ namespace Application.BLL
{
public interface ICategoryService
{
Task<IEnumerable<ReadCategoryDto>> AllCategories();
Task AddCategory(CreateCategoryDto createCategoryDto);
Task<ReadCategoryDto> GetCategoryById(Guid CategoryId);
Task UpdateCategory(UpdateCategoryDto updateCategoryDto);
Task DeleteCategory(Guid CategoryId);
Task<bool> IsCategoryExists(string name); // Check if Category deleted or not
}
}
9 changes: 8 additions & 1 deletion src/Application.BLL/Services/Interfaces/ILoanService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +9,11 @@ namespace Application.BLL
{
public interface ILoanService
{
Task AddLoan(CreateLoanDto createLoanDto);
Task<IEnumerable<ReadLoanDto>> AllLoans();
Task<ReadLoanDto> GetBookById(Guid LoanId);
Task UpdateLoan(UpdateLoanDto updateLoanDto);
Task DeleteLoan(Guid LoanId);
Task ReturnLoan(Guid LoanId);
}
}
13 changes: 13 additions & 0 deletions src/Application.BLL/Services/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.BLL.Services
{
public interface INotificationService
{

}
}
8 changes: 7 additions & 1 deletion src/Application.BLL/Services/Interfaces/IPenaltyService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Application.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +9,10 @@ namespace Application.BLL
{
public interface IPenaltyService
{
Task<IEnumerable<ReadPenaltyDto>> AllPenalties();
Task<ReadPenaltyDto> GetLByPenaltiesByMember(Guid MemberId);
Task UpdatePenalty(UpdatePenaltyDto updatePenaltyto);
Task DeletePenalty(Guid PenaltyId);
Task<bool> IsPenaltyPaid(Guid PenaltyId); // Check if Penalty Paid or not
}
}
Loading

0 comments on commit 2a2a652

Please sign in to comment.