public static void AddImages(Organization org, ICollection<OrganizationMediaImageRel> list) { foreach (var rel in list) { var c = rel.MediaImage; var mediaImage = new Domain.Models.MediaImage() { Id = c.Id, Title = c.ImageTitle, Summary = c.Summary, FileName = c.ImageFileName, CatalogId = c.CatalogId, ContactOwner = c.ContactOwner, BatchSortOrder = c.BatchSortOrder, Photographer = c.PhotographerArtist, DatePublished = c.DatePublished, DateTaken = c.DateTaken, RollFrame = c.RollFrameNumber, ImageType = Helpers.ConvertImageType(c.ImageTypeId), SecurityLevel = c.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open, Movement = Helpers.ConvertMovementId(c.MovementClassId), //// Image = c.Image.IMAGE1, // MimeType = c.Image.MimeType.Name, //todo: make type DateCreated = c.DateCreated, DateUpdated = c.DateModified, LogEntries = new List<MediaImageLogEntry>() }; mediaImage.LogEntries.Add(new MediaImageLogEntry() { Note = $"Added image {mediaImage.Title}" }); org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added image {mediaImage.Title}" }); org.MediaImages.Add(mediaImage); } }
public static void LoadImages(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.MediaImages.Count(); var entityName = "Image"; using (var context = new AppContext()) { using (var trans = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT MediaImages ON"); w.White.Line($"Creating {takecount} {entityName}s"); foreach (var item in db.MediaImages.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0)) { count++; var i = context.MediaImages.Find(item.Id); if (i != null) { w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Title} already exists"); continue; } var newItem = new Domain.Models.MediaImage() { Id = item.Id, Title = item.ImageTitle?.Trim(), Summary = item.Summary?.Trim(), FileName = item.ImageFileName?.Trim(), CatalogId = item.CatalogId?.Trim(), ContactOwner = item.ContactOwner?.Trim(), BatchSortOrder = item.BatchSortOrder, Photographer = item.PhotographerArtist?.Trim(), DatePublished = item.DatePublished, DateTaken = item.DateTaken, RollFrame = item.RollFrameNumber?.Trim(), ImageType = Helpers.ConvertImageType(item.ImageTypeId), SecurityLevel = item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open, Movement = Helpers.ConvertMovementId(item.MovementClassId), //// Image = item.Image.IMAGE1, // MimeType = item.Image.MimeType.Name, //todo: make type DateCreated = item.DateCreated, DateUpdated = item.DateModified, }; newItem.LogEntries.Add(new MediaImageLogEntry() { Note = $"Added {entityName} {newItem.Title}" }); context.MediaImages.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 MediaImages 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)); } }