public void SyncData() { var remote = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServerRemote"].ConnectionString); var remoteGroups = remote.Groups.ToDictionary(a => a.Id, b => b); var entrySource = remote.Sources.ToDictionary(a => a.Id, b => b); var entries1 = remote.Entries.Select(e => new { e.Id, e.Title, Content = "" }).ToList(); var local = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServerLocal"].ConnectionString); var entries2 = local.Entries.Select(e => e).ToList(); var query = (from e in entries2 where !entries1.Exists(e1 => e1.Title == e.Title) select e).ToList(); for (int i = 0; i < query.Count; i++) { var entry = query[i]; if (i % 40 == 0) { remote.SaveChanges(); Debug.WriteLine(string.Format(">> Save {0}/{1}",i,query.Count)); } if (entry.Group == null) continue; if (!remoteGroups.ContainsKey(entry.Group.Id)) //throw new Exception("Group not exist"); continue; if (!entrySource.ContainsKey(entry.EntrySource.Source.Id)) throw new Exception("EntrySource not exist"); // clone var newEntry = new Entry { Content = entry.Content, Date = entry.Date, Description = entry.Description, Title = entry.Title, ImageUrl = entry.ImageUrl, ViewType = entry.ViewType, ViewIndex = entry.ViewIndex, Group = remoteGroups[entry.Group.Id], Published = entry.Published, EntrySource = new EntrySource { Url = entry.EntrySource.Url, Source = entrySource[entry.EntrySource.Source.Id] } }; remote.Entries.AddObject(newEntry); } remote.SaveChanges(); // Empty entry var entries3 = (from e in remote.Entries where e.Content == null select e).ToList(); foreach (var entry in entries3) { var tmp = entries2.SingleOrDefault(e => e.Title == entry.Title); if (tmp == null) continue; entry.Content = tmp.Content; } remote.SaveChanges(); }
/// <summary> /// Create a new Entry object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="viewIndex">Initial value of the ViewIndex property.</param> /// <param name="published">Initial value of the Published property.</param> public static Entry CreateEntry(global::System.Int32 id, global::System.String title, global::System.Int32 viewIndex, global::System.Boolean published) { Entry entry = new Entry(); entry.Id = id; entry.Title = title; entry.ViewIndex = viewIndex; entry.Published = published; return entry; }
public static EntryViewModel FromEntry(Entry entry) { var vm = new EntryViewModel { Content = entry.Content, Title = entry.Title, PostedDate = entry.Date == null ? DateTime.MinValue : (DateTime)entry.Date, ImageUrl = entry.ImageUrl, RelatedEntries = new List<EntryViewModel> { new EntryViewModel { Title = "Ref1" }, new EntryViewModel { Title = "Ref2" } }, PostMan = "Hero", RenderType = entry.ViewType, Id = entry.Id, Desc = entry.Description, SourceText = entry.EntrySource == null || entry.EntrySource.Source == null ? null : entry.EntrySource.Source.Name, SourceUrl = entry.EntrySource == null ? null : entry.EntrySource.Url, GroupName = entry.Group == null ? null : entry.Group.Name }; if (vm.RenderType == null) vm.RenderType = "2x4"; var sp = vm.RenderType.Split('x'); vm.W = int.Parse(sp[0]); vm.H = int.Parse(sp[1]); return vm; }
/// <summary> /// Deprecated Method for adding a new object to the Entries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEntries(Entry entry) { base.AddObject("Entries", entry); }
public PartialViewResult EntryContentView(Entry entry) { return PartialView(EntryViewModel.FromEntry(entry)); }