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")); }