public void Execute(IJobExecutionContext context) { using (RSSNewsContext db = new RSSNewsContext()) { SourcesXMLHandler xml = new SourcesXMLHandler(context.JobDetail.JobDataMap.GetString("XMLPath")); var approvedSources = xml.GetEntries(); if (approvedSources == null) { return; } // Delete sources not in XML var ToDel = db.Sources.ToList().Where(n => !approvedSources.Exists(a => a.Address == n.Address)); if (ToDel.Count() > 0) { db.Sources.RemoveRange(ToDel); db.SaveChanges(); } // Add sources and Modify categories if needed db.Sources.AddOrUpdate(p => p.Address, approvedSources.Select(n => new Source { Address = n.Address, Category = n.Category }).ToArray()); db.SaveChanges(); } }
public void Execute(IJobExecutionContext context) { using (RSSNewsContext db = new RSSNewsContext()) using (RSSHandler servs = new RSSHandler(db)) { foreach (Source source in db.Sources.ToList()) { servs.AcquireNewsForSource(source); } } }
public async Task <ActionResult> DeleteConfirmed() { var id = User.Identity.GetUserId(); if (ModelState.IsValid) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = await UserManager.FindByIdAsync(id); var result = await UserManager.DeleteAsync(user); if (result.Succeeded) { using (var db = new RSSNewsContext()) { List <UserLikesCategory> toDelete = new List <UserLikesCategory>(); toDelete.AddRange(db.UserLikesCategories.Where(n => n.UserId == id)); if (toDelete.Count > 0) { db.UserLikesCategories.RemoveRange(toDelete); await db.SaveChangesAsync(); } } AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); } return(RedirectToAction("Index", "News")); } else { return(View()); } }
public void Execute(IJobExecutionContext context) { using (RSSNewsContext db = new RSSNewsContext()) { DateTime maxDateOk = DateTime.UtcNow.AddDays(-(Int32.Parse(ConfigurationManager.AppSettings["DaysTillOldNews"]))); var ToDel = db.News.Where(n => n.PubDate < maxDateOk); if (ToDel.Count() > 0) { db.News.RemoveRange(ToDel); db.SaveChanges(); } List <News> Replaced = new List <News>(); foreach (var newsItem in db.News) { Replaced.AddRange(db.News.Where(n => n.Title == newsItem.Title && n.PubDate < newsItem.PubDate)); } if (Replaced.Count > 0) { db.News.RemoveRange(Replaced); db.SaveChanges(); } } }
public RSSHandler(RSSNewsContext Appdb) { db = Appdb; }
public NewsController() { db = new RSSNewsContext(); servs = new RSSHandler(db); }