예제 #1
0
        public async Task <Unit> Handle(UpdateCelestialObjectCommand request, CancellationToken cancellationToken)
        {
            var sqlParams = new
            {
                request.Id,
                request.Magnitude,
                request.AbsoluteMagnitude,
                request.Name,
                ObjectType = request.ObjectType.ToString(),
                request.Designation1,
                request.Designation2,
                request.Designation3,
                request.Designation4,
                request.Description,
                request.Distance,
                request.DistanceTolerance
            };

            var result = await _dataRepo.ExecuteAsync(
                SqlLoader.GetSql(SqlResourceNames.CelestialObjects.CelestialObject_Update),
                sqlParams);

            if (result == 0)
            {
                throw new NotFoundException($"Unable to find resource with id '{request.Id}'for deletion.");
            }

            return(Unit.Value);
        }
예제 #2
0
        public async Task <Unit> Handle(DeleteCelestialObjectCommand request, CancellationToken cancellationToken)
        {
            var result = await _dataRepo.ExecuteAsync(
                SqlLoader.GetSql(sqlResourceName: SqlResourceNames.CelestialObjects.CelestialObject_Delete),
                new { Id = request.CelestialObjectId });

            if (result == 0)
            {
                throw new NotFoundException($"Unable to find resource with id '{request.CelestialObjectId}'for deletion.");
            }

            return(Unit.Value);
        }
예제 #3
0
        public async Task <CelestialObjectDto> Handle(GetCelestialByIdQuery request, CancellationToken cancellationToken)
        {
            var celestialObject = await _dataRepo.QueryFirstOrDefaultAsync <CelestialObjectEntityModel>(
                SqlLoader.GetSql(SqlResourceNames.CelestialObjects.CelestialObject_Get),
                new { Id = request.CelestialId });

            if (celestialObject == null)
            {
                throw new NotFoundException($"No celestial object found for Id: {request.CelestialId}");
            }

            return(_mapper.Map <CelestialObjectDto>(celestialObject));
        }
예제 #4
0
        public async Task <IEnumerable <CelestialObjectDto> > Handle(SearchCelestialQuery request, CancellationToken cancellationToken)
        {
            var searchResult = await _dataRepo.QueryAsync <CelestialObjectEntityModel>(
                SqlLoader.GetSql(SqlResourceNames.CelestialObjects.CelestialObject_Search),
                new { searchText = $"\"{request.SearchText}*\"" });

            if (searchResult == null)
            {
                return(new List <CelestialObjectDto>());
            }

            return(searchResult.Select(c => _mapper.Map <CelestialObjectDto>(c)));
        }
예제 #5
0
        public async Task <int> Handle(CreateCelestialObjectCommand request, CancellationToken cancellationToken)
        {
            var sqlParams = new
            {
                ObjectType = request.ObjectType.ToString(),
                request.Magnitude,
                request.AbsoluteMagnitude,
                request.Name,
                request.Designation1,
                request.Designation2,
                request.Designation3,
                request.Designation4,
                request.Description,
                request.Distance,
                request.DistanceTolerance
            };

            var createResultId = await _dataRepo.QueryFirstAsync <int>(
                SqlLoader.GetSql(SqlResourceNames.CelestialObjects.CelestialObject_Create),
                sqlParams);

            return(createResultId);
        }