private async Task ValidateUniqueness(string title, int?bookId) { var duplicate = await _repository.GetByTitleAsync(title); if (duplicate != null && duplicate.Id != bookId) { ThrowHttp.Conflict(ErrorMessage.BOOK_EXISTS); } }
private async Task ValidateUniqueness(string firstName, string lastName, int?authorId) { var duplicate = await _repository.GetByNameAsync(firstName, lastName); if (duplicate != null && duplicate.Id != authorId) { ThrowHttp.Conflict(ErrorMessage.AUTHOR_EXISTS); } }
public async Task DeleteAuthorAsync(int id) { var author = await GetByIdAsync(id); var hasBooks = await _repository.AuthorHasBooksAsync(id); if (hasBooks) { ThrowHttp.Conflict(ErrorMessage.AUTHOR_HAS_BOOKS); } await _repository.RemoveAsync(author); }
public async Task CreateUserAsync(UserProxy user) { ValidateUser(user); var existing = await _repository.GetByEmailAsync(user.Email); if (existing != null) { ThrowHttp.Conflict(ErrorMessage.EMAIL_EXISTS); } var entity = MapToEntity(user); await _repository.AddAsync(entity); }