public void UpdateData() { try { if (_dataAcces.CheckLastUpdate()) { string json = _dataAcces.GetData(); var data = MapData(json); using (Data.Entity.StarWarsEntities1 ent = new StarWarsEntities1()) { foreach (var item in data) { var id = int.Parse(item.episode_id); var film = ent.Film.Where(x => x.Id == id).FirstOrDefault(); if (film != null) { film.opening_crawl = item.opening_crawl; film.director = item.director; film.producer = item.producer; film.url = item.url; film.Title = item.title; film.edited = DateTime.Now; film.releasedate = DateTime.Parse(item.release_date.Replace('-', '/')); film.visited = false; } else { ent.Film.Add(new Film() { Id = int.Parse(item.episode_id), opening_crawl = item.opening_crawl, director = item.director, producer = item.producer, url = item.url, Title = item.title, created = DateTime.Now, edited = DateTime.Now, releasedate = DateTime.Parse(item.release_date.Replace('-', '/')) }); } } ent.SaveChanges(); } } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { string mess = e.InnerException.ToString(); } } }