public InstrumentModel GetById(string id)
        {
            var instrument = _instrumentRepository.GetById(id);

            if (instrument == null)
            {
                throw new NotFoundException(Messages.InvalidInstrumentId);
            }

            return(InstrumentMapper.ToInstrumentModel(instrument));
        }
Exemplo n.º 2
0
        public IList <InstrumentPriceDto> Get()
        {
            var instrumentsPrice        = new List <InstrumentPriceDto>();
            var instrumentBusinessLogic = new InstrumentBusinessLogic(new ShepherdEntities(),
                                                                      new InstrumentGenerator(new PriceGenerator()),
                                                                      new PriceGenerator());
            var instrumentsBusinessLogic = instrumentBusinessLogic.GetStockInstruments();
            var instrumentMapper         = new InstrumentMapper();

            return(instrumentMapper.MapInstrumentsToInstrumentsPriceDto(instrumentsBusinessLogic));
        }
        public void Add(InstrumentModel instrumentModel)
        {
            if (string.IsNullOrEmpty(instrumentModel.Name))
            {
                throw new ValidationException(Messages.InstrumentNameRequired);
            }

            var instrumentByName = _instrumentRepository.GetByName(instrumentModel.Name);

            if (instrumentByName != null)
            {
                throw new ConflictException(Messages.InstrumentNameAlreadyExists);
            }

            var instrument = InstrumentMapper.ToInstrument(instrumentModel);

            instrument.Id = SecurityUtils.GenerateEntityId();

            _instrumentRepository.Add(instrument);
        }
        public void Update(string id, InstrumentModel instrumentModel)
        {
            if (string.IsNullOrEmpty(instrumentModel.Name))
            {
                throw new ValidationException(Messages.InstrumentNameRequired);
            }

            var instrument = _instrumentRepository.GetById(id);

            if (instrument == null)
            {
                throw new NotFoundException(Messages.InvalidInstrumentId);
            }

            var instrumentByName = _instrumentRepository.GetByName(instrument.Name);

            if (instrumentByName != null && instrumentByName.Id != id)
            {
                throw new ConflictException(Messages.InstrumentNameAlreadyExists);
            }

            InstrumentMapper.RefreshInstrument(instrument, instrumentModel);
            _instrumentRepository.Update(instrument);
        }
 public InstrumentService(IInstrumentBusinessLogic instrumentBusinessLogic,
                          InstrumentMapper instrumentMapper)
 {
     _instrumentBusinessLogic = instrumentBusinessLogic;
     _instrumentMapper        = instrumentMapper;
 }