コード例 #1
0
ファイル: GithubOp.cs プロジェクト: perfumedsea/MultiSpider
 /// <summary>
 /// 保存一组数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="datas"></param>
 public void SaveRangeData <T>(IEnumerable <T> datas) where T : IRepo
 {
     using (GithubContext github = new GithubContext())
     {
         if (typeof(T) == typeof(TrendingRepo))
         {
             github.TrendingEntities.AddRange(datas as IEnumerable <TrendingRepo>);
         }
         else if (typeof(T) == typeof(ThemeRepo))
         {
             github.ThemeEntities.AddRange(datas as IEnumerable <ThemeRepo>);
         }
         github.SaveChanges();
     }
 }
コード例 #2
0
ファイル: GithubOp.cs プロジェクト: perfumedsea/MultiSpider
 /// <summary>
 /// 保存一条数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 public void SaveData <T>(T data) where T : IRepo
 {
     using (GithubContext github = new GithubContext())
     {
         if (typeof(T) == typeof(TrendingRepo))
         {
             github.TrendingEntities.Add(data as TrendingRepo);
         }
         else if (typeof(T) == typeof(ThemeRepo))
         {
             github.ThemeEntities.Add(data as ThemeRepo);
         }
         github.SaveChanges();
     }
 }
コード例 #3
0
        public async Task <IActionResult> Updateto(string Json)   //just string data...
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var data = JsonConvert.DeserializeObject <List <gitd> >(Json); //Convert from JSON to object...

                    await _context.AddRangeAsync(data);

                    _context.SaveChanges(); //adding list to table.
                }
                return(Ok());               //RESPONSE
            }
            catch (Exception ex)
            {
                return(BadRequest(ex)); //ERROR RESPONSE
            }
        }