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

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

            return(InstrumentMapper.ToInstrumentModel(instrument));
        }
Пример #2
0
        public void Execute(UpdateLotInstrumentPriceCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var lot = _lotRepository.GetById(command.LotId);

            if (lot == null)
            {
                throw new InvalidOperationException($"Cannot find lot with id `{command.LotId}`.");
            }

            var instrument = _instrumentRepository.GetById(lot.InstrumentInfo.Symbol);

            if (instrument == null)
            {
                throw new InvalidOperationException($"Cannot find instrument with symbol `{lot.InstrumentInfo.Symbol}`.");
            }

            lot.UpdateInstrumentPrice(instrument.CurrentPrice);

            _lotRepository.Update(lot);
        }
Пример #3
0
        public void UpdateInstrumentPrice(string symbol, decimal newPrice)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (newPrice <= 0)
            {
                throw new ArgumentException($"`{nameof(newPrice)}` must be positive. Was `{newPrice}`.", nameof(newPrice));
            }

            using (var events = _eventManagerSource.Create())
            {
                var instrument = _instrumentRepository.GetById(symbol);
                if (instrument == null)
                {
                    throw new InvalidOperationException($"Instrumemt `{symbol}` not found.");
                }

                instrument.UpdatePrice(newPrice, events);

                _instrumentRepository.Update(instrument);
            }
        }
Пример #4
0
        public Instrument Edit(Guid id, string manufacturer, string modelNo, string range, string description, int allocatedCalibrationTime)
        {
            var instrument = _instrumentRepository.GetById(id);

            if (instrument == null)
            {
                throw new ArgumentException("An ID must be supplied for the instrument");
            }
            instrument.Manufacturer             = manufacturer;
            instrument.ModelNo                  = modelNo;
            instrument.Range                    = range;
            instrument.Description              = description;
            instrument.AllocatedCalibrationTime = GetAllocatedCalibrationTime(allocatedCalibrationTime);
            ValidateAnnotatedObjectThrowOnFailure(instrument);
            _instrumentRepository.Update(instrument);
            return(instrument);
        }
Пример #5
0
 public IActionResult OnGet(int instrumentId)
 {
     Instrument = instrumentRepository.GetById(instrumentId);
     if (Instrument == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Пример #6
0
 /// <summary>
 /// Could retrieve a instrument by id
 /// </summary>
 /// <param name="getById"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public Instrument GetInstrumentById(int id)
 {
     if (id != 0)
     {
         return(instrumentRepository.GetById(id));
     }
     logger.WriteLog("Failed to Get iteam with id " + id, LogLevel.Warning);
     return(null);
 }
Пример #7
0
        public void GetInstrumentById_ValidId_ReturnsResult()
        {
            // Arrange
            var result = fixture.Create <Instrument>();

            instrumentRepository.GetById(Arg.Any <int>()).Returns(result);

            // Act
            var serviceResult = instrumentService.GetInstrumentById(1);

            // Assert
            Assert.IsNotNull(serviceResult);
            Assert.AreEqual(serviceResult.Id, result.Id);
        }
        private void StartTrackingInstrumentForLot(Lot createdLot)
        {
            var existingInstrument = _instrumentRepository.GetById(createdLot.InstrumentInfo.Symbol);

            if (existingInstrument != null)
            {
                existingInstrument.AttachLotId(createdLot.Id);
                _instrumentRepository.Update(existingInstrument);
            }
            else
            {
                var newInstrument = InstrumentFactory.NewInstrumentByInfo(createdLot.InstrumentInfo);
                newInstrument.AttachLotId(createdLot.Id);
                _instrumentRepository.Add(newInstrument);
            }
        }
Пример #9
0
 /// <summary>
 /// Could retrieve a instrument by id [not complete]
 /// </summary>
 /// <param name="getById"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public Instrument GetInstrument(bool getById, int?id)
 {
     if (getById)
     {
         if (id != null)
         {
             int  val     = 0;
             bool validId = int.TryParse(id.ToString(), out val);
             if (validId && val > 0)
             {
                 return(instrumentRepository.GetById(val));
             }
         }
         return(null);
     }
     return(null);
 }
Пример #10
0
        public IActionResult OnGet(int?instrumentId)
        {
            LoadEnums();
            if (instrumentId.HasValue)
            {
                Instrument = instrumentRepository.GetById(instrumentId.Value);
            }
            else
            {
                Instrument = new Instrument();
            }
            if (Instrument == null)
            {
                RedirectToPage("./NotFound");
            }

            return(Page());
        }
Пример #11
0
        public void AddLot(
            string symbol,
            DateTime purchaseDate,
            decimal purchasePrice,
            string notes = null
            )
        {
            using (var events = _eventManagerSource.Create())
            {
                var existingInstrument = _instrumentRepository.GetById(symbol);

                var newLot = existingInstrument != null
                    ? LotFactory.NewLotForExistingInstrument(existingInstrument, purchaseDate, purchasePrice, notes, events)
                    : LotFactory.NewLotForNewInstrument(symbol, purchaseDate, purchasePrice, notes, events);

                _lotRepository.Add(newLot);
            }
        }
        public void When(InstrumentPriceChangedDomainEvent domainEvent)
        {
            if (domainEvent == null)
            {
                throw new ArgumentNullException(nameof(domainEvent));
            }

            using (var commands = _commandManagerSource.Create())
            {
                var instrument = _instrumentRepository.GetById(domainEvent.InstrumentSymbol);
                if (instrument == null)
                {
                    throw new InvalidOperationException($"Cannot find instrument with symbol `{domainEvent.InstrumentSymbol}`.");
                }

                foreach (var lotId in instrument.LotIdList)
                {
                    commands.Send(new UpdateLotInstrumentPriceCommand(lotId));
                }
            }
        }
Пример #13
0
 public IActionResult GetById(int id)
 {
     return(Ok(_instrumentRepository.GetById(id)));
 }
        // GET: InstrumentController/Details/5
        public ActionResult Details(int id)
        {
            Instrument instrument = _instrumentRepository.GetById(id);

            return(View(instrument));
        }