Beispiel #1
0
 private void testDateSingle()
 {
     using (var db = new EntranceScoresContext())
     {
         var collegeEntity = db.collegeEntities.DefaultIfEmpty().Single(c => c.code.Equals("ANH"));
         var majorEntity   = db.majorEntities.DefaultIfEmpty().Single(c => c.code.Equals("714"));
         var majorCollege  = new MajorCollege();
         majorCollege.CollegeEntity = collegeEntity;
         majorCollege.MajorEntity   = majorEntity;
         majorCollege.score         = 17.5;
         majorCollege.groupCode     = "sdsd";
         majorCollege.year          = 2019;
         db.majorColleges.Add(majorCollege);
         db.SaveChanges();
     }
 }
Beispiel #2
0
        public ActionResult <string> Get(int year)
        {
            using (var db = new EntranceScoresContext())
            {
                //Parallel.ForEach(collegeEntities, college => Process(college,year,db));

                foreach (var cl in collegeEntities)
                {
                    this.Process(cl, year, db);
                }

                if (isAddNewMajor == false)
                {
                    //Add majorCollege to database
                    db.majorColleges.AddRange(majorColleges);
                }
                else
                {
                    //Add majorCollege to database

                    //Convert map to list
                    newMajorEntities = newMajorMap.Select(p => new MajorEntity {
                        code = p.Key, name = p.Value
                    }).ToList();

                    Console.WriteLine("Begin the process of adding industry of the " + year + " to the database");

                    //Add list to db
                    db.majorEntities.AddRange(newMajorEntities);

                    Console.WriteLine("Finish process of add industry!");
                }

                db.SaveChanges();
                return("Crawling data from " + year + " OK");
            }
        }