Пример #1
0
        public async Task Create(CreateInstrumentCommand newInstrument)
        {
            string json = JsonConvert.SerializeObject(newInstrument);

            StringContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await _Client.PostAsync($"/instruments", httpContent);

            response.EnsureSuccessStatusCode();
        }
Пример #2
0
        public async Task <IActionResult> Index(CreateInstrumentCommand createInstrument)
        {
            var token = this.Request.Headers["Authorization"].ToString().Substring("Bearer ".Length);


            await _Bus.SendAsync(Queues.Frontend.Commands, token, createInstrument);

            CommandStatus status = CommandStatus.Queue(createInstrument.Id);

            await _Hub.Clients.All.SendAsync(createInstrument.Id.ToString(), status);

            return(Ok());
        }
Пример #3
0
        public async Task <IActionResult> Index(CreateInstrumentCommand createInstrument)
        {
            _Logger.LogInformation($"Creating instrument with ticker symbol {createInstrument.Symbol}");

            bool exists = _InstrumentsDbContext.Instruments.Any(i => i.Symbol == createInstrument.Symbol);

            if (exists)
            {
                _Logger.LogCritical($"Error creating instrument with ticker symbol {createInstrument.Symbol}. Instrument with Ticker symbol {createInstrument.Symbol} allready exits");
                return(BadRequest($"Instrument with Ticker symbol {createInstrument.Symbol} allready exits"));
            }

            Currency currency = _InstrumentsDbContext.Currencies.SingleOrDefault(c => c.Symbol.ToUpper() == createInstrument.Currency.ToUpper());

            if (currency == null)
            {
                currency = new Currency
                {
                    Symbol = createInstrument.Currency.ToUpper()
                };

                await _InstrumentsDbContext.Currencies.AddAsync(currency);
            }

            Sector sector = _InstrumentsDbContext.Sectors.SingleOrDefault(s => s.Id == createInstrument.Sector);

            if (sector == null)
            {
                _Logger.LogCritical($"Error creating instrument with ticker symbol {createInstrument.Symbol}. Sector with id {0} does not exist");
                return(BadRequest($"Sector with id {0} does not exist"));
            }

            Instrument instrument = new Instrument
            {
                Symbol    = createInstrument.Symbol,
                Name      = createInstrument.Name,
                Currency  = currency,
                IsDeleted = false,
                Isin      = createInstrument.Isin,
                Exchange  = createInstrument.Exchange,
                Sector    = sector
            };

            await _InstrumentsDbContext.AddAsync(instrument);

            await _InstrumentsDbContext.SaveChangesAsync();

            return(Ok());
        }