public ActionResult UpdateDatabase() { ResponseNewsAppModels jsonModel = new ResponseNewsAppModels(); List <DisplayArticle> articleList = new List <DisplayArticle>(); List <Category> categoryList = db.Categories.ToList(); foreach (var category in categoryList) { string jsonObject = jsonModel.TransportJsonNewsWithApp(category.name); IEnumerable <NewArticle> listArticle = JsonConvert.DeserializeObject <IEnumerable <NewArticle> >(jsonObject) as IEnumerable <NewArticle>; foreach (var article in listArticle) { displayArticle = new DisplayArticle { author = article.newAuthor, title = article.newTitle, description = article.newDescription, url = article.newUrl, urlToImage = article.newUrlToImage, publishetAt = article.newPublishetAt, source = article.newSource.newName, idCateogry = category.idCategory }; articleList.Add(displayArticle); } } db.Articles.AddRange(articleList); db.SaveChanges(); var message = "Zaktualizowano wszystkie artykuły "; return(RedirectToAction("ControlPanel", new { information = message })); }
// GET: JsonOperation public ActionResult Index() { ResponseNewsAppModels jsonModel = new ResponseNewsAppModels(); string a = Request.QueryString["category"]; string jsonObject = jsonModel.TransportJsonNewsWithApp(Request.QueryString["category"]); IEnumerable <NewArticle> listArticle = JsonConvert.DeserializeObject <IEnumerable <NewArticle> >(jsonObject) as IEnumerable <NewArticle>; return(View(listArticle)); }
public ActionResult ControlPanel() { string category = Request.QueryString["category"]; ResponseNewsAppModels jsonModel = new ResponseNewsAppModels(); int idCategory = selectCategory(category); if (selectCategory(category) != 0) { var searchCategoryName = from categories in db.Categories where categories.idCategory == idCategory select categories.name; db.Articles.RemoveRange(db.Articles.Where(x => x.idCateogry == idCategory)); db.SaveChanges(); string jsonObject = jsonModel.TransportJsonNewsWithApp(Request.QueryString["category"]); IEnumerable <NewArticle> listArticle = JsonConvert.DeserializeObject <IEnumerable <NewArticle> >(jsonObject) as IEnumerable <NewArticle>; foreach (var article in listArticle) { displayArticle.author = article.newAuthor; displayArticle.title = article.newTitle; displayArticle.description = article.newDescription; displayArticle.url = article.newUrl; displayArticle.urlToImage = article.newUrlToImage; displayArticle.publishetAt = article.newPublishetAt; displayArticle.source = article.newSource.newName; displayArticle.idCateogry = idCategory; db.Articles.Add(displayArticle); db.SaveChanges(); db.Database.Connection.Close(); } } return(View(db.Articles.ToList())); }