public async Task <IEnumerable <ShelfDto> > Handle(ShelfQueryGetAll request, CancellationToken cancellationToken)
            {
                var shelfs = await _context.Shelfs.Include(x => x.ShelfProducts).ToListAsync();

                var shelfDtos = ShelfMapper.MapToDto(shelfs);

                return(shelfDtos);
            }
            public async Task <ShelfDto> Handle(ShelfCommandUpdateInfo request, CancellationToken cancellationToken)
            {
                var shelf = _context.Shelfs.FirstOrDefault(x => x.Id == request.Id);

                if (shelf == null)
                {
                    throw new InvalidOperationException($"ShelfId '{request.Id}' not found");
                }
                shelf.UpdateShelfInfo(request.ShelfInfoDto);
                await _context.SaveChangesAsync(cancellationToken);

                return(ShelfMapper.MapToDto(shelf));
            }
Exemple #3
0
            public async Task <ShelfDto> Handle(ShelfQueryGetById request, CancellationToken cancellationToken)
            {
                var shelf = await _context.Shelfs.Include(x => x.ShelfProducts).FirstOrDefaultAsync(x => x.Id == request.Id);

                if (shelf == null)
                {
                    throw new InvalidOperationException($"ShelfId '{request.Id}' not found");
                }

                var shelfDto = ShelfMapper.MapToDto(shelf);

                return(shelfDto);
            }