コード例 #1
0
ファイル: DataController.cs プロジェクト: jaickerag/GNBApp
        public async Task CompleteRateTable()
        {
            using (var context = new GNBContext())
            {
                string sqlstring = "SELECT pair.Id, pair.FromCurr, pair.ToCurr, pair.rate " +
                                   "FROM " +
                                   "(    SELECT  f.id Id,f.FromCurr FromCurr , t.FromCurr ToCurr, (f.rate/t.rate) rate " +
                                   "    FROM dbo.rates f, dbo.rates t " +
                                   "    WHERE  " +
                                   "    f.ToCurr = t.ToCurr " +
                                   ") pair " +
                                   "LEFT OUTER JOIN rates " +
                                   "ON  " +
                                   "pair.FromCurr = rates.FromCurr " +
                                   "AND pair.ToCurr = rates.ToCurr " +
                                   "WHERE rates.FromCurr IS NULL " +
                                   "and  pair.rate<>1";

                var result = context.Rates.FromSql(sqlstring).ToList();
                foreach (Rates trans in result)
                {
                    var row = new Rates {
                        Id = 0, FromCurr = trans.FromCurr, ToCurr = trans.ToCurr, Rate = Decimal.Round(trans.Rate, 2)
                    };

                    context.Add(row);
                }
                context.SaveChanges();
            }
        }
コード例 #2
0
ファイル: DataController.cs プロジェクト: jaickerag/GNBApp
        public async Task ProcessRates()
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            //client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
            var serializer   = new DataContractJsonSerializer(typeof(List <RatesJSON>));
            var streamTask   = client.GetStreamAsync("http://quiet-stone-2094.herokuapp.com/rates.json");
            var repositories = serializer.ReadObject(await streamTask) as List <RatesJSON>;

            using (var context = new GNBContext())
            {
                foreach (var trans in context.Rates)
                {
                    context.Remove(trans);
                }
                context.SaveChanges();
                foreach (var trans in repositories)
                {
                    var row = new Rates {
                        Id = 0, FromCurr = trans.from, ToCurr = trans.to, Rate = trans.Rate
                    };
                    context.Add(row);
                }
                context.SaveChanges();
            }
        }