Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }