Beispiel #1
0
 public void Post([FromBody] Currency curr)
 {
     if (ModelState.IsValid)
     {
         CurrencyRepository.Add(curr);
     }
 }
        public void Add_AddsItemToDbSet()
        {
            var newItem = new Currency()
            {
                CurrencyId = 4,
                IsoCode    = "DD",
                Name       = "TestName"
            };

            var mockSet = new Mock <DbSet <Currency> >().SetupData(new List <Currency>());

            mockSet.Setup(m => m.Add(It.IsAny <Currency>())).Returns(newItem);

            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Set <Currency>()).Returns(mockSet.Object);

            var service = new CurrencyRepository(mockContext.Object);

            // Act
            var item = service.Add(newItem);

            mockSet.Verify(m => m.Add(newItem), Times.Once);
            Assert.IsNotNull(item);
            Assert.AreEqual(item.IsoCode, newItem.IsoCode);
            Assert.AreEqual(item.Name, newItem.Name);
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Name")] Currency currency)
        {
            if (ModelState.IsValid)
            {
                CurrencyRepository.Add(currency);
                return(RedirectToAction("Index"));
            }

            return(View(currency));
        }
Beispiel #4
0
        public ActionResult AddCurrency(string currencyName, string currencySymbol)
        {
            Currency currency = new Currency()
            {
                CurrencyName   = currencyName,
                CurrencySymbol = currencySymbol
            };
            CurrencyRepository currencyRepository = new CurrencyRepository();

            currencyRepository.Add(currency);
            currencyRepository.PersistChanges();

            Currency dbCurrency = currencyRepository.Get(currency.Id);

            return(Content($"Inserted currency id: {dbCurrency.Id}"));
        }
        public async Task <bool> Run(ILogger logger)
        {
            logger.LogInformation("Running repository bootstrapper");

            try
            {
                foreach (var currency in CurrencyFactory.List())
                {
                    await CurrencyRepository.Add(currency);
                }

                foreach (var symbol in SymbolFactory.List())
                {
                    await SymbolRepository.Add(symbol);
                }

                foreach (var group in IntervalFactory.ListGroups())
                {
                    foreach (var ik in IntervalFactory.ListIntervalKeys(group.IntervalGroup))
                    {
                        await IntervalRepository.Add(ik);
                    }
                }

                foreach (var exchange in ExchangeFactory.List())
                {
                    await ExchangeRepository.Add(exchange);

                    var httpClient = exchange.GetHttpClient();

                    foreach (var symbolCode in exchange.Symbol)
                    {
                        var symbol = SymbolFactory.Get(symbolCode);

                        await SymbolRepository.Add(symbol);

                        await ExchangeRepository.AddSymbol(exchange.Name, symbolCode);

                        var tradeFilter = await HistorianRepository.GetTradeFilter(exchange.Name, symbolCode);

                        if (tradeFilter == null)
                        {
                            using (var transaction = await StorageTransactionFactory.Begin())
                            {
                                await HistorianRepository.SetTradeFilter(transaction, exchange.Name, symbolCode, httpClient.InitialTradeFilter);

                                await transaction.Commit();
                            }
                        }
                    }
                }

                foreach (var orderSide in OrderSideFactory.List())
                {
                    await OrderSideRepository.Add(orderSide);
                }

                return(true);
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, "Unable to run repository bootstrapper");

                return(false);
            }
        }