예제 #1
0
        public CurrencyDTO Insert(Currency currency)
        {
            try
            {
                var entry = _repository.Currency.Add(_mapper.Map <CurrencyDTO>(currency)).Entity;

                _repository.SaveChanges();
                return(entry);
            }
            catch (Exception ex)
            {
                //Todo: Log error
                throw ex.InnerException;
            }
        }
예제 #2
0
        public BoardgameDTO Insert(Boardgame boardGame)
        {
            try
            {
                var model  = _mapper.Map <BoardgameDTO>(boardGame);
                var result = _repository.Boardgame.Add(model).Entity;
                _repository.SaveChanges();

                return(result);
            }
            catch (Exception e)
            {
                //Todo: Log error here
                throw e;
            }
        }
예제 #3
0
        public CountryDTO Insert(Country country)
        {
            try
            {
                var model    = _mapper.Map <CountryDTO>(country);
                var currency = _repository.Currency.FirstOrDefault(c => c.IsoCode == country.Currency);
                model.Currency = currency ?? model.Currency;

                var result = _repository.Country.Add(model).Entity;
                _repository.SaveChanges();

                return(result);
            }
            catch (Exception e)
            {
                //Todo: Log error here
                throw e;
            }
        }
예제 #4
0
        public StoreDTO Insert(Store store)
        {
            try
            {
                var model   = _mapper.Map <StoreDTO>(store);
                var country = _repository.Country.FirstOrDefault(s => s.Name == store.Country);
                model.Country = country ?? model.Country;

                var result = _repository.Store.Add(model).Entity;
                _repository.SaveChanges();

                return(result);
            }
            catch (Exception e)
            {
                //Todo: Log error here
                throw e;
            }
        }
예제 #5
0
        public static void EnsureSeedData(this BGScreenerContext context)
        {
            if (context.AllMigrationsApplied())
            {
                if (!context.Currency.Any())
                {
                    var euro = context.Currency.Add(new CurrencyDTO()
                    {
                        IsoCode = "EUR"
                    }).Entity;
                    var real = context.Currency.Add(new CurrencyDTO()
                    {
                        IsoCode = "BRL"
                    }).Entity;
                    var dolar = context.Currency.Add(new CurrencyDTO()
                    {
                        IsoCode = "USD"
                    }).Entity;

                    var germany = context.Country.Add(new CountryDTO()
                    {
                        Name = "Germany", Currency = euro
                    }).Entity;
                    var brasil = context.Country.Add(new CountryDTO()
                    {
                        Name = "Brasil", Currency = real
                    }).Entity;
                    var usa = context.Country.Add(new CountryDTO()
                    {
                        Name = "USA", Currency = dolar
                    }).Entity;

                    var glomhaven = context.Boardgame.Add(new BoardgameDTO()
                    {
                        Name = "Gloomhaven"
                    }).Entity;
                    var seventhContinent = context.Boardgame.Add(new BoardgameDTO()
                    {
                        Name = "7Th Continent"
                    }).Entity;
                    var mariposas = context.Boardgame.Add(new BoardgameDTO()
                    {
                        Name = "Mariposas"
                    }).Entity;

                    var fanazyWelt = context.Store.Add(new StoreDTO()
                    {
                        Name = "FantazyWelt", Country = germany, Boardgames = new List <BoardgameDTO>()
                        {
                            glomhaven, seventhContinent
                        }
                    }).Entity;
                    var zatu = context.Store.Add(new StoreDTO()
                    {
                        Name = "ZATU", Country = germany, Boardgames = new List <BoardgameDTO>()
                        {
                            mariposas
                        }
                    }).Entity;

                    glomhaven.Stores = new List <StoreDTO>()
                    {
                        fanazyWelt
                    };
                    seventhContinent.Stores = new List <StoreDTO>()
                    {
                        fanazyWelt
                    };
                    mariposas.Stores = new List <StoreDTO>()
                    {
                        zatu
                    };

                    //var ex1 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 1, ToCurrencyId = 2, Rate = 6.52m }).Entity;
                    //var ex2 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 1, ToCurrencyId = 3, Rate = 1.21m }).Entity;
                    //var ex3 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 2, ToCurrencyId = 1, Rate = 0.15m }).Entity;
                    //var ex4 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 2, ToCurrencyId = 3, Rate = 0.19m }).Entity;
                    //var ex5 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 3, ToCurrencyId = 1, Rate = 0.83m }).Entity;
                    //var ex6 = context.ExchangeRate.Add(new DbcExchangeRate() { FromCurrencyId = 3, ToCurrencyId = 2, Rate = 5.38m }).Entity;

                    //var historicalPrice = context.HistoricalPrice.Add(new DbcHistoricalPrice() { BoardGame = glomhaven, Store = fanazyWelt, DateTime = DateTime.UtcNow }).Entity;

                    context.SaveChanges();
                }
            }
        }