예제 #1
0
        public async Task <IDataResult <List <Brand> > > Handle(GetBrandsQuery request, CancellationToken cancellationToken)
        {
            var result = await _brandDal.GetAll();

            if (result != null)
            {
                return(new SuccessDataResult <List <Brand> >(result, Messages.BrandListSuccessful));
            }
            return(new ErrorDataResult <List <Brand> >(Messages.BrandNotFound));
        }
        public async Task <List <BrandDto> > Handle(GetBrandsQuery request, CancellationToken cancellationToken)
        {
            var brands = await _repository.ListAsync <Brand, BrandDto>(
                x => new BrandDto
            {
                Id       = x.Id,
                Name     = x.Name,
                ImageUri = x.ImageUri
            }).ConfigureAwait(false);

            return(brands);
        }
예제 #3
0
        public async Task <Result <IEnumerable <BrandViewModel> > > Handle(GetBrandsQuery request, CancellationToken cancellationToken)
        {
            var cacheKey = BrandCacheKeys.ListKey;
            var brands   = await _distributedCache.GetAsync <IEnumerable <BrandViewModel> >(cacheKey, cancellationToken);

            if (brands == null)
            {
                brands = await _dbConnection.QueryAsync <BrandViewModel>("Select * from CatalogBrands", null, null, cancellationToken);

                await _distributedCache.SetAsync(cacheKey, brands);
            }
            return(Result <IEnumerable <BrandViewModel> > .Success(brands));
        }
예제 #4
0
 public GetBrandsQueryHandlerTest()
 {
     mapper          = new Mock <IMapper>();
     brandRepository = new Mock <IBrandRepository>();
     query           = new GetBrandsQuery();
     queryHandler    = new GetBrandsQueryHandler(brandRepository.Object, mapper.Object);
     brands          = new List <Brand> {
         new Brand(), new Brand()
     };
     brandsDto = new List <GetBrandsDto> {
         new GetBrandsDto(), new GetBrandsDto()
     };
 }
        public async Task <List <GetBrandsDto> > Handle(GetBrandsQuery request, CancellationToken cancellationToken)
        {
            var brands = await brandRepository.GetAll();

            return(mapper.Map <List <GetBrandsDto> >(brands));
        }