Esempio n. 1
0
            public async Task <Result <VehicleTypesResponse> > Handle(GetVehicleTypeByIdQuery query, CancellationToken cancellationToken)
            {
                var category = await _repository.GetByIdAsync(query.Id);

                var mappedCategory = _mapper.Map <VehicleTypesResponse>(category);

                return(Result <VehicleTypesResponse> .Success(mappedCategory));
            }
            public async Task <Result <int> > Handle(DeleteVehicleTypeCommand command, CancellationToken cancellationToken)
            {
                var item = await _repository.GetByIdAsync(command.Id);

                await _repository.DeleteAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        public async Task <Result <int> > Handle(UpdateVehicleTypeCommand command, CancellationToken cancellationToken)
        {
            var item = await _repository.GetByIdAsync(command.Id);

            if (item == null)
            {
                return(Result <int> .Fail($"PlaceType Not Found."));
            }
            else
            {
                item.Name        = command.Name ?? item.Name;
                item.Code        = command.Code ?? item.Code;
                item.Icon        = command.Icon ?? item.Icon;
                item.Description = command.Description ?? item.Description;
                item.SeatCount   = command.SeatCount ?? item.SeatCount;


                await _repository.UpdateAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        }