public async Task <Response <Guid> > AddAsync(BookCategoryUpsertDto bookCategoryUpsertDto)
        {
            if (_permissionChecker.HasClaim(AppPermissions.BookCategory.Create))
            {
                BookCategoryUpsertDtoValidator dtoValidator = new BookCategoryUpsertDtoValidator();

                ValidationResult validationResult = dtoValidator.Validate(bookCategoryUpsertDto);

                if (validationResult != null && validationResult.IsValid == false)
                {
                    return(new Response <Guid>(validationResult.Errors.Select(modelError => modelError.ErrorMessage)
                                               .ToList()));
                }
                else
                {
                    if (await _unitOfWork.Repository <IBookCategoryRepositoryAsync>()
                        .AnyAsync(o => o.Title.ToUpper() == bookCategoryUpsertDto.Title.ToUpper()))
                    {
                        return(new Response <Guid>(string.Format(SD.ExistData, bookCategoryUpsertDto.Title)));
                    }
                    else
                    {
                        BookCategory bookCategory = _mapper.Map <BookCategory>(bookCategoryUpsertDto);

                        var addedEntity = await _unitOfWork.Repository <IBookCategoryRepositoryAsync>()
                                          .AddAsync(bookCategory);

                        int effectedRows = await _unitOfWork.CommitAsync();

                        if (effectedRows != 0)
                        {
                            return(new Response <Guid>(addedEntity.Id));
                        }
                    }
                }

                return(new Response <Guid>(SD.ErrorOccurred));
            }

            return(new Response <Guid>("not authorized"));
        }
        public async Task <Response <bool> > UpdateAsync(BookCategoryUpsertDto bookCategoryUpsertDto)
        {
            if (_permissionChecker.HasClaim(AppPermissions.BookCategory.Edit))
            {
                BookCategoryUpsertDtoValidator dtoValidator = new BookCategoryUpsertDtoValidator();

                ValidationResult validationResult = dtoValidator.Validate(bookCategoryUpsertDto);

                if (validationResult != null && validationResult.IsValid == false)
                {
                    return(new Response <bool>(validationResult.Errors.Select(modelError => modelError.ErrorMessage).ToList()));
                }
                else
                {
                    if (await _unitOfWork.Repository <IBookCategoryRepositoryAsync>().AnyAsync(o => o.Title.ToUpper() == bookCategoryUpsertDto.Title.ToUpper() && o.Id != bookCategoryUpsertDto.Id))
                    {
                        return(new Response <bool>(string.Format(SD.ExistData, bookCategoryUpsertDto.Title)));
                    }
                    else
                    {
                        var entityToUpdate = await _unitOfWork.Repository <IBookCategoryRepositoryAsync>().FirstOrDefaultAsync(x => x.Id == bookCategoryUpsertDto.Id);

                        _mapper.Map(bookCategoryUpsertDto, entityToUpdate);

                        await _unitOfWork.Repository <IBookCategoryRepositoryAsync>().UpdateAsync(entityToUpdate);

                        int effectedRows = await _unitOfWork.CommitAsync();

                        if (effectedRows != 0)
                        {
                            return(new Response <bool>(true));
                        }
                    }
                }

                return(new Response <bool>(SD.ErrorOccurred));
            }

            return(new Response <bool>("not authorized"));
        }