示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IPriceService priceService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CryptoService v1"));
            }

            app.UseCors(CorsPolicy);

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // This is not the best place or the best way to update the list of valid coins.
            // This resulted from (incorrectly) assuming only three types of coins should be supported
            // during the design stage. Going forward with this now due to time constraints.
            CoinStore.AddCoinsToStore(priceService.GetAllValidCoins().GetAwaiter().GetResult());
        }
 public CoinEvent(int id, int capacity, int quantity, decimal value)
 {
     CoinStore = new CoinStore()
     {
         ID = id, Capacity = capacity, Quantity = quantity, Value = value
     };
 }
示例#3
0
        public bool SetPreferredCoin(string symbol)
        {
            if (CoinStore.GetCoin(symbol, out Coin coin))
            {
                PreferredCoin = coin;
                return(true);
            }

            return(false);
        }
示例#4
0
        public IActionResult SetPreferredCoin(string symbol)
        {
            if (string.IsNullOrEmpty(symbol) ||
                !CoinStore.IsSymbolValid(symbol) ||
                !user.SetPreferredCoin(symbol))
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <IActionResult> GetCoinData(string symbol)
        {
            if (string.IsNullOrEmpty(symbol) ||
                !CoinStore.IsSymbolValid(symbol) ||
                !CoinStore.GetCoin(symbol, out Coin coin))
            {
                return(BadRequest());
            }

            var coinData = await priceService.GetCoinData(coin);

            coin.UpdatePrices(coinData.SpotRate, coinData.Ask, coinData.Bid);
            return(Ok(coin));
        }
示例#6
0
        public void Update(CoinStore coin)
        {
            //CoinStore retrievedCoin = _context.Coins.Find(new { coin.ID });

            CoinStore retrievedCoin = _context.Coins.Find(coin.ID);

            if (retrievedCoin != null)
            {
                retrievedCoin.Capacity = coin.Capacity;
                retrievedCoin.Quantity = coin.Quantity;
                retrievedCoin.Value    = coin.Value;

                _context.Coins.Update(retrievedCoin);
                _context.SaveChanges();
            }
        }
        public static void Initialize(DataBaseContext context)
        {
            context.Database.EnsureCreated();

            if (context.Drinks.Any())
            {
                return;   // DB has been seeded
            }

            var drinks = new Drink[] {
                new Drink {
                    Code = "COKE", Description = "Coca-Cola", Price = 1.20m, Color = "#eb1c2c"
                },
                new Drink {
                    Code = "WAT", Description = "Water", Price = 1, Color = "#337ab7"
                },
                new Drink {
                    Code = "FAN", Description = "Fanta", Price = 1.6m, Color = "#eb681c"
                },
                new Drink {
                    Code = "RED", Description = "Red Bull", Price = 2.0m, Color = "#9d9d9d"
                }
            };

            foreach (Drink s in drinks)
            {
                context.Drinks.Add(s);
            }
            context.SaveChanges();


            var items = new CatalogItem[] {
                new CatalogItem {
                    DrinkID = 1, Quantity = 20
                },
                new CatalogItem {
                    DrinkID = 2, Quantity = 10
                },
                new CatalogItem {
                    DrinkID = 3, Quantity = 15
                },
                new CatalogItem {
                    DrinkID = 4, Quantity = 5
                }
            };

            foreach (CatalogItem i in items)
            {
                context.CatalogItems.Add(i);
            }
            context.SaveChanges();

            var coins = new CoinStore[] {
                new CoinStore {
                    Value = Coin.Five, Quantity = 0, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.Two, Quantity = 5, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.One, Quantity = 8, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.FiftyCent, Quantity = 8, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.TwentyCent, Quantity = 8, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.TenCent, Quantity = 8, Capacity = 20
                },
                new CoinStore {
                    Value = Coin.FiveCent, Quantity = 5, Capacity = 20
                },
            };

            foreach (var c in coins)
            {
                context.Coins.Add(c);
            }
            context.SaveChanges();
        }
 public void Post([FromBody] CoinStore coinStore)
 {
     _coinProvider.Update(coinStore);
 }