public async Task <IActionResult> UpdateBookCategory(BookCategoryUpsertDto bookCategoryUpsertDto)
        {
            if (bookCategoryUpsertDto == null)
            {
                return(BadRequest(ModelState));
            }

            Response <bool> response = await _bookCategoryService.UpdateAsync(bookCategoryUpsertDto);

            if (response != null)
            {
                if (response.Succeeded)
                {
                    return(NoContent());
                }
                else
                {
                    return(BadRequest(response));
                }
            }
            else
            {
                response = new Response <bool>(SD.ErrorOccurred);
                return(BadRequest(response));
            }
        }
        public async Task <IActionResult> CreateBookCategory(BookCategoryUpsertDto bookCategoryUpsertDto)
        {
            if (bookCategoryUpsertDto == null)
            {
                return(BadRequest(ModelState));
            }

            Response <Guid> response = await _bookCategoryService.AddAsync(bookCategoryUpsertDto);

            if (response != null)
            {
                if (response.Succeeded)
                {
                    return(CreatedAtRoute("GetBookCategoryById", new { bookCategoryId = response.Data }, response.Data));
                }
                else
                {
                    return(BadRequest(response));
                }
            }
            else
            {
                response = new Response <Guid>(SD.ErrorOccurred);
                return(BadRequest(response));
            }
        }
        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"));
        }