public static void AddAudioVideo(Organization org, ICollection<OrganizationMediaAudioVideoRel> list) { foreach (var rel in list) { var c = rel.MediaAudioVideo; var audioVideo = new AudioVideo() { Id = c.Id, Title = c.Title, Summary = c.Summary, SpeakerCommentator = c.SpeakerCommentator, MediaLength = c.MediaLength, CatalogId = c.CatalogId, DateReceivedRecorded = c.DateReceivedRecorded, DateAired = c.DateAired, AudioVideoType = (AudioVideoType)c.AudioVideoTypeId, SecurityLevel = c.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open, Movement = Helpers.ConvertMovementId(c.MovementClassId), City = c.City, County = c.County, StateId = c.StateId, DateCreated = c.DateCreated, DateUpdated = c.DateModified, LogEntries = new List<AudioVideoLogEntry>() }; audioVideo.LogEntries.Add(new AudioVideoLogEntry() { Note = $"Added audio video {audioVideo.Title}" }); org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added audio video {audioVideo.Title}" }); org.AudioVideos.Add(audioVideo); } }
public static void LoadAudioVideo(int? skip = 0, int? takecount = 0) { var startTime = DateTime.Now; var w = FluentConsole.Instance; var db = new ACDBContext(); var count = 0; var savedCount = 0; if (takecount == 0) takecount = db.MediaAudioVideos.Count(); var entityName = "AudioVideo"; using (var context = new AppContext()) { using (var trans = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT AudioVideos ON"); w.White.Line($"Creating {takecount} {entityName}s"); foreach (var item in db.MediaAudioVideos.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0)) { count++; var i = context.AudioVideos.Find(item.Id); if (i != null) { w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Title} already exists"); continue; } var newItem = new AudioVideo() { Id = item.Id, Title = item.Title?.Trim(), Summary = item.Summary?.Trim(), SpeakerCommentator = item.SpeakerCommentator?.Trim(), MediaLength = item.MediaLength?.Trim(), CatalogId = item.CatalogId?.Trim(), DateReceivedRecorded = item.DateReceivedRecorded, DateAired = item.DateAired, AudioVideoType = (AudioVideoType)item.AudioVideoTypeId, SecurityLevel = item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open, Movement = Helpers.ConvertMovementId(item.MovementClassId), City = item.City?.Trim(), County = item.County?.Trim(), StateId = item.StateId, DateCreated = item.DateCreated, DateUpdated = item.DateModified, }; newItem.LogEntries.Add(new AudioVideoLogEntry() { Note = $"Added {entityName} {newItem.Title}" }); context.AudioVideos.Add(newItem); w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Title}"); savedCount++; context.SaveChanges(); } w.Gray.Line($"Saving {entityName}s..."); context.SaveChanges(); context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT AudioVideos OFF"); trans.Commit(); } var totalTime = DateTime.Now - startTime; w.Green.Line($"Saved {savedCount} {entityName}s in {totalTime.Hours}:{totalTime.Minutes}:{totalTime.Seconds} "); w.White.Line(new String('-', 15)); } }