public static void AddPublished(Organization org, ICollection<OrganizationMediaPublishedRel> list)
 {
     foreach (var rel in list)
     {
         var c = rel.MediaPublished;
         var publication = new Publication()
         {
             Id = c.Id,
             Name = c.Name,
             Summary = c.Summary,
             DateReceived = c.DateReceived,
             DatePublished = c.DatePublished,
             Author = c.Author,
             CatalogId = c.CatalogId,
             RenewalType = Helpers.ConvertRenewalType(c.RenewalPermissionTypeId),
             SecurityLevel = c.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
             Movement = Helpers.ConvertMovementId(c.MovementClassId),
             //                        PublicationTypeId = c.PublishedTypeId,
             City = c.City,
             County = c.County,
             StateId = c.StateId,
             DateCreated = c.DateCreated,
             DateUpdated = c.DateModified,
             LogEntries = new List<PublicationLogEntry>()
         };
         publication.LogEntries.Add(new PublicationLogEntry() { Note = $"Added publication {publication.Name}" });
         org.LogEntries.Add(new OrganizationLogEntry() { Note = $"Added publication {publication.Name}" });
         org.Publications.Add(publication);
     }
 }
예제 #2
0
 public static void AddPublished(Person person, ICollection<PersonMediaPublishedRel> list)
 {
     using (var db = new AppContext())
     {
         foreach (var item in list)
         {
             var pub = db.Publications.Find(item.Id);
             if (pub == null)
             {
                 pub = new Publication()
                 {
                     Id = item.MediaPublishedId,
                     Name = item.MediaPublished.Name,
                     Summary = item.MediaPublished.Summary,
                     DateReceived = item.MediaPublished.DateReceived,
                     DatePublished = item.MediaPublished.DatePublished,
                     Author = item.MediaPublished.Author,
                     CatalogId = item.MediaPublished.CatalogId,
                     RenewalType = Helpers.ConvertRenewalType(item.MediaPublished.RenewalPermissionTypeId),
                     SecurityLevel = item.MediaPublished.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                     Movement = Helpers.ConvertMovementId(item.MediaPublished.MovementClassId),
                     //                        PublicationTypeId = item.MediaPublishedPublishedTypeId,
                     City = item.MediaPublished.City,
                     County = item.MediaPublished.County,
                     StateId = item.MediaPublished.StateId,
                     DateCreated = item.MediaPublished.DateCreated,
                     DateUpdated = item.MediaPublished.DateModified,
                     LogEntries = new List<PublicationLogEntry>()
                 };
                 pub.LogEntries.Add(new PublicationLogEntry() { Note = $"Added publication {pub.Name}" });
             }
             person.Publications.Add(pub);
             person.LogEntries.Add(new PersonLogEntry() { Note = $"Added publication {pub.Name}" });
             pub.LogEntries.Add(new PublicationLogEntry() { Note = $"Added person {person.ReverseFullName}" });
         }
     }
 }
        public static void LoadPublications(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.MediaPublisheds.Count();
            var entityName = "Publication";

            using (var context = new AppContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Publications ON");
                    w.White.Line($"Creating {takecount} {entityName}s");

                    foreach (var item in db.MediaPublisheds.OrderBy(x => x.Id).Skip(skip ?? 0).Take(takecount ?? 0))
                    {
                        count++;
                        var i = context.Publications.Find(item.Id);
                        if (i != null)
                        {
                            w.Yellow.Line($"Adding {entityName} {count} of {takecount}: {entityName} {i.Name} already exists");
                            continue;
                        }

                        var newItem = new Publication()
                        {
                            Id = item.Id,
                            Name = item.Name,
                            Summary = item.Summary,
                            DateReceived = item.DateReceived,
                            DatePublished = item.DatePublished,
                            Author = item.Author,
                            CatalogId = item.CatalogId,
                            RenewalType = Helpers.ConvertRenewalType(item.RenewalPermissionTypeId),
                            SecurityLevel = item.ConfidentialityTypeId == 1 ? SecurityLevel.EyesOnly : SecurityLevel.Open,
                            Movement = Helpers.ConvertMovementId(item.MovementClassId),
                            //                        PublicationTypeId = item.PublishedTypeId,
                            City = item.City,
                            County = item.County,
                            StateId = item.StateId,
                            DateCreated = item.DateCreated,
                            DateUpdated = item.DateModified
                        };
                        newItem.LogEntries.Add(new PublicationLogEntry() { Note = $"Added {entityName} {newItem.Name}" });
                        context.Publications.Add(newItem);
                        context.SaveChanges();
                        w.Green.Line($"Adding {count} of {takecount} {entityName}: {newItem.Name}");
                        savedCount++;
                        context.SaveChanges();
                    }
                    w.Gray.Line($"Saving {entityName}s...");
                    //context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT Publications 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));
            }
        }