public void UpdateEdaphobaseInfo() { try { var taxons = _infContext.Taxon.Where(tax => tax.EdaphobaseId != null).ToList(); foreach (Taxon tax in taxons) { if (tax.EdaphobaseId != null) { List <string> synonyms = doEdaphoRequest(edaphoApi, tax.EdaphobaseId.ToString()); if (synonyms != null) { synonyms.RemoveAll(syn => syn == tax.Genus.TaxonName); //sanitize edaphobase input double whitespaces synonyms.ForEach(syn => Regex.Replace(syn, @"\s+", " ")); tax.Synonyms = JsonConvert.SerializeObject(synonyms); } } } _infContext.UpdateRange(taxons); _infContext.SaveChanges(); Logger.Info("-- Done Updating Edaphobase Info."); } catch (Exception e) { Logger.Error(e, "-- Error Updating Edaphobase Info"); } }
public ActionResult Create([Bind(Include = "ID,Email,Password")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ID,Description,DueDateTime")] Task task) { if (ModelState.IsValid) { db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(task)); }
public async Task <ActionResult <Intervention> > PutInterventionStart(int id) { var existingIntervention = await _context.interventions.Where(i => i.id == id) .FirstOrDefaultAsync <Intervention>(); if (existingIntervention == null) { return(NotFound()); } existingIntervention.start_date_time = DateTime.Now; existingIntervention.updated_at = DateTime.Now; existingIntervention.status = "InProgress"; _context.SaveChanges(); return(existingIntervention); }
/// <summary> /// Method for populating the database with address data. /// </summary> /// <param name="staticMapData">The staticdata object.</param> private void UpdateDatabase(StaticMapData staticMapData) { using (var context = new InformationContext()) { Dispatcher.Invoke(() => { lblNumberOfRecords.Content = context.Persons.Count().ToString(); }); Postal postal = context.Postals.Where(x => x.PostalCode == staticMapData.PostalCode && x.City == staticMapData.City).FirstOrDefault(); if (postal == null) { context.Postals.Add(staticMapData.GetPostal()); context.SaveChanges(); return; } Address address = context.Addresses.Where(x => x.Street == staticMapData.Addr1 && x.PostalCode == staticMapData.PostalCode).FirstOrDefault(); if (address == null) { postal.Addresses.Add(staticMapData.GetAddress(postal)); context.SaveChanges(); return; } Person person = context.Persons.Where(x => x.DataId.ToString() == staticMapData.Id).FirstOrDefault(); if (person == null) { address.Persons.Add(staticMapData.GetPerson(address)); context.SaveChanges(); } } }
//写入搜索记录 public void Add_SearchLog(IEnumerable <Manage.Models.Book> BookList) { var firstBook = BookList.FirstOrDefault(); if (firstBook != null) { SearchLog searchLog = new SearchLog { Book = firstBook }; _context.SearchLogs.Add(searchLog); _context.SaveChanges(); } }
public void BackupAndTruncate() { _infContext.Database.ExecuteSqlCommand("TRUNCATE TABLE \"Inf\".\"Taxon\" CASCADE;"); Logger.Info("Truncated Inf.Taxon"); _infContext.SaveChanges(); _detContext.Database.ExecuteSqlCommand("TRUNCATE TABLE \"Det\".\"DescriptionKeyGroup\" CASCADE;"); Logger.Info("Truncated Det.DescriptionKeyGroup"); _detContext.Database.ExecuteSqlCommand("TRUNCATE TABLE \"Det\".\"DescriptionKey\" CASCADE;"); Logger.Info("Truncated Det.DescriptionKey"); _detContext.Database.ExecuteSqlCommand("TRUNCATE TABLE \"Det\".\"TaxonDescription\" CASCADE;"); Logger.Info("Truncated Det.TaxonDescription"); _detContext.SaveChanges(); //_infContext.Database.ExecuteSqlCommand(string.Format("DELETE FROM {0}", "[Taxon]")); }
private async Task FillData(DataSet ds, InformationContext entity, List <InformationReport> reports) { foreach (DataRow item in ds.Tables[0].Rows) { InformationReport report = new InformationReport(); report.ErrorCode = item["errorcode"] != null?Convert.ToInt32(item["errorcode"]) : 0; report.ErrorMessage = item["errormessage"].ToString(); report.NumberOfResults = item["numberofresults"].ToString(); report.Results = item["results"].ToString(); report.StopID = item["stopid"] != null?Convert.ToInt32(item["stopid"]) : 0; report.TimeStamp = item["timestamp"] != null?Convert.ToDateTime(item["timestamp"]) : DateTime.Now; reports.Add(report); entity.InformationReport.Add(report); } entity.SaveChanges(); }
public static void Initialize(InformationContext context) { context.Database.EnsureCreated(); if (context.Posts.Any()) { return; } var posts = new Post[] { new Post { Title = "1", Content = "1", Time = "2018-2-1" }, new Post { Title = "2", Content = "2", Time = "2018-2-2" }, new Post { Title = "3", Content = "3", Time = "2018-2-3" }, }; foreach (Post t in posts) { context.Posts.Add(t); } context.SaveChanges(); if (context.Books.Any()) { return; } var books = new Book[] { new Book { Name = "神经计算原理", Author = "1", Publisher = "机械工业出版社" }, new Book { Name = "Windows程序设计", Author = "2", Publisher = "北京大学出版社" }, new Book { Name = "java 5 游戏编程", Author = "3", Publisher = "人民邮电出版社" }, }; foreach (Book s in books) { context.Books.Add(s); } context.SaveChanges(); if (context.Blogs.Any()) { return; } var blogs = new Blog[] { new Blog { BlogAuthor = "User A", BlogUrl = "https://www.liaoxuefeng.com/" }, new Blog { BlogAuthor = "User B", BlogUrl = "https://www.liaoxuefeng.com/" }, new Blog { BlogAuthor = "User C", BlogUrl = "https://www.liaoxuefeng.com/" }, }; foreach (Blog u in blogs) { context.Blogs.Add(u); } context.SaveChanges(); if (context.Videos.Any()) { return; } var videos = new Video[] { new Video { VideoName = "1", VideoNum = 1, VideoURL = "1" }, new Video { VideoName = "2", VideoNum = 2, VideoURL = "2" }, new Video { VideoName = "3", VideoNum = 3, VideoURL = "3" }, }; foreach (Video o in videos) { context.Videos.Add(o); } context.SaveChanges(); }